Improve Tab Completion in Mac OS X Terminal

Aug 2, 2012 - 5 Comments

Improve Tab Completion in Terminal

Tab completion is a wonderful feature of shells that make power users lives easier, letting you automatically complete commands, paths, file names, and a variety of other things entered into the command line. It works great as is but you can make it even better by enabling a few features; ignore caps lock and casing of commands when completing, remove the necessity to double-tap the Tab key if something is ambiguous, and last but certainly not least, cycle through a menu of all possibilities rather than dumping a humungous list if there is ambiguity.

If you don’t regularly use the OS X Terminal (or a linux terminal) you probably don’t have a use for this tip.

Launch Terminal and be in the home directory to get started:

  • Using emacs, nano, vi, or whatever your favorite text editor is to edit .inputrc, we’ll use nano for the walkthrough:
  • nano .inputrc

  • Paste in the following three rules on unique lines:
  • set completion-ignore-case on
    set show-all-if-ambiguous on
    TAB: menu-complete

  • Hit Control+O to save changes to .inputrc followed by control+X to quit
  • Open a new Terminal window or tab, or type “login” to open a new session with the rules in effect
  • Start typing a command, path, or something else and hit the Tab key to see the improvements firsthand

This has been tested to work with bash shell and should work with any version of Mac OS X. If you enjoyed this, don’t miss our other command line tips and tricks.

Thanks to Kuthair Habboush for the great tip

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

5 Comments

» Comments RSS Feed

  1. Umair says:

    Thanks a lot for the tip. I’m a Windows user and just got a MAC. Your help will really help me getting used to MAC :)

  2. Lauri Ranta says:

    My favorite thing to do in .inputrc is to assign shortcuts to history-search-backward and history-search-forward.

    "\C-p": history-search-backward
    "\C-n": history-search-forward

    If you for example open a new tab and type “def”, control-P would insert the previous command starting with “def”.

  3. William Scott says:

    If you really want intelligent tab completion, along with many other life-simplifying features, take a look at /bin/zsh

    It is arguably a more powerful shell than bash (and resembles ksh in lineage), but is the most user-friendly of the shells that come with Mac OS X.

    One of the finest features is remote file name completion, when using scp or ssh.

    • Derek says:

      In related news, zsh 5.0 was recently released. I would definitely recommend zsh to anyone who uses the terminal frequently.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site