Hacker News new | past | comments | ask | show | jobs | submit login
The poor man’s Bash Tab-completion (paksoy.net)
31 points by mustpax on Aug 9, 2009 | hide | past | favorite | 13 comments



Autocomplete known_hosts:

  complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ssh


In similar vain. Autocomplete screen sessions:

  complete -o default -W "$(screen -ls | cut -f 2 -s | tr '\n' ' ')" screen


I use a handwritten list, but this ssh host completion looks like the killer argument for this feature.


The "dynamic" example:

complete -o default -W "`echo $(cat /path/to/file | grep 'lines i want')`" \ [command]

is easier written as

complete -o default -W "`echo $(grep 'lines i want' /path/to/file)`" \ [command]


pipe that grep through | tr '\n' ' ' and you don't need the echo.


That makes a lot of sense, thanks for pointing these out. I'm updating the article to reflect these corrections.


Btw, your updated version has an unnecessary ` lying near the end.


Corrected again :) Thanks.


I didn't know about the $(...) syntax. I've needed this, and resorted to a script, thinking it couldn't be done in a one-liner.

$(command) allows them to be nested arbitrarily, whereas `command` can't nest.


I thought you could escape backticks


You're right, that works too. Now I've learnt two things.


or you could just install zsh and the problem is solved.


It would be more helpful if you actually described what ZSH does differently that solves the problem without manual configuration.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: