What do you do when you want SSH hostname autocompletion on a mac?
- Don't google the problem directly, instead assume no one has done it before
- Do sudo port install bash-completion for a dependency
- Don't realize that it solved your problem.
- Do write a parser for an ssh known_hosts file in python for fun and name it parse_hostnames.py
- Don't realize you are doing the easy part of the task
- Do modify /opt/local/etc/bash_completion.d/ssh and add in ssh_autocomplete.sh as a section
- Don't realize that while trouble shooting you rewrote the known_hosts parser in bash
- Do pull out the bash known_hosts parser and name it parse_hostnames.sh
- Don't get mad when you realize your autocompletion is almost as good as the one in bash-completion
- Do put your code on Github to attempt to achieve something from all of this
To get SSH hostname completion, all you really need to do is sudo port install bash-completion and add this to the end of your ~/.profile
if [ -f /opt/local/etc/bash_completion ]; then
Other than that is just inserting the text of ssh_autocomplete.sh, placing the parsing scripts in ~/.ssh and picking which parsing script to use.
A good learning experience, not quite functional because it will attempt to use this completion for all options in scp/ssh. It would really require rewriting the _ssh function and adding this as a special case.