diff options
author | xero <x@xero.nu> | 2017-01-22 23:22:55 -0500 |
---|---|---|
committer | xero <x@xero.nu> | 2017-01-22 23:22:55 -0500 |
commit | 5a4d4a06a287985fbf5b458056881d3d0a0c71aa (patch) | |
tree | 0daa8de87d60c396ca3dbadccbdfe735fc5f72d8 /wmutils/bin/closest.sh | |
parent | 4d6c6b497c3e4d5d6bd4e7728f42303f23120f27 (diff) | |
download | dotfiles_ascii-5a4d4a06a287985fbf5b458056881d3d0a0c71aa.tar.xz dotfiles_ascii-5a4d4a06a287985fbf5b458056881d3d0a0c71aa.zip |
add wmutils setup
Diffstat (limited to 'wmutils/bin/closest.sh')
-rwxr-xr-x | wmutils/bin/closest.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/wmutils/bin/closest.sh b/wmutils/bin/closest.sh new file mode 100755 index 0000000..c49b8fb --- /dev/null +++ b/wmutils/bin/closest.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# z3bra - 2014 (c) wtfpl +# find and focus the closest window in a specific direction +# depends on: focus.sh + +# get current window id +CUR=$(pfw) + +usage() { + echo "usage: $(basename $0) <direction>" >&2 + exit 1 +} + +next_east() { + lsw | xargs wattr xi | sort -nr | sed "0,/$CUR/d" | sed "1s/^[0-9]* //p;d" +} + +next_west() { + lsw | xargs wattr xi | sort -n | sed "0,/$CUR/d" | sed "1s/^[0-9]* //p;d" +} + +next_north() { + lsw | xargs wattr yi | sort -nr | sed "0,/$CUR/d" | sed "1s/^[0-9]* //p;d" +} + +next_south() { + lsw | xargs wattr yi | sort -n | sed "0,/$CUR/d" | sed "1s/^[0-9]* //p;d" +} + +# Use the specification of your choice: WASD, HJKL, ←↑↓→, west/north/south/east +case $1 in + h|a|east|left) focus.sh $(next_east) 2>/dev/null ;; + j|s|south|down) focus.sh $(next_south) 2>/dev/null ;; + k|w|north|up) focus.sh $(next_north) 2>/dev/null ;; + l|d|west|right) focus.sh $(next_west) 2>/dev/null ;; + *) usage +esac |