Is there a way to make bash more TAB friendly?

31

18

I use bash on both my Mac and as my cygwin shell. Overall, I'm quite pleased with it.

My one complaint however is that its TAB completion isn't as good as Windows Command Line TAB completion.

For example, if there are two files with the same prefix, then bash just beeps at me when I try to TAB complete. If I keep nailing TAB, then it will eventually show me a list of potential files.

I definately prefer how Windows will cycle through potential files right on the command line.

Is there a way to get bash to operate similar to Windows Command Line in this regard?

If there isn't (I do not want to switch shells), am I missing something about TAB completion in bash? Is there a more efficient way to use it?

Frank Krueger

Posted 2009-10-22T23:21:58.337

Reputation: 976

Answers

42

To get the ‘cycle through possible completions’ behavior, copy the following into an appropriate place in your .bashrc file:

[[ $- = *i* ]] && bind TAB:menu-complete

Also, bash-completion provides many extra kinds of completion besides just pathname completion. For example, menu-complete works fine with Git's bash-completion module to complete command names, option names, etc.

Chris Johnsen

Posted 2009-10-22T23:21:58.337

Reputation: 31 786

3@ppp in your .bashrc: bind '"\e[Z":menu-complete-backward' – vault – 2016-02-23T10:24:40.180

what is the procedure to do this for OSx terminal? – Alex – 2011-11-30T14:19:40.590

2@Alex: You edit the file .bashrc in your home directory so that it contains the specified line. If your .bash_profile file (in the same directory) does not also have a line like source ~/.bashrc, then you should also edit it to include such a line. The setting will be active in new Terminal windows. If you do not have a preferred editor, you can open the file in TextEdit with the command open -e ~/.bashrc; if the file does not yet exist, you will need to create it first with (e.g.) the command touch ~/.bashrc. – Chris Johnsen – 2011-12-01T02:46:38.013

It seems that bash isn't default for OSx. So I have to type in 'bash' to take advantage of the feature. I also noticed that autocomplete does not distinguish between folders and files, so when I type 'cd ' and hit TAB files will also be cycled. – Alex – 2011-12-01T19:07:29.843

@Alex: bash is the default in 10.3–10.6, I suppose it may have changed in Lion though (note: migrated accounts will retain their original shell, and the preferences of Terminal can change the shell it starts in its windows). If you have further questions, you should search for them or ask them as new questions since they would likely be out of scope in this particular question; here are a couple of pointers to posts you might be interested in: http://apple.stackexchange.com/q/7984/3349 http://superuser.com/a/267627/14827

– Chris Johnsen – 2011-12-01T22:02:06.293

I'm on 10.6.8 and my default is showing up as 'sh' – Alex – 2011-12-06T14:38:30.337

1@Alex, Bash is the default shell on 10.3 and later, including 10.7 (Lion). First echo $SHELL. That will be the shell selected for your user account. If that’s not what you want, you’ll need to change your shell with chpass -s /bin/bash (or whatever shell you want). If $SHELL is fine, then check Terminal > Preferences > Startup > Shells open with: and Terminal > Preferences > Settings > Profiles > Shell > Startup to see if the default user shell has been overridden with a custom command. – Chris Page – 2012-06-14T20:31:33.360

5Does anyone have any idea what should I bind to go one option back with Shift + Tab? – ppp – 2014-01-02T08:12:40.397