Created
July 23, 2014 01:42
-
-
Save windelicato/a1325397dd8303b7607c to your computer and use it in GitHub Desktop.
bspwm_resize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
POSITIVE=false | |
HORIZONTAL=false | |
SIZE='20' | |
err() { | |
echo "$1" | |
exit 1 | |
} | |
usage() { | |
echo "usage: bspwm_resize [direction]" | |
echo | |
echo "Options:" | |
echo " -p, --positive - resize in positively" | |
echo " -n, --negative - resize in negatively" | |
echo " -x, --xdir - resize in x direction" | |
echo " -y, --ydir - resize in y dir" | |
echo " -s, - number of pixels to resize or move" | |
echo " -h, --help - display this" | |
exit | |
} | |
if [[ $# -eq 0 ]] ; then | |
usage | |
exit | |
fi | |
for i in "$@"; do | |
case $i in | |
'-p'|'--positive') | |
POSITIVE=true | |
;; | |
'-n'|'--negative') | |
POSITIVE=false | |
;; | |
'-x'|'--xdir') | |
HORIZONTAL=true | |
;; | |
'-y'|'--ydir') | |
HORIZONTAL=false | |
;; | |
'-s') | |
SIZE=$(echo $@ | sed 's/.*-s \([0-9]*\).*/\1/') | |
[[ "$SIZE" == "$@" ]] && err "Must specify number of pixels" | |
;; | |
''|'-h'|'--help') | |
usage | |
exit | |
;; | |
*) | |
;; | |
esac | |
done | |
# Find current window mode | |
WINDOW_STATUS="$(bspc query -T -w | sed 's/.* \(.*\) \*.*/\1/' | tail -n1)" | |
FLAGS="$(echo $WINDOW_STATUS | sed 's/-//g')"; | |
# If the window is floating, move it | |
if [[ "$FLAGS" =~ ^.*f.*$ ]]; then | |
$HORIZONTAL && switch="-x" || switch="-y" | |
$POSITIVE && sign="+" || sign="-" | |
xdo move ${switch} ${sign}${SIZE} | |
# If the window is pseudotiled, resize it | |
elif [[ "$FLAGS" =~ ^.*d.*$ ]]; then | |
$HORIZONTAL && switch="-w" || switch="-h" | |
$POSITIVE && sign="+" || sign="-" | |
xdo resize ${switch} ${sign}${SIZE} | |
# Otherwise, window is tiled modified split ratio | |
else | |
$HORIZONTAL && switch=("left","right") || switch=("down", "up") | |
$POSITIVE && sign="+" || sign="-" | |
bspc window -e ${switch[0]} ${sign}${SIZE} || bspc window -e ${switch[1]} ${sign}${SIZE} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment