#!/usr/bin/env bash # # Workspaces for ratpoison # Copyright (C) 2003 Shawn Betts # Author: Shawn Betts # # To enable workspaces, put the following lines in your .ratpoisonrc # file: # # exec rpws -i # exec rpws -b # # The first line initializes the workspaces (never call this more than # once or it will clutter ratpoison with duplicate window groups). The # second line sets up some keybindings: # # C-t M-1 Workspace 1 # C-t M-2 Workspace 2 # ... # C-t M-7 Workspace 7 # # You want more workspaces? Edit this script. # # FIXME: Currently this depends on bash because I can't figure out how # to pass argument to these functions. In bash $1 ... $n are bound to # them, not so in plain bourne. # # Code: # # This allows outside scripts to tell this script where to find # ratpoison. if [ -z $RATPOISON ]; then RATPOISON=ratpoison fi rp_call () { $RATPOISON -c "$*" } ws_init_ws () { rp_call gnew ws$1 rp_call setenv fs$1 `rp_call fdump` } ws_init () { # Backup the frames FS=`rp_call fdump` rp_call select - rp_call only # Make 6 workspaces ws_init_ws 2 ws_init_ws 3 ws_init_ws 4 ws_init_ws 5 ws_init_ws 6 ws_init_ws 7 # Workspace 1 uses the 'default' group. # Start in workspace 1. rp_call gselect default rp_call setenv fs1 `rp_call fdump` rp_call setenv ws 1 # restore the frames rp_call frestore $FS } ws_save () { WS=`rp_call getenv ws` rp_call setenv fs$WS `rp_call fdump` } ws_restore () { ws_save if [ $1 == 1 ]; then rp_call gselect default else rp_call gselect ws$1 fi rp_call echo Workspace $1 rp_call frestore `rp_call getenv fs$1` rp_call setenv ws $1 } ws_prev () { ws_save current=`rp_call getenv ws` if [ $current == 1 ]; then new=7 rp_call gselect $ne elif [ $current == 2 ]; then new=1 rp_call gselect default else let new=$current-1 rp_call gselect $new fi rp_call echo Workspace $new rp_call frestore `rp_call getenv fs$new` rp_call setenv ws $new } ws_next () { ws_save current=`rp_call getenv ws` if [ $current == 7 ]; then new=1 rp_call gselect default else let new=$current+1 rp_call gselect $new fi rp_call echo Workspace $new rp_call frestore `rp_call getenv fs$new` rp_call setenv ws $new } ws_bindings () { # Use $0 so we know the name and location of the script to call. rp_call bind M-1 exec $0 1 rp_call bind M-2 exec $0 2 rp_call bind M-3 exec $0 3 rp_call bind M-4 exec $0 4 rp_call bind M-5 exec $0 5 rp_call bind M-6 exec $0 6 rp_call bind M-7 exec $0 7 rp_call bind P exec $0 -p rp_call bind N exec $0 -n } if [ -z $@ ]; then echo "Usage:" echo "$0 -i -- initialize the workspaces" echo "$0 -b -- setup some key bindings" echo "$0 -- Switch to workspace n" echo "$0 -p -- Switch to previous workspace" echo "$0 -n -- Switch to next workspace" else if [ $1 == -i ]; then ws_init elif [ $1 == -b ]; then ws_bindings elif [ $1 == -p ]; then ws_prev elif [ $1 == -n ]; then ws_next else ws_restore $1 fi fi