为调用 SSH 的函数启用 SSH 自动完成功能

问题描述 投票:0回答:1

我在

.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
别名。

bash bash-completion
1个回答
0
投票

就我而言,这成功了:

complete -F _ssh connect

启用另一个命令的自动完成,例如

cd
将像这样

complete -F _cd somecommand
© www.soinside.com 2019 - 2024. All rights reserved.