Is there a way to make bash more TAB friendly?
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.
Related videos on Youtube
Frank Krueger
I am an engineer living in Seattle. I have been programming for about 15 years. I started out with video game hacking with the Code Alliance. Moved on to embedded systems development in an R&D group at GM. Did way too much graphics (3D) programming. Then did a lot of network programming for large data centers. Was forced to get my Master's in Electrical Engineering. Got into compiler and interpreter development. Spent some time coding at Microsoft. Moved on a year later to start my own company creating control systems and web apps. I love programming and have spent way too much time learning too many languages, frameworks, APIs, paradigms, and operating systems.
Updated on September 17, 2022Comments
-
Frank Krueger over 1 year
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?
-
Alex over 12 yearswhat is the procedure to do this for OSx terminal?
-
Chris Johnsen over 12 years@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 likesource ~/.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 commandopen -e ~/.bashrc
; if the file does not yet exist, you will need to create it first with (e.g.) the commandtouch ~/.bashrc
. -
Alex over 12 yearsIt 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.
-
Chris Johnsen over 12 years@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: apple.stackexchange.com/q/7984/3349 superuser.com/a/267627/14827
-
Alex over 12 yearsI'm on 10.6.8 and my default is showing up as 'sh'
-
Chris Page almost 12 years@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 withchpass -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. -
ppp over 10 yearsDoes anyone have any idea what should I bind to go one option back with Shift + Tab?
-
vault about 8 years@ppp in your
.bashrc
:bind '"\e[Z":menu-complete-backward'