Monday, September 19, 2016

More Ratpoison Tweaking: Quick Access to any Program

I'm continuing my journey to optimize ratpoison. My latest tweak: binding keys that bring up specific programs. For example Windows + e now pops emacs front and center.

I accomplished this by enhancing the rpwin script I'd previously created. Here's the latest version:

#!/bin/bash

## A shell script for capturing / switching / deleting / etc.
## ratpoison window configurations

RATPOISON=ratpoison
RP_SNAPSHOT=$HOME/.rp.snapshot


usage() {
  echo "Usage: `basename $0` {capture|restore|goto}"
  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
    ;;
  goto)
    win=`rp_cmd windows | grep -i "$2" | sed 's/[^0-9].*//' | head -1`
    if [ -n "$win" ]; then
      rp_cmd "select $win"
    fi
    ;;
  *)
    usage
    ;;
esac

The above script includes a new sub command: goto. To use this new command, I added the following bindings to my .ratpoisonrc:

definekey top s-o exec rpwin goto Gimp
definekey top s-e exec rpwin goto emacs

And just like that Windows + o pops up Gimp and Windows + e pops up emacs. I'm loving the ability to quickly save and restore window configurations, and I find that this new 'goto' capability works well with it. The standard configurations cover most cases and the quick jump lets me get to programs I use less frequently (like Gimp) or need more often (like emacs).

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails