Hacker Newsnew | comments | leaders | jobs | submitlogin
The poor man’s Bash Tab-completion (paksoy.net)
30 points by mustpax 183 days ago | 13 comments


7 points by jokull 183 days ago | link

Autocomplete known_hosts:

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

-----

2 points by simonb 183 days ago | link

In similar vain. Autocomplete screen sessions:

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

-----

1 point by beza1e1 183 days ago | link

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

-----

5 points by justinlilly 183 days ago | link

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

-----

8 points by mustpax 183 days ago | link

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

-----

4 points by ivanstojic 183 days ago | link

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]

-----

6 points by lallysingh 183 days ago | link

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

-----

2 points by mustpax 183 days ago | link

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

-----

3 points by lallysingh 183 days ago | link

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

-----

1 point by mustpax 183 days ago | link

Corrected again :) Thanks.

-----

2 points by 10ren 183 days ago | link

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.

-----

2 points by calcnerd256 181 days ago | link

I thought you could escape backticks

-----

2 points by 10ren 180 days ago | link

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

-----




Lists | RSS | Bookmarklet | Guidelines | FAQ | News News | Feature Requests | Y Combinator | Apply | Library

Analytics by Mixpanel