aboutsummaryrefslogtreecommitdiff
path: root/bspc/bspcSwapOrMove.sh
blob: 996f1481cf7c971d3a3e01e3b215c2b6118b9bcb (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
#!/bin/sh

# bspcSwapOrMove.sh: A template for sh scripts
#
# Usage: bspcSwapOrMove.sh h|j|k|l

usageMessage="Usage: ${0} h|j|k|l"

error() {
	printf '%s error: %s\n' "$0" "$*" >&2
}

errorAndUsage() {
	printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
}

direction="$1"

step="10"
movementX=""
movementY=""
swapDirection="$1"

case "$direction" in

	"h" )
		movementX="-${step}"
		movementY="0"
		swapDirection="west"
		;;

	"j" )
		movementX="0"
		movementY="${step}"
		swapDirection="south"
		;;

	"k" )
		movementX="0"
		movementY="-${step}"
		swapDirection="north"
		;;

	"l" )
		movementX="${step}"
		movementY="0"
		swapDirection="east"
		;;

	* )
		errorAndUsage "Direction must be h, j, k or l. It was [${direction}]."
		exit 1
		;;

	esac

nodeStatus="$(bspc query -T -n)"
desktopStatus="$(bspc query -T -d)"

if echo "$nodeStatus" | grep -q '"state":"floating"'; then
	bspc node --move "$movementX" "$movementY"
elif echo "$desktopStatus" | grep -q '"layout":"monocle"'; then
	if [ "$swapDirection" = "west" ]; then
		bspc node --swap prev.local.window.!floating
	elif [ "$swapDirection" = "east" ]; then
		bspc node --swap next.local.window.!floating
	fi
else
	bspc node --swap "$swapDirection"
fi