I'm probably one of the last production users of ratpoison, a Window Manager for Linux designed to avoid using the mouse. But I don't care, it's just brilliant software. When I initially set it up, I made a few tweaks (for example, setting Caps Lock as the Escape key) and pretty much left it alone.
Recently, I decided it was time to streamline things a bit. I found that I had a number of standard window configurations I was switching between (Work Browser + Xterm, Emacs + Development Browser, etc.) and I wanted a single keystroke to jump me to these. I experimented with fancy virtual desktops, but in the end, went with a simple solution.
First, I needed to make sure my .xmodmap configuration was setup correctly. Here's the code I have in place to map the Caps Lock key to Hyper and the Windows key to Super:
clear lock clear control clear mod1 clear mod2 clear mod3 clear mod4 clear mod5 keycode 66 = Hyper_L add control = Control_L Control_R add mod1 = Alt_L Alt_R Meta_L add mod2 = Num_Lock add mod3 = Hyper_L add mod4 = Super_L Super_R add mod5 = Mode_switch ISO_Level3_Shift
Next up, I set up the following new keystrokes in my .ratpoisonrc:
definekey top s-j exec rpwin restore J definekey top s-k exec rpwin restore K definekey top s-l exec rpwin restore L definekey top s-h exec rpwin restore H definekey top s-J exec rpwin capture J definekey top s-K exec rpwin capture K definekey top s-L exec rpwin capture L definekey top s-H exec rpwin capture H
The H K L J keystrokes are inspired by vi, of course. Holding down Shift + Windows Key + J grabs whatever the current window configuration is and stores it (that is, it runs rpwin capture J). Pressing Windows Key + J updates the screen to re-show the stored window configuration. In other words, I now have four keystrokes I can quickly setup as different window configurations, and a fast way to access them. After a couple of weeks of use, I'm totally loving this.
Below is the rpwin script that captures and restores the window configuration.
#!/bin/bash ## A shell script for capturing / restoring ratpoison window configurations RATPOISON=ratpoison RP_SNAPSHOT=$HOME/.rp.snapshot usage() { echo "Usage: `basename $0` {capture|restore}" exit 1 } rp_cmd() { $RATPOISON -c "$@" } case "$1" in capture) if [ -n "$2" ] ; then loc=$2 else loc='default' fi touch $RP_SNAPSHOT.$loc rp_cmd sfdump > $RP_SNAPSHOT.$loc ;; restore) if [ -n "$2" ] ; then loc=$2 else loc='default' fi if [ -s $RP_SNAPSHOT.$loc ] ; then rp_cmd "sfrestore `cat $RP_SNAPSHOT.$loc`" else echo "Refusing to restore an empty snapshot" exit fi ;; *) usage ;; esac
No comments:
Post a Comment