--- rpws.orig 2006-06-10 11:43:09.000000000 -0600 +++ rpws 2006-06-11 15:05:48.000000000 -0600 @@ -11,7 +11,10 @@ # Copyright (C) 2003 Shawn Betts # Author: Shawn Betts # - +# dmw changes: +# 1. made workspace names configurable +# 2. added group toggle feature and mapped to C-g (same as C-t except for groups instead of windows) +# use strict; use Fcntl qw (:flock); use Getopt::Std; @@ -20,6 +23,19 @@ my $tmp=$ENV{ "TMP" } || "/tmp"; my $lockfile = $ENV{ "RPWS_LOCKFILE" } || "$tmp/rpws.$<.lock"; +my @ws_names; +for( my $i = 1; $i <= 9; $i++ ) +{ + $ws_names[$i] = "rpws$i"; +} +# customized workspace names: +$ws_names[1] = "firefox"; +$ws_names[2] = "email"; +$ws_names[3] = "music"; +$ws_names[4] = "admin"; +$ws_names[5] = "school"; +$ws_names[6] = "projects"; + sub help { system("pod2usage", $0); @@ -36,10 +52,9 @@ sub ws_init_ws { - my $num = shift; - rp_call( "gnew wspl$num" ); + rp_call( "gnew $ws_names[$num]" ); my $fd = fdump(); rp_call( "setenv fspl$num $fd" ) } @@ -60,7 +75,7 @@ rp_call( "only" ); my $i; - for( my $i = 0; $i < $num; $i++ ) + for( my $i = 1; $i <= $num; $i++ ) { ws_init_ws( $i ); } @@ -71,6 +86,7 @@ rp_call( "gselect default" ); rp_call( "setenv fspl1 $fd" ); rp_call( "setenv wspl 1" ); + rp_call( "setenv wspl_prev 1" ); # restore the frames rp_call( "frestore $fd" ); @@ -86,6 +102,7 @@ my $ws = rp_call( "getenv wspl" ); my $fd = fdump(); rp_call( "setenv fspl$ws $fd" ); + rp_call( "setenv wspl_prev $ws" ); } sub ws_restore @@ -100,29 +117,40 @@ } else { - rp_call( "gselect wspl$which"); + rp_call( "gselect $ws_names[$which]"); } - rp_call( "echo Workspace $which" ); + rp_call( "echo Workspace: $ws_names[$which]" ); my $last = rp_call( "getenv fspl$which" ); rp_call( "frestore $last" ); rp_call( "setenv wspl $which" ); } +sub ws_toggle +{ + my $old_ws = rp_call( "getenv wspl_prev" ); + ws_restore($old_ws); +} + sub add_aliases { my $n = shift; foreach my $i (1..$n) { rp_call ( "alias rpws$i exec $0 $i" ); } + rp_call ( "alias rpws_toggle exec $0 toggle" ); } sub add_keys { my $n = shift; foreach my $i (1..$n) { - rp_call ( "definekey top M-F$i rpws$i" ); + #rp_call ( "definekey top C-$i rpws$i" ); + # dmw hack: don't know why definekey doesn't work, but it doesn't: + rp_call ( "bind C-$i rpws$i" ); } + #rp_call ( "definekey top C-g rpws$i" ); + rp_call ( "bind C-g rpws_toggle" ); } my $arg = shift @ARGV || 'help'; @@ -137,9 +165,16 @@ add_aliases( $num ) if $opts{'a'} || $opts{'k'}; add_keys ( $num ) if $opts{'k'}; } else { - open LOCK, ">>$lockfile" or die "Cannot open lockfile: $lockfile"; - flock(LOCK, LOCK_EX); - ws_restore( $arg ); + open LOCK, ">>$lockfile" or die "Cannot open lockfile: $lockfile"; + flock(LOCK, LOCK_EX); + if ( $arg eq "toggle" ) { + ws_toggle(); + } elsif ( $arg eq "current" ) { + my $cws = rp_call( "getenv wspl" ); + print "$cws"; + } else { + ws_restore( $arg ); + } } __END__ @@ -155,6 +190,8 @@ -k sets up key bindings and aliases. rpws help - this documentation rpws n - switch to this workspace + rpws toggle - switch to previous workspace + rpws current - print the index of the current workspace =head1 DESCRIPTION @@ -169,8 +206,9 @@ exec /path/to/rpws init 6 -k -This creates 6 aliases rpws1, rpws2, etc. It also binds the keys M-F1, -M-F2, etc to each rpwsN alias. +This creates 6 aliases rpws1, rpws2, etc. It also binds the keys C-1, +C-2, etc to each rpwsN alias. Workspace names can be configured at the +top of this script. =head1 FILES