---
title: 'Quick Tip: some .inputrc fun'
date: 2011-09-25 08:52
slug: quick-tip-some-inputrc-fun
categories:
- Code
tags:
- experiments
- inputrc
- quicktip
- terminal
---

*[Quick tips](http://brettterpstra.com/tag/quicktip/) are random posts regarding something I discovered on my way to something bigger. They usually get longer than "quick" would imply, for which I refuse to apologize.*

<img src="/uploads/2011/09/old-typewriter-keys.jpeg" alt="" title="old typewriter keys" width="650" height="138" class="aligncenter size-full wp-image-2842" />

I was playing around with some `readline` options this morning, after reading [this post](http://www.reddit.com/r/commandline/comments/kbeoe/you_can_make_readline_and_bash_much_more_user/) on [Reddit Commandline](http://www.reddit.com/r/commandline/). A few of them wouldn't work for me, so I did some research into the version of Bash that comes with OS X.

<!--more-->

Specifically, I wanted to get `menu-complete-backward` to work in my `~/.inputrc` file. `menu-complete` is a cool feature where you bind a key combination and typing it cycles through available completions. It follows, then, that `menu-complete-backward` would cycle in the reverse order. It turns out you need a special escape sequence to pull this off on OS X. 

Say you want to bind the Tab key to cycle completions one at a time instead of listing them all and requiring you to type characters until there's only one match. In your `.inputrc` you would include:

	TAB: menu-complete

Binding Shift-Tab to go backward is a little tricker:

	"\e[Z": "\e-1\C-i"
	
The above is working perfectly for me in iTerm2 on GNU Bash 3.2.48(1)-release-(x86_64-apple-darwin11). It will take a few days to decide if I prefer this completion to the normal Tab-complete behavior or whether I want to bind this to a secondary key combination. Either way, it's handy info to have.

While I'm on the subject, I was playing around with binding commands a while ago and added a couple to my `.inputrc` which I've found helpful. The following will bind Option-z to run `cd -` followed by `ls`, returning you to the previous directory in your stack and doing a file listing in one keystroke:

	"\ez": 'cd -\015ls\015'

The `\015` in the command is the return key, so it's entering `cd -`, executing with return, then repeating with `ls`. You could add any parameters you want (`ls -aF`) if you don't already have it aliased in your `.bash_profile`.

The next one binds Option-x to `cd` to the folder that was the last argument in my previous command. If I run `cp myfile.txt ~/Desktop/`, then hitting Option-X will take me to `~/Desktop/` and list its contents:

	"\ex": 'cd !$\015ls\015'
	
Just some Terminal fun... to be clear, all of the above commands would go into the `.inputrc` file in your home folder. Create it if it doesn't exist, and be sure to restart your bash shell before trying them out.

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
