summaryrefslogtreecommitdiff
path: root/contrib/rpws
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/rpws')
-rwxr-xr-xcontrib/rpws255
1 files changed, 168 insertions, 87 deletions
diff --git a/contrib/rpws b/contrib/rpws
index 2b091d0..580495f 100755
--- a/contrib/rpws
+++ b/contrib/rpws
@@ -1,118 +1,199 @@
-#!/usr/bin/env bash
+#!/usr/bin/perl -w
+
+#
+# Copyright (c) 2005 Mike O'Connor
+# All rights reserved.
+# Author Mike O'Connor <stew@vireo.org>
#
-# Workspaces for ratpoison
+# Modified by Shawn Betts.
+#
+# code was adapeted from rpws that comes from ratpoison containing the follwing copyright:
# 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:
-#
+use strict;
+use Fcntl qw (:flock);
+use Getopt::Std;
+
+my $ratpoison = $ENV{ "RATPOISON" } || "ratpoison";
+my $tmp=$ENV{ "TMP" } || "/tmp";
+my $lockfile = $ENV{ "RPWS_LOCKFILE" } || "$tmp/rpws.$<.lock";
-# This allows outside scripts to tell this script where to find
-# ratpoison.
-if [ -z $RATPOISON ]; then
- RATPOISON=ratpoison
-fi
+sub help
+{
+ system("pod2usage", $0);
+ print( "for more detailed documentation run \"perldoc $0\"\n" );
+}
+
+sub rp_call
+{
+ my $result = `$ratpoison -c "@_"`;
+ chomp( $result );
+ chomp( $result );
+ return $result;
+}
-rp_call ()
+sub ws_init_ws
{
- $RATPOISON -c "$*"
+
+ my $num = shift;
+
+ rp_call( "gnew wspl$num" );
+ my $fd = fdump();
+ rp_call( "setenv fspl$num $fd" )
}
-ws_init_ws ()
+sub fdump
{
- rp_call gnew ws$1
- rp_call setenv fs$1 `rp_call fdump`
+ return rp_call( "fdump" );
}
-ws_init ()
+sub ws_init
{
+ my $num = shift;
+
# 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
+ my $fd = fdump();
+ rp_call( "select -" );
+ rp_call( "only" );
+
+ my $i;
+ for( my $i = 0; $i < $num; $i++ )
+ {
+ ws_init_ws( $i );
+ }
+
# 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
+ $fd = fdump();
+ rp_call( "gselect default" );
+ rp_call( "setenv fspl1 $fd" );
+ rp_call( "setenv wspl 1" );
# restore the frames
- rp_call frestore $FS
+ rp_call( "frestore $fd" );
+
+ if( -e "$lockfile" )
+ {
+ unlink ("$lockfile" );
+ }
}
-ws_save ()
+sub ws_save
{
- WS=`rp_call getenv ws`
- rp_call setenv fs$WS `rp_call fdump`
+ my $ws = rp_call( "getenv wspl" );
+ my $fd = fdump();
+ rp_call( "setenv fspl$ws $fd" );
}
-ws_restore ()
+sub ws_restore
{
- ws_save
- if [ $1 == 1 ]; then
- rp_call gselect default
+ my $which = shift;
+
+ ws_save();
+
+ if( $which == 1 )
+ {
+ 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
+ {
+ rp_call( "gselect wspl$which");
+ }
+
+ rp_call( "echo Workspace $which" );
+ my $last = rp_call( "getenv fspl$which" );
+ rp_call( "frestore $last" );
+ rp_call( "setenv wspl $which" );
}
-ws_bindings ()
+sub add_aliases
{
- # 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
+ my $n = shift;
+ foreach my $i (1..$n) {
+ rp_call ( "alias rpws$i exec $0 $i" );
+ }
}
-if [ -z $@ ]; then
- echo "Usage:"
- echo "$0 -i -- initialize the workspaces"
- echo "$0 -b -- setup some key bindings"
- echo "$0 <n> -- Switch to workspace n"
-else
- if [ $1 == -i ]; then
- ws_init
- elif [ $1 == -b ]; then
- ws_bindings
- else
- ws_restore $1
- fi
-fi
+sub add_keys
+{
+ my $n = shift;
+ foreach my $i (1..$n) {
+ rp_call ( "definekey top M-F$i rpws$i" );
+ }
+}
+
+my $arg = shift @ARGV || 'help';
+
+if( $arg eq "help" ) {
+ help();
+} elsif( $arg eq "init" ) {
+ my $num = shift @ARGV;
+ my %opts;
+ ws_init( $num );
+ getopts('ka', \%opts);
+ 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 );
+}
+
+__END__
+
+=head1 NAME
+
+rpws - Implements multiple workspaces in ratpoison
+
+=head1 SYNOPSIS
+
+ rpws init n [-k] [-a] - setup rpws with n workspaces.
+ -a sets up command aliases;
+ -k sets up key bindings and aliases.
+ rpws help - this documentation
+ rpws n - switch to this workspace
+
+
+=head1 DESCRIPTION
+
+ B<rpws> implements multiple workspaces in ratpoison by making calls
+ to fdump, freestore. It was adapted from rpws which comes with
+ ratpoison in the contrib directory.
+
+=head1 USAGE
+
+Add the following line in ~/.ratpoisonrc
+
+ 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.
+
+=head1 FILES
+
+ rpws requires use of a lockfile. It defaults to using
+/tmp/rpws.<UID>.lock but this can be changed by setting the
+environment variable RPWS_LOCKFILE to your desired lockfile.
+
+=head1 AUTHOR
+
+ Mike O'Connor <stew@vireo.org>
+
+=head1 COPYRIGHT
+
+ Copyright (c) 2005 Mike O'Connor
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+