Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] bash completion #35

Open
sbonnegent opened this issue Mar 20, 2012 · 1 comment
Open

[doc] bash completion #35

sbonnegent opened this issue Mar 20, 2012 · 1 comment

Comments

@sbonnegent
Copy link

We use this to do bash completion on sshgate command, maybe can be usefull:

We define 2 alias in .bash_aliases:

alias sshgate="ssh -Xt sshgate@YOUR_SERVER"
alias update_sshgate="ssh sshgate@YOUR_SERVER cmd list targets > ~/.sshgate_list_targets.txt"

And in your .bashrc:

_sshgate_hosts()
{
local args cur opts
COMPREPLY=()

argc : parameters number

argc=${COMP_CWORD}

cur : current word

cur="${COMP_WORDS[argc]}"

targets list

opts=""

if [ ! -e ~/.sshgate_list_targets.txt ]
then
/usr/bin/ssh sshgate@YOUR_SERVER cmd list targets > ~/.sshgate_list_targets.txt
fi

for i in $(cat ~/.sshgate_list_targets.txt)
do
opts="$opts $i"
done

we search $cur in targets list

COMPREPLY=( $(compgen -W "$opts" -- $cur ) )
}
complete -F _sshgate_hosts sshgate

An example:

cat ~/.sshgate_list_targets.txt
root@server1
root@server2
root@server3

sshg[TAB]
sshgate [TAB]
sshgate root@server[TAB][TAB]
root@server1
root@server2
root@server3

@beudbeud
Copy link

hi i'm use auto completion for sshgate

in your .bashrc

gatehost=sshg 'cmd list targets' | tr -d $'\r' | sed 's/root@//g' 2>&1
complete -W "$gatehost" sshg
complete -o nospace -F _scp -W "$gatehost" scpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants