#!/usr/bin/env cached-nix-shell
#! nix-shell -i zsh -p jshon

# Script: bspc-presel
# Author: Henrik Lissner
# Usage:
#   bspc-presel RATIO
#   bspc-presel 0.2
#
# Wrote this to invert the ratio on east/south-bound preselections. In English
# that means bspc node -p 0.2 should resize the preselection to 20%, whether or
# not it's on the west or east side of the window (or north or south side),
# which isn't the case by default.
#
# NOTE: We use zsh for this because bash chokes on float arithmetic.

shift  # nix-shell passes script path as $1
ratio="$1"
case "$(bspc query -T -n focused | jshon -e presel -e splitDir | tr -d \")" in
  west|north) bspc node -o $ratio ;;
  east|south) bspc node -o $(( 1.0 - ratio )) ;;
esac
