Update primary Canonical mail and a few other small tweaks
[~bandali/configs] / .local / bin / b-ws-util
1 #!/bin/sh
2
3 if [ "$1" = "i3" ]; then
4 msgcmd=i3-msg
5 elif [ "$1" = "sway" ]; then
6 msgcmd=swaymsg
7 else
8 echo "Usage: $0 {i3|sway} {switch|move} {prev|next} [follow]"
9 exit 1
10 fi
11
12 curr_ws=$("$msgcmd" -t get_workspaces | jq -r '.[] | select(.focused==true).name')
13 [ "$curr_ws" -eq 1 ] && prev_ws=10 || prev_ws=$((curr_ws-1))
14 [ "$curr_ws" -eq 10 ] && next_ws=1 || next_ws=$((curr_ws+1))
15 dest_ws=-1
16 op=-1
17
18 if [ "$2" = "switch" ] || [ "$2" = "move" ]; then
19 op="$2"
20 if [ "$3" = "prev" ]; then
21 dest_ws="$prev_ws"
22 elif [ "$3" = "next" ]; then
23 dest_ws="$next_ws"
24 else
25 echo "Usage: $0 $1 $2 {prev|next} [follow]"
26 exit 1
27 fi
28 else
29 echo "Usage: $0 $1 {switch|move} {prev|next} [follow]"
30 exit 1
31 fi
32
33 if [ "$op" = "switch" ]; then
34 i3 workspace "$dest_ws"
35 elif [ "$op" = "move" ]; then
36 i3 move container to workspace "$dest_ws"
37 if [ "$4" = "follow" ]; then
38 i3 workspace "$dest_ws"
39 fi
40 fi