aboutsummaryrefslogtreecommitdiff
path: root/bspc/bspcDirectionFocus.sh
blob: 2e76527a45515d79a09c9768e2623096e1ae4bd6 (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
#!/bin/sh

# bspcDirectionFocus.sh: Directionally select node with same floating state
#
# Usage: bspcDirectionFocus.sh DIRECTION

usageMessage="Usage: bspcDirectionFocus.sh DIRECTION"

direction="$1"

if ! echo "$direction" | grep -Eq '(west)|(south)|(north)|(east)'; then
	echo "$usageMessage" 1>&2
	exit 1
fi

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

# If selected window is floating select floating in direction.

if echo "$nodeStatus" | grep -q '"state":"floating'; then
	bspc node --focus "$direction".floating

# Else if layout is monocle and north or south select previous or next local
# window in direction. North and south are chosen over west and east so they
# don't conflict when wanting to select a window in a different screen from a
# monocle layout screen.

elif echo "$desktopStatus" | grep -q '"layout":"monocle"' &&
	echo "$direction" | grep -Eq '(north)|(south)'; then
	if [ "$direction" = "north" ]; then
		bspc node --focus prev.local.window.!floating
	elif [ "$direction" = "south" ]; then
		bspc node --focus next.local.window.!floating
	fi

# Else select non-floating in direction.

else
	bspc node --focus "$direction".!floating
fi