Skip to content

Instantly share code, notes, and snippets.

@emanuele6
Last active April 2, 2023 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emanuele6/9eab3f7867ea446f5e9bc6ce5561ebdb to your computer and use it in GitHub Desktop.
Save emanuele6/9eab3f7867ea446f5e9bc6ce5561ebdb to your computer and use it in GitHub Desktop.
#!/bin/bash --
case $# in
1) dir=$1 ;;
0) printf >&2 'No arguments given.\n'; exit 2 ;;
*) printf >&2 'Too many arguments.\n'; exit 2 ;;
esac
case $dir in
west|east|south|north) ;;
*) printf >&2 'Invalid argument: %s.\n' "${dir@Q}"; exit 2 ;;
esac
ensure_tiled ()
{
bspc query -N focused.window > /dev/null \
|| return
bspc node 'focused.!tiled.!pseudo_tiled.window' -t '~' \
&& bspc node 'focused.!tiled.!pseudo_tiled.window' -t tiled
}
bspc query -N -d focused.tiled > /dev/null \
|| exit
if bspc query -N '@/.focused' > /dev/null; then
ensure_tiled
exit
fi
case $dir in
west|north)
bspc node '@/1.!focused' -s '@/2.focused' || {
bspc node '@/1.!focused#focused' -n '@/' \
&& bspc node '@/1.!focused' -s '@/2.focused'
}
;;
east|south)
bspc node '@/2.!focused' -s '@/1.focused' \
|| bspc node '@/2.!focused#focused' -n '@/'
;;
esac
split_type=
case $dir in
west|east) split_type=vertical ;;
north|south) split_type=horizontal ;;
esac
bspc node '@/.!'"$split_type" -y "$split_type"
ensure_tiled
# Move the focused node to the given side of the tiled area.
super + {Left,Up,Right,Down}
bspside {west,north,east,south}
@emanuele6
Copy link
Author

emanuele6 commented Sep 1, 2021

The current version uses new bspwm features not released in 0.9.10 to simplify the code; if you want an equivalent version that is release compatible, see this revision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment