summaryrefslogtreecommitdiff
path: root/contrib/rpws
blob: 33a7cecd8fd54be30a8825aa9665ecbfeb10dc10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/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_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
}

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