Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

More Terminal keybindings for the bash shell UNIX
In other *nix prompts, you can do history searches for partial commands. For instance, if you find yourself typing "telnet 192.168.1.12" repeatedly, you can type "tel and hit Page Up to search for the last command you typed that began with "tel" You can hit Page Up repeatedly to find the previous command that began the same way. You can also hit Page Down to go forward in the search if you hit Page Up too many times and missed the command you wanted.

Terminal uses Page Up and Page Down for scrolling, which is great for new users, but seriously slows power users down. Other unices use Shift-Page Up and Shift-PageDown for scrolling.

To restore command completion from history (in bash), you can use (mind the quotes!):
bind '"M-e": history-search-backward'
bind '"M-r": history-search-forward'
This binds Option-E to the reverse search (Page Up on Linux) and Option-R to a forward search (Page Down on Linux). To use this, the "Option (alt) key acts as meta key" item under Emulation in Terminal preferences must be on.

I put these commands in my .profile so that my terminal would always be configured to my tates. I'm sure there's an analogous command in tcsh.

On a side note, if you want a more powerful history search, you can hit Control-R to do a full interactive history search under bash. You hit Control-R at the prompt and type some text. Each letter you type will make the search more detailed. For example, if you want to find the last command that you executed with 192.168.1.12 as a parameter, you can hit Control-R and begin typing the IP. When you type the "1" the last command with a "1" in it will be displayed. When you type "9" the last command with a "19" in it will be displayed, and so on. Hitting Control-R again tries to find another command that matches.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[5,589 views]  

More Terminal keybindings for the bash shell | 1 comments | Create New Account
Click here to return to the 'More Terminal keybindings for the bash shell' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
tcsh
Authored by: pmccann on Jan 01, '02 02:14:57AM

If you're using the default shell in osx (ie tcsh) you get the completion mentioned in the hint via a leading "!". I don't have bash, so I can't verify whether it works this way as well (which would negate the need for the remappings). That is, to get the previous command beginning with "mu" just enter

!mu

and either "tab" (to see what the completion will be) or "return" (if you're confident that you're going to get the correct completion).

The control-R search mechanism also works the same way in tcsh as described above for bash.

Cheers,
Paul



[ Reply to This | # ]