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...
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...
*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...
Re: Cheesy
Much appreciated! Formatting is turned off, sorry about that. Good catch on the number filtering!
comment...