-
Notifications
You must be signed in to change notification settings - Fork 2
/
ws
executable file
·114 lines (97 loc) · 2.26 KB
/
ws
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
#!/bin/sh
# workspace management
log () {
printf '%s\n' "tofc: ws: $*"
}
die () {
log "$*"
exit 1
}
usage () {
cat << EOF
tofc ws: workspace expansion pack for tofu
usage: tofc ws <->[opt]
send sends a window to a workspace
init create workspaces
switch switch what workspace is shown
query show shell parseable info
hookc a CREATE hook to attach windows
hookd a DESTROY hook to clean up windows
EOF
}
switch_ws () {
[ -d "$WM/ws/$1" ] || die "workspace $1 not found"
read -r current < "$WM/ws/current"
for win in "$WM/ws/$current"/*; do
tofc unmap "${win##*/}"
done
#printf '%s\n' "false" >> "$WM/ws/$current"/*/mapped
for win in "$WM/ws/$1"/*; do
tofc map "${win##*/}"
done
#printf '%s\n' "true" >> "$WM/ws/$1"/*/mapped
printf '%s\n' "$1" > "$WM/ws/current"
}
remove_win () {
rm "$WM"/ws/*/"$1"
}
add_win () {
read -r current < "$WM/ws/current"
ln -sfT "$WM/fs/$wid" "$WM/ws/$current/$wid"
tofc map "$wid"
}
send_win () {
# tofc ws send $ws $wid
remove_win "$wid"
ln -sfT "$WM/fs/$wid" "$WM/ws/$1/$wid"
read -r current < "$WM/ws/current"
if [ -e "$WM/ws/$current/$wid" ]
then tofc map "$wid"
else
tofc unmap "$wid"
fi
}
init_ws () {
for ws; do
if [ -d "$WM/ws/$ws" ]; then
rm "$WM/ws/$ws"/*
mkdir -p "$WM/ws/$ws"
else
mkdir -p "$WM/ws/$ws"
fi
done
}
query_ws () {
for dir in "$WM"/ws/*; do
i=0
[ -d "$dir" ] && \
for win in $dir/*; do
[ "$win" = "$dir/*" ] && continue
: $(( i = i + 1 ))
done
printf '%s\n' "${dir##*/}: $i"
done
}
clean_wins () {
for file in "$WM"/ws/*; do
[ -d "$file" ] && for win in "$file"/*; do
rm "$win"
done
done
}
main () {
opt="$1"
shift 1
case $opt in
*init) init_ws "$@" ;;
*send) send_win "$@" ;;
*switch) switch_ws "$@" ;;
*query) query_ws "$@" ;;
*hookc) add_win "$@" ;;
*hookd) remove_win "$@" ;;
*clean) clean_wins "$@" ;;
*usage|*help) usage ;;
*) usage && die "not found" ;;
esac
}
main "$@"