diff options
Diffstat (limited to 'bspc/bspcSwapOrMove.sh')
-rwxr-xr-x | bspc/bspcSwapOrMove.sh | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/bspc/bspcSwapOrMove.sh b/bspc/bspcSwapOrMove.sh new file mode 100755 index 0000000..996f148 --- /dev/null +++ b/bspc/bspcSwapOrMove.sh @@ -0,0 +1,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 |