Productivity tip: Using the Bash history

The next time you’re using the terminal a lot and want to run a previous command again, try using Bash’s reverse-i-search feature. Type Ctrl-r and enter part of the command. For example, if you’ve recently run make and want to run it again, typing Ctrl-r ma might bring up:

(reverse-i-search)`ma': make

Hitting enter now will run make. If this isn’t the line you wanted, either type more characters or hit Ctrl-r again to show an earlier line matching your search.

I use this all the time in combination with git-svn, because its rebase command needs a clean index (if you’re not familiar with git, this means that there are no uncommitted changes in your tree). To rebase despite a dirty index, you can use the stash like this:

git stash && git svn rebase && git stash apply

But that’s a pain to type over and over, so once I’ve done it once I can type something like Ctrl-r re, and Bash responds with:

(reverse-i-search)`re': git stash && git svn rebase && git stash apply

Although I’ve been talking about Bash here, this is actually a GNU Readline feature, and works the same way in other programs that use Readline or a similar library.

comments powered by Disqus