-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi3wpswitch
executable file
·66 lines (53 loc) · 1.16 KB
/
i3wpswitch
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
#!/bin/bash
die() {
echo "$@"
echo "Usage: $0 [next|prev] OUTPUT"
exit 1
}
switch_direction=$1
output=$2
urgent_color="#aa0000"
focus_color="#444444"
delimiter=
[ -z "$switch_direction" -o -z "$output" ] && {
die Output not specified
}
first=
prev=
active=
next=
last=
workspaces=( $(i3-msg -t get_workspaces | jq -r '.[] | select(.output == "DP-0") | "\(.name),\(.focused)"') )
for workspace in "${workspaces[@]}"; do
name=$(cut -d, -f1 <<< "$workspace")
focus=$(cut -d, -f2 <<< "$workspace")
if [ -z "$first" ]; then
first=$name
fi
if [ -z "$active" -a "$focus" = "false" ]; then
prev=$name
fi
if [ "$focus" = "true" ]; then
active=$name
fi
if [ "$focus" != "true" -a -z "$next" -a -n "$active" ]; then
next=$name
fi
done
last=$name
if [ -z "$next" ]; then
next=$first
fi
if [ -z "$prev" ]; then
prev="$last"
fi
switch_to=
if [ "$switch_direction" = "next" ]; then
switch_to=$next
elif [ "$switch_direction" = "prev" ]; then
switch_to=$prev
fi
if [ -z "$switch_to" ]; then
die Couldn\'t deduce a wp to switch to
fi
i3-msg workspace $switch_to | jq -r '.[].success'