diff options
author | adam <56338480+adastx@users.noreply.github.com> | 2022-10-09 00:48:45 +0200 |
---|---|---|
committer | adam <56338480+adastx@users.noreply.github.com> | 2022-10-09 00:48:45 +0200 |
commit | c67588de6c97f2182fd87e3f7cc139e055385963 (patch) | |
tree | cc82232c20fcea0770d2296136b06f18979c05e2 | |
parent | d9579aee55d4295151b4a76d82975c7171908acc (diff) |
script: polished 'barpos'
-rwxr-xr-x | .local/bin/barpos | 63 |
1 files changed, 54 insertions, 9 deletions
diff --git a/.local/bin/barpos b/.local/bin/barpos index deb3840..840b839 100755 --- a/.local/bin/barpos +++ b/.local/bin/barpos @@ -1,14 +1,59 @@ #!/bin/bash -polybar_cfg=$XDG_CONFIG_HOME/polybar/config.ini +BAR_CFG=$XDG_CONFIG_HOME/polybar/config.ini -bottom_str="bottom = true" -top_str="bottom = false" +BOTTOM="bottom = true" +TOP="bottom = false" -if grep -q "$bottom_str" $polybar_cfg; then - sed -i "s/$bottom_str/$top_str/" $polybar_cfg -else - sed -i "s/$top_str/$bottom_str/" $polybar_cfg -fi +main () { + if [ ! -n "$1" ]; then + toggle + fi -polybar-launch + while [ -n "$1" ]; do # while loop starts + case "$1" in + -b) + bottom; break ;; + -t) + top; break ;; + -h|--help) + help ; break ;; + *) + usage; echo "error: unrecognized arguments: $1" ; exit 1 ;; + esac + shift + done +} + +usage () { + echo "usage: barpos [options]" +} + +help () { + usage + echo + echo "Toggles status bar position, or sets it as specified" + echo + echo "options:" + echo " -h, --help show this help message and exit" + echo " -b bottom" + echo " -t top" +} + +toggle () { + if grep -q "$BOTTOM" $BAR_CFG; then + sed -i "s/$BOTTOM/$TOP/" $BAR_CFG + else + sed -i "s/$TOP/$BOTTOM/" $BAR_CFG + fi +} + +bottom () { + sed -ir "s/bottom = .*$/bottom = true/" $BAR_CFG +} + +top () { + sed -ir "s/bottom = .*$/bottom = false/" $BAR_CFG +} + +main "$@" |