我在
.bashrc
中创建了一个简单的函数,以 ssh
进入特定机器并进入特定的 tmux
会话:
# Function to ssh to a machine with tmux
connect() {
local host=$1
local session=${2:-main}
# Check if tmux session exists
if ssh -q "$host" "tmux has-session -t $session 2>/dev/null"; then
ssh -t "$host" "tmux attach -t $session"
else
# Create tmux session if it doesn't exist
ssh -t "$host" "tmux new-session -s $session"
fi
}
一切都运行良好,但之前当我输入
ssh
并按 TAB
时,我在 .ssh/config
文件中定义的现有机器获得了自动完成功能,并且正在寻找一种方法来为新机器启用自动完成功能connect
别名。
就我而言,这成功了:
complete -F _ssh connect
启用另一个命令的自动完成,例如
cd
将像这样
complete -F _cd somecommand