Skip to content

Instantly share code, notes, and snippets.

@windelicato
Created July 23, 2014 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windelicato/a1325397dd8303b7607c to your computer and use it in GitHub Desktop.
Save windelicato/a1325397dd8303b7607c to your computer and use it in GitHub Desktop.
bspwm_resize
#!/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