#!/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