From 1d6467c91cdab70ff71cc30b04579c50c4e404a8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 4 Jun 2026 11:14:04 +0200 Subject: [PATCH] Add explicit toggle states --- bin/omarchy-toggle | 35 ++++++++++++++++++++----- bin/omarchy-toggle-bar | 47 +++------------------------------- test/shell.d/toggle-test.sh | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 50 deletions(-) create mode 100644 test/shell.d/toggle-test.sh diff --git a/bin/omarchy-toggle b/bin/omarchy-toggle index 61370e1d..a36f0e63 100755 --- a/bin/omarchy-toggle +++ b/bin/omarchy-toggle @@ -1,19 +1,42 @@ #!/bin/bash # omarchy:summary=Toggle Omarchy features between enabled and disabled -# omarchy:args= +# omarchy:args= [toggle|on|off] if (($# < 1)); then - echo "Usage: omarchy-toggle " >&2 + echo "Usage: omarchy-toggle [toggle|on|off]" >&2 exit 1 fi FLAG_NAME="$1" +ACTION="${2:-toggle}" FLAG="$HOME/.local/state/omarchy/toggles/$FLAG_NAME" -if [[ -f $FLAG ]]; then - rm -f "$FLAG" -else +enable() { mkdir -p "$(dirname "$FLAG")" touch "$FLAG" -fi +} + +disable() { + rm -f "$FLAG" +} + +case "$ACTION" in + toggle|"") + if [[ -f $FLAG ]]; then + disable + else + enable + fi + ;; + on) + enable + ;; + off) + disable + ;; + *) + echo "Usage: omarchy-toggle [toggle|on|off]" >&2 + exit 1 + ;; +esac diff --git a/bin/omarchy-toggle-bar b/bin/omarchy-toggle-bar index 68a1eca4..f76fe049 100755 --- a/bin/omarchy-toggle-bar +++ b/bin/omarchy-toggle-bar @@ -1,48 +1,7 @@ #!/bin/bash # omarchy:summary=Toggle bar visibility without killing the Omarchy shell -# omarchy:args=[toggle|show|hide] -# omarchy:examples=omarchy toggle bar | omarchy toggle bar hide | omarchy toggle bar show +# omarchy:args=[toggle|on|off] +# omarchy:examples=omarchy toggle bar | omarchy toggle bar off | omarchy toggle bar on -FLAG="$HOME/.local/state/omarchy/toggles/bar-off" - -apply_state() { - case "$1" in - hidden) - mkdir -p "$(dirname "$FLAG")" - touch "$FLAG" - ;; - visible) - rm -f "$FLAG" - ;; - esac -} - -case "${1:-toggle}" in - hide|off) - apply_state hidden - state=hidden - ;; - show|on) - apply_state visible - state=visible - ;; - toggle|"") - if [[ -f $FLAG ]]; then - apply_state visible - state=visible - else - apply_state hidden - state=hidden - fi - ;; - *) - echo "Usage: omarchy-toggle-bar [toggle|show|hide]" >&2 - exit 1 - ;; -esac - -case "$state" in - visible) omarchy-notification-send "Bar shown" -g 󰍜 ;; - hidden) omarchy-notification-send "Bar hidden" -g 󰍜 ;; -esac +omarchy-toggle bar-off "${1:-toggle}" diff --git a/test/shell.d/toggle-test.sh b/test/shell.d/toggle-test.sh new file mode 100644 index 00000000..945dc8af --- /dev/null +++ b/test/shell.d/toggle-test.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +TMPDIR="" + +export PATH="$ROOT/bin:$PATH" + +cleanup() { + [[ -n $TMPDIR && -d $TMPDIR ]] && rm -rf "$TMPDIR" +} +trap cleanup EXIT + +TMPDIR=$(mktemp -d) +test_home="$TMPDIR/home" +flag="$test_home/.local/state/omarchy/toggles/example" +bar_flag="$test_home/.local/state/omarchy/toggles/bar-off" + +HOME="$test_home" omarchy-toggle example on +[[ -f $flag ]] || fail "generic toggle enables explicit on state" +pass "generic toggle enables explicit on state" + +HOME="$test_home" omarchy-toggle example on +[[ -f $flag ]] || fail "generic toggle on is idempotent" +pass "generic toggle on is idempotent" + +HOME="$test_home" omarchy-toggle example off +[[ ! -f $flag ]] || fail "generic toggle disables explicit off state" +pass "generic toggle disables explicit off state" + +HOME="$test_home" omarchy-toggle example +[[ -f $flag ]] || fail "generic toggle flips disabled state on" +pass "generic toggle flips disabled state on" + +HOME="$test_home" omarchy-toggle example toggle +[[ ! -f $flag ]] || fail "generic toggle flips enabled state off" +pass "generic toggle flips enabled state off" + +HOME="$test_home" omarchy-toggle-bar on +[[ -f $bar_flag ]] || fail "bar on enables bar-off toggle" +pass "bar on enables bar-off toggle" + +HOME="$test_home" omarchy-toggle-bar on +[[ -f $bar_flag ]] || fail "bar on is idempotent" +pass "bar on is idempotent" + +HOME="$test_home" omarchy-toggle-bar off +[[ ! -f $bar_flag ]] || fail "bar off disables bar-off toggle" +pass "bar off disables bar-off toggle"