Is there a way to make bash more TAB friendly?

6,702

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.

Share:
6,702

Related videos on Youtube

Frank Krueger
Author by

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, 2022

Comments

  • Frank Krueger
    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
    Alex over 12 years
    what is the procedure to do this for OSx terminal?
  • Chris Johnsen
    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 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.
  • Alex
    Alex over 12 years
    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.
  • Chris Johnsen
    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
    Alex over 12 years
    I'm on 10.6.8 and my default is showing up as 'sh'
  • Chris Page
    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 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.
  • ppp
    ppp over 10 years
    Does anyone have any idea what should I bind to go one option back with Shift + Tab?
  • vault
    vault about 8 years
    @ppp in your .bashrc: bind '"\e[Z":menu-complete-backward'