By spencer, Tuesday, October 21, 2008 · 4:30 pm

My favorite BASH shell completion of all time is hostname completion for all of my favorite commands:

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 scp sftp rsync nmap traceroute ping nslookup dig host nmap nc

I find most of the hosts I ssh into I use for basic network diagnostics. So performing completion for traceroute, ping, etc based on the contents of known_hosts works great. Just add it to your .bashrc.

Update: 2008/11/04

I’ve modified it to support completion of SVN commands leveraging the hostnames expanded during the SSH completion above:

SVN_COMPLETE=( $(svn -h|grep -e '^ '|awk '{ print $1; }') $SSH_COMPLETE )
complete -o default -W "${SVN_COMPLETE[*]} ${SSH_COMPLETE[*]}" svn

Adding these may lengthen your shell exec tasks.

I test at work. I work from home. But I will not test from home. Fix it yourself. (trademark pending).

Add your own comment or set a trackback

Currently 2 comments

  1. Comment by Bobby

    Yo Spence. Seriously man, what language do you speak these days. Just kidding man. Really dude, hit me up sometime. Just got in touch with Collier down in Costa Rica. But maybe someday you will join that joe the plumber facebook someday. Anyways, hope life is going okay for ya. Peace man.

    bobbo
    meachamrob@netscape.net

  2. Comment by spencer

    Bob-o I’m going to have to introduce you to email one day. My address is all over this site ;)

Add your own comment

Powered by WP Hashcash



Follow comments according to this article through a RSS 2.0 feed


Jump to start of page | Jump to posts