helm/config/bspwm/bin/bspc-focus

45 lines
1,005 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# bspc-focus
# Jump to the next window in a direction. If -m is supplied, jump to the next
# monitor in that direction.
#
# Makes switching nodes more intuitive.
#
# Usage: bspc-focus [-m] (west|south|north|east)
# Example:
# + bspc-focus south
# + bspc-focus -m west
set -e
leap=
if [[ $1 == -m ]]; then
leap=1; shift
fi
dir=$1
opposite=
case $dir in
west) opposite=east ;;
east) opposite=west ;;
north) opposite=north ;;
south) opposite=south ;;
*) >&2 echo "Not a valid direction: $dir"
exit 1
esac
if [[ -n $leap ]]; then
# jump to monitor in direction
bspc monitor -f "$dir"
else
# jump to window in direction (unless at edge of last monitor)
if ! bspc node -f "$dir.local"; then
if [[ $(bspc query -M -m "$dir") ]]; then
bspc monitor -f "$dir"
# Ensure we start at the edge of the window we arrived from
while bspc node -f "$opposite.local"; do :; done
fi
fi
fi