Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Enhance the power of Bash UNIX
Many might not know this, but since version 2.04, Bash offers us a very powerful way to program certain command line completions.

The bash completions scripts (see downloads in the middle of the page) offer an already rather advanced set. Those completions work flawlessly under Mac OS X; you simply need to follow the provided instructions and you are up.

You need an example? Well, then imagine typing ssh [TAB] and seeing all the IP addresses from your known_hosts file. But this is only one example; completion offers hundreds of possibilities to make your life on the CLI easier. Once installed, you can obtain a complete listing of all commands that have associated completions with complete -p.
    •    
  • Currently 2.67 / 5
  You rated: 3 / 5 (3 votes cast)
 
[3,326 views]  

Enhance the power of Bash | 6 comments | Create New Account
Click here to return to the 'Enhance the power of Bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Nice, but..
Authored by: sapporo on Jul 18, '02 01:14:55PM
..this breaks my usual filename completion somehow:
cd;
cd Appl
gets expanded to "Applications " with a trailing space instead of a slash, which won't let me add e.g. "Utilities" without hitting backspace and slash. I'd love to use the extension-specific completion, but this is just too annoying.
Am I missing something?

Thanks, sapporo.

[ Reply to This | # ]

Nice, but..
Authored by: chmod007 on Jul 18, '02 03:41:23PM

Are you really using Bash, not the standard tcsh shell?



[ Reply to This | # ]
Nice, but..
Authored by: mervTormel on Jul 18, '02 05:28:16PM

there is a mention of your situation in the readme, second paragraph of troubleshooting...

"If you find that some commands, such as 'cd /usr<Tab>', end with a trailing
space instead of appending a / ..."



[ Reply to This | # ]
Nice, but..
Authored by: sapporo on Jul 19, '02 05:23:56AM
Ah, missed that. Thanks.
For the record, use bash > 2.04 to avoid this.

[ Reply to This | # ]
Nice, but..
Authored by: sjk on Jul 21, '02 12:37:29AM

I wonder if the mark-directories variable in the readline library interacts/interfers with that. I have "set mark-directories off" in ~/.inputrc because I don't like trailing slashes appended to directories; wish there were also a way to nuke trailing spaces, like "unset addsuffix" in tcsh.

tcsh is still my primary interactive shell, but more recent features like programmable completion in bash tempt me to switch. There are a few tcsh features I utilize in tcsh (e.g. the wordchars variable to set word boundaries) that don't have bash equivalents (yet), but it's really that trailing space appended to filenames after completion that's the biggest issue to full-time conversion.



[ Reply to This | # ]
tcsh has similar (was: Nice, but..)
Authored by: duff on Jul 22, '02 12:28:09AM
tcsh is still my primary interactive shell, but more recent features like programmable completion in bash tempt me to switch.
I haven't looked at the package (as I don't use bash), but I do have programmable completion setup for tcsh. It's done with the 'complete' command and you can override default completion for commands, argument numbers given to commands or even arguments followed by certain options for certain commands -- the completion can be provided either by saying e.g. files ending with .tex to the cammand pdflatex, "just directories" for arguments followed by -I for gcc or by giving a shell variable to use as list or even a command to execute (and use the result as a list of matches). But it's really a mess to setup (man tcsh if you want to have a go at it), but I'd expect it isn't much simpler for bash... this is unix in all its beauty...

[ Reply to This | # ]