Brian's Waste of Time

Mon, 07 Feb 2005

Bash Completion for SSH

Cleaned up my bash commpletion for ssh some, figured I'd put it up so can people can show me what they have that's better ;-)

SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | \
                 cut -f 1 -d ' ' | \
                 sed -e s/,.*//g | \
                 uniq | \
                 egrep -v [0123456789]) )
complete -o default -W "${SSH_COMPLETE[*]}" ssh

You can drop the final egrep -v [0123456789] if you regularly ssh to ip addresses =)

writebacks...

Cheesy


Did you know that you need to sort for uniq to be effective (ie: | sort | uniq)? The following is a little more compact in terms of processes used (note that sort -u is a GNU extension): sed -e 's/ .*//; s/,.*//g' .ssh/known_hosts |\ sort -u |\ egrep '[[:alpha:]]' I replaced your egrep with something that matches anything containing a letter so that you will see hostnames that include numbers. Of course, I could probably have condensed it to a single invocation of awk, but that might be a little dense...

Cheesy


*sigh* Using HTML this time. Did you know that you need to sort for uniq to be effective (ie: | sort | uniq)? The following is a little more compact in terms of processes used (note that sort -u is a GNU extension): sed -e 's/ .*//; s/,.*//g' .ssh/known_hosts |\ sort -u |\ egrep '[[:alpha:]]' I replaced your egrep with something that matches anything containing a letter so that you will see hostnames that include numbers. Of course, I could probably have condensed it to a single invocation of awk, but that might be a little dense...

Brian McCallister

Re: Cheesy
Much appreciated! Formatting is turned off, sorry about that. Good catch on the number filtering!

comment...

 
Name:
URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Spam Guard, translate l33t to English: (hint, it's an Australian animal, plural form)
Comments:
Save my Name and URL/Email for next time