From 4eb1e2255765e02bc1eeaef5bbfaa1b567c9665c Mon Sep 17 00:00:00 2001 From: InigoGutierrez Date: Tue, 20 Sep 2022 14:44:33 +0200 Subject: Fixed a bspc script and created one to swap or move windows. --- bspc/bspcDirectionFocus.sh | 13 +++++---- bspc/bspcSwapOrMove.sh | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100755 bspc/bspcSwapOrMove.sh (limited to 'bspc') diff --git a/bspc/bspcDirectionFocus.sh b/bspc/bspcDirectionFocus.sh index 5222298..f36359b 100755 --- a/bspc/bspcDirectionFocus.sh +++ b/bspc/bspcDirectionFocus.sh @@ -13,14 +13,15 @@ if ! echo "$direction" | grep -Eq '(west)|(south)|(north)|(east)'; then exit 1 fi -status="$(bspc wm --get-status)" +nodeStatus="$(bspc query -T -n)" +desktopStatus="$(bspc query -T -d)" -# If floating (TF) select floating in direction. -# Else if monocle (LM) and west or east select previous or next local window in direction. +# If selected window is floating select floating in direction. +# Else if layout is monocle and west or east select previous or next local window in direction. # Else select non-floating in direction. -if echo "$status" | grep -q ':TF:'; then - bspc node --focus "$direction".floating; -elif echo "$status" | grep -q ':LM:'; then +if echo "$nodeStatus" | grep -q '"state":"floating'; then + bspc node --focus "$direction".floating +elif echo "$desktopStatus" | grep -q '"layout":"monocle"'; then if [ "$direction" = "west" ]; then bspc node --focus prev.local.window.!floating elif [ "$direction" = "east" ]; then 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 -- cgit v1.2.1