commit 398ac8bd8dc740e95afce6ffc4868a7c9e34946c parent 36d3fe39be7ff9eac6191cda1628f09eb0925f62 Author: Yuval Langer <yuval.langer@gmail.com> Date: Wed, 1 Nov 2023 13:13:40 +0200 Generalise boolean gsettings toggling. Diffstat:
M | bin/toggle-DND.sh | | | 19 | +++---------------- |
A | bin/toggle-gsetting.sh | | | 25 | +++++++++++++++++++++++++ |
M | bin/toggle-night-light.sh | | | 19 | +++---------------- |
3 files changed, 31 insertions(+), 32 deletions(-)
diff --git a/bin/toggle-DND.sh b/bin/toggle-DND.sh @@ -1,18 +1,5 @@ #!/bin/sh -if [ -z "$(command -v gsettings)" ]; then - echo "No gsettings."; - exit 1; -fi - -show_banners_value="$(gsettings get org.gnome.desktop.notifications show-banners)" - -if [ "$show_banners_value" = "true" ]; then - echo "DND turn on." - gsettings set org.gnome.desktop.notifications show-banners false -elif [ "$show_banners_value" = "false" ]; then - echo "DND turn off." - gsettings set org.gnome.desktop.notifications show-banners true -else - echo "Something's wrong! Not a valid show-banner value: $show_banners_value" -fi +toggle-gsetting.sh DND \ + org.gnome.desktop.notifications \ + show-banners diff --git a/bin/toggle-gsetting.sh b/bin/toggle-gsetting.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +if [ -z "$(command -v gsettings)" ]; then + printf "No \"gsettings\" command!\n"; + exit 1; +fi + +name="$1" +schema="$2" +key="$3" + +current_value="$(gsettings get $schema $key)" + +if [ "$current_value" = "true" ]; then + printf "%s set to false\n" "$name" + gsettings set "$schema" "$key" false +elif [ "$current_value" = "false" ]; then + printf "%s set to true\n" "$name" + gsettings set "$schema" "$key" true +else + printf "Something's wrong! %s not changed. Not a valid %s value: %s\n" \ + "$name" \ + "$key" \ + "$current_value" +fi diff --git a/bin/toggle-night-light.sh b/bin/toggle-night-light.sh @@ -1,18 +1,5 @@ #!/bin/sh -if [ -z "$(command -v gsettings)" ]; then - echo "No gsettings."; - exit 1; -fi - -current_value="$(gsettings get org.gnome.settings-daemon.plugins.color night-light-enabled)" - -if [ "$current_value" = "true" ]; then - echo "Night light turn off." - gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled false -elif [ "$current_value" = "false" ]; then - echo "Night light turn on." - gsettings set org.gnome.settings-daemon.plugins.color night-light-enabled true -else - echo "Something's wrong! Not a valid value: $current_value" -fi +toggle-gsetting.sh 'Night light' \ + org.gnome.settings-daemon.plugins.color \ + night-light-enabled