This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratSpaces.sh
executable file
·179 lines (149 loc) · 4.32 KB
/
ratSpaces.sh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
# Author: Daniel Noland
# Date: 2013-07-25
# This is a simple helper script which lets me find the ratpoison "implementation"
# of work spaces to be tolerable.
# Convenience functions
# =====================
# compute the total number of groups
totalGroups() {
echo -e $(ratpoison -c "groups" | wc -l)
}
# return current group number
getCurrentGroupNumber() {
echo -e $(ratpoison -c "groups" | sed -e "/\*[0-9]*/!d" -e "s/\*.*//")
}
# return current window number
getCurrentWindowNumber() {
echo -e $(ratpoison -c "windows" | sed -e "/[0-9]*\*/!d" -e "s/\([0-9]*\)\*.*/\1/")
}
# return current group name
getCurrentGroupName() {
echo -e $(ratpoison -c "groups" | sed -e "/[0-9]*\*/!d" -e "s/[0-9]*\*//")
}
# return current window name
getCurrentWindowName() {
echo -e $(ratpoison -c "windows" | sed -e "/[0-9]*\*/!d" -e "s/[0-9]*\*\(.*\)/\1/")
}
# get next group number
getNextGroupNumber() {
local group=$(( $(getCurrentGroupNumber) + 1 ))
local group=$(( $group % $(totalGroups) ))
echo $group
}
# get previous group number
getPreviousGroupNumber() {
local group=$(( $(getCurrentGroupNumber) - 1 ))
[ $group -lt 0 ] && group=$(( $(totalGroups) - 1 ))
echo $group
}
# change to group number (provided by first argument),
# update the screen to display a window specific to that group,
# and print the current group scan
changeToGroupNumber() {
#move to that group
ratpoison -c "gselect $1"
ratpoison -c "select -"
ratpoison -c "next"
scanAllGroups
}
# "Public Facing" Functions
# =========================
# return a formatted list of all the windows in all the groups
# with marks to indicate the active window and group
scanAllGroups() {
local initialGroup=$(getCurrentGroupNumber)
local output=""
for (( i=0; i<$(totalGroups); i++ ))
do
local mark="---"
[ $i -eq $initialGroup ] && mark="***"
ratpoison -c "gselect $i"
name=$(getCurrentGroupName)
output+=$mark$name$mark'\n'$(ratpoison -c "windows")'\n'
done
ratpoison -c "gselect $initialGroup"
ratpoison -c "echo $(echo -e ${output})"
}
# Send the current window to the next group
sendWindowToNextGroup() {
ratpoison -c "gmove $(getNextGroupNumber)"
ratpoison -c "next"
scanAllGroups
}
# Send the current window to the previous group
sendWindowToPreviousGroup() {
ratpoison -c "gmove $(getNextPreviousNumber)"
ratpoison -c "next"
scanAllGroups
}
# Send the current window to the next group and switch to the next group
followWindowToNextGroup() {
ratpoison -c "gmove $(getNextGroupNumber)"
changeToGroupNumber $(getNextGroupNumber)
scanAllGroups
}
# Send the current window to the previous group and switch to the next group
followWindowToPreviousGroup() {
ratpoison -c "gmove $(getPreviousGroupNumber)"
changeToGroupNumber $(getPreviousGroupNumber)
scanAllGroups
}
# swap the active window on this monitor with screen on the next
#swapScreens() {
# local currentWindow=$(getCurrentWindowNumber)
# ratpoison -c "select -"
# ratpoison -c "nextscreen"
# local otherWindow=$(getCurrentWindowNumber)
# # this is not optional if you want it to correctly swap to blank
# # windows.
# ratpoison -c "select -"
# ratpoison -c "select $currentWindow"
# ratpoison -c "prevscreen"
# ratpoison -c "select $otherWindow"
#}
# swap the active window on this monitor with screen on the next
swapScreens() {
local firstScreenNumber=$(ratpoison -c info | sed -e 's/.*\([0-9]\)(.*/\.*1/')
local firstFDump=$(ratpoison -c "fdump")
ratpoison -c "select -"
ratpoison -c "nextscreen"
local secondScreenNumber=$(ratpoison -c info | sed -e 's/.*\([0-9]\)(.*/\.*1/')
local secondFDump=$(ratpoison -c "fdump")
ratpoison -c "select -"
ratpoison -c "frestore $firstFDump"
ratpoison -c "prevscreen"
ratpoison -c "frestore $secondFDump"
}
# pick action based on incoming argument
case "$1" in
"scan")
scanAllGroups
;;
"inc")
changeToGroupNumber $(getNextGroupNumber)
;;
"dec")
changeToGroupNumber $(getPreviousGroupNumber)
;;
"sendn")
sendWindowToNextGroup
;;
"sendp")
sendWindowToPreviousGroup
;;
"follown")
followWindowToNextGroup
;;
"followp")
followWindowToPreviousGroup
;;
"swap")
swapScreens
;;
*)
echo "invalid option $1"
exit 1;
;;
esac
exit 0