Archive for October, 2008

Programmable Autocompletion in Bash

Saturday, October 25th, 2008

I always knew Bash had programmable autocompletion but never knew what it was good for until I came across this snippet:

# tab completion for ssh hosts
SSH_COMPLETE=( $(cat ~/.ssh/known_hosts | cut -f 1 -d ‘ ‘ | \
sed -e s/,.*//g | grep -v \| ) )
complete -o default -W “${SSH_COMPLETE[*]}” ssh

Throw that into your .bashrc. This will search your known hosts file for ssh hosts you’ve connected to so that when you hit tab after entering ssh, you have a list of hosts. Like tab autocomplete for ls, but for remote hosts. Neat! Now to think of other cool uses for this…

A clean slate…

Thursday, October 23rd, 2008

Will post more soon.