nixos/dotfiles/sway/scripts/scale.sh

33 lines
821 B
Bash
Executable File

#!/bin/bash
SCALE_FILE="scale.txt"
DIRNAME="/tmp/$(ls /tmp | grep scale.sh | head -n 1)"
CUR_SCALE=$(swaymsg -t get_outputs | grep -oP "scale\": \K\d.\d+")
NEW_SCALE=""
if [[ $DIRNAME == "/tmp/" ]]; then
DIRNAME=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXXXX")
echo $CUR_SCALE > $DIRNAME/$SCALE_FILE
else
CUR_SCALE=$(cat $DIRNAME/$SCALE_FILE)
fi
if [[ $1 == "inc" ]]; then
NEW_SCALE=$(echo $CUR_SCALE + 0.25 | bc)
elif [[ $1 == "dec" ]]; then
NEW_SCALE=$(echo $CUR_SCALE - 0.25 | bc)
else
echo "No op provided, pass in 'inc' or 'dec' to change scale"
fi
if [[ $NEW_SCALE < 0.50 ]]; then
NEW_SCALE=0.50
elif [[ $NEW_SCALE > 2 ]]; then
NEW_SCALE=2.00
fi
echo $NEW_SCALE > $DIRNAME/$SCALE_FILE
notify-send -t 1000 "Scale set to $NEW_SCALE"
swaymsg "output * scale $NEW_SCALE"