Bash keybindings

Posted at 2007-01-20 13.05

Some wonderful person (I can't believe it was me) made me a .initrc file for my work home directory. It contained one line:

set mark-directories off

I wouldn't press you to go out and copy me, for its effect is to stop tab-completion from putting the trailing / onto a completed directory name, so you have to do cd //….

One of my colleagues found this config item and thus fixed this terrible problem I'd been having.

However, this led me to reading more about bash and its interaction with readline. It turns out that you can bind commands to a bash key combination. This has the effect of running the command at that point, regardless of whether or not you're in the middle of editing another command.

I bound M-'-' to pushd ..' and M-'=' to 'popd'. This lets you zoom up the filesystem tree, then zoom back in once you're finished with it. Very handy:

bind -x '"\M--": pushd ..'
bind -x '"\M-=": popd'

I'd be interested to hear what bindings you come up with.


1 Comment for 'Bash keybindings'

  1.  
    2007-02-27 | 20.23 +0000
     

    Clever. Here’s a quick "port" to zsh:

    function up-one-dir { set -E; pushd ..; set +E; zle redisplay; zle -M `pwd` }
    function back-one-dir { set -E; popd; set +E; zle redisplay; zle -M `pwd` }
    zle -N up-one-dir
    zle -N back-one-dir
    bindkey "^[-" up-one-dir
    bindkey "^[=" back-one-dir

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI

 
ok