diff --git a/quick-switch.sh b/quick-switch.sh index a765c57..dbef1f1 100755 --- a/quick-switch.sh +++ b/quick-switch.sh @@ -1,30 +1,34 @@ -#!/usr/bin/env bash +#!/usr/bin/env bash set -euo pipefail commitchanges="false" while getopts 'c' OPTION; do case "$OPTION" in - c) commitchanges="true" ;; + c) commitchanges="true" ;; + *) exit 1 ;; esac done -# Stolen from https://stackoverflow.com/a/29436423 +# Stolen from https://stackoverflow.com/a/29436423 function yes_or_no { - while true; do - read -p "$* [y/n]: " yn - case $yn in - [Yy]*) return 0 ;; - [Nn]*) echo "Aborted" ; return 1 ;; - esac - done + while true; do + read -r -p "$* [y/n]: " yn + case $yn in + [Yy]*) return 0 ;; + [Nn]*) + echo "Aborted" + return 1 + ;; + esac + done } function reset_bspwm() { pkill -USR1 -x sxhkd pkill -x picom pkill polybar - + sxhkd & bspc wm -r } @@ -38,25 +42,23 @@ function apply() { } function commit_and_apply() { - read -p "Git working directory is unclean. Commit message: " msg + read -r -p "Git working directory is unclean. Commit message: " msg git add . git commit -m "$(hostname): $msg" apply } -if [ -z "$(git status --porcelain)" ] -then +if [ -z "$(git status --porcelain)" ]; then apply else - if [ "$commitchanges" == "false" ] - then - echo "Using local flake..." - sudo nixos-rebuild switch --show-trace --flake . - reset_bspwm - else - echo "Committing flake and pushing..." - commit_and_apply + if [ "$commitchanges" == "false" ]; then + echo "Using local flake..." + sudo nixos-rebuild switch --show-trace --flake . + reset_bspwm + else + echo "Committing flake and pushing..." + commit_and_apply fi + # shellcheck disable=SC2028 echo "\nOperation completed." fi -