Skip to content

fix(theme): establish OMARCHY_PATH in entry points for non-interactive shells - #9103

Open
harshithnadig wants to merge 1 commit into
omacom:quattrofrom
harshithnadig:fix/theme-non-interactive-omarchy-path
Open

harshithnadig wants to merge 1 commit into
omacom:quattrofrom
harshithnadig:fix/theme-non-interactive-omarchy-path

Conversation

@harshithnadig

Copy link
Copy Markdown

Problem

In #9065, omarchy theme list and omarchy theme set fail in non-interactive environments (scripts, cron, SSH, CI, AI agents) because $OMARCHY_PATH is only exported by ~/.bashrc in interactive login sessions.

When $OMARCHY_PATH is unset:

  • omarchy theme list queries /themes/, outputs a find error to stderr, and silently exits 0 with an empty list.
  • omarchy theme set <name> queries /themes/<name> and falsely reports that the theme does not exist.

Solution

  1. In bin/omarchy (the root entry dispatcher), establish OMARCHY_PATH if unset before executing sub-commands.
  2. In bin/omarchy-theme-list and bin/omarchy-theme-set, check and fallback OMARCHY_PATH from /etc/omarchy.conf or /usr/share/omarchy.
  3. In bin/omarchy-theme-list, exit with code 1 if neither system nor user theme directories exist.

Fixes #9065

…e shells

'omarchy theme list' and 'omarchy theme set' depended on OMARCHY_PATH being
exported in the caller's environment. Because OMARCHY_PATH was only exported
in '~/.bashrc' via 'env-bootstrap', non-interactive shells (cron, SSH, scripts,
CI, systemd) evaluated OMARCHY_PATH as empty, causing 'theme list' to query
'/themes/' (failing silently with exit 0) and 'theme set' to report that
existing themes do not exist.

Establish OMARCHY_PATH in 'bin/omarchy', 'bin/omarchy-theme-list', and
'bin/omarchy-theme-set' if unset, falling back to '/etc/omarchy.conf' and
'/usr/share/omarchy'. Also exit non-zero if the themes directory cannot be found.

Fixes omacom#9065
@omarchybot omarchybot added bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review labels Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 4206914 and tested on a disposable Omarchy VM. The bug in #9065 is real and this fixes it, but the approach goes against a rule in this repository's AGENTS.md, so it is waiting on the maintainer.

What ran. In bash --noprofile --norc with OMARCHY_PATH unset, on the base commit omarchy theme list printed find: '/themes/': No such file or directory and exited 0, and omarchy theme set Everforest said Theme 'everforest' does not exist and exited 1. On this branch both work: the list is complete, and the theme is applied. With neither themes directory present, omarchy-theme-list now exits 1 with an error where it used to exit 0. ./test/cli and test/shell.d/theme-staging-test.sh pass on the branch.

The concern. The Runtime Environment section of AGENTS.md on quattro says commands in bin/ should rely on $OMARCHY_PATH and not "re-export/default OMARCHY_PATH manually". This PR adds that default three times: in the bin/omarchy router and in each of the two theme commands. The router change alone already fixes omarchy theme …, because the router exports the variable before it runs the subcommand. The two per-command copies only matter when omarchy-theme-* is called directly, and a fix that covers that case would mean the same block in every command that reads OMARCHY_PATH. Whether to default the variable in the router, to make it reach cron, sudo and systemd environments some other way, or to leave it as the rule says is a design decision for the maintainer, so nothing has been pushed here. The exit-status change in omarchy-theme-list stands on its own whichever way that goes.

Related. #12860 and #12796 handle the same unset variable in the update commands, one command at a time. #8769 is still open for omarchy-update-available.

Second opinion. Only Claude Opus 5.5 reviewed this. The configured second reviewer, Codex Medium, did not review it because omabot's daily review budget was used up, so this is one model's reading.

@SafiullahRattar

Copy link
Copy Markdown

There's still an exit-status gap in 4206914: both theme directories exist, but one can't be read. find prints Permission denied, yet the script exits 0 because sort | sed masks the failed scan.

Here's a patch and regression test you can fold into this PR. It tracks failures from both scans and enables pipefail, without changing the existing OMARCHY_PATH fallback.

The regression fails on this PR head and passes with the patch.

Patch against 4206914
--- a/bin/omarchy-theme-list
+++ b/bin/omarchy-theme-list
@@ -2,6 +2,8 @@
 
 # omarchy:summary=List available themes
 # omarchy:examples=omarchy theme list | omarchy theme set "Tokyo Night"
+
+set -o pipefail
 
 if [[ -z ${OMARCHY_PATH:-} ]]; then
   if [[ -f /etc/omarchy.conf ]]; then
@@ -16,7 +18,13 @@
   exit 1
 fi
 
+scan_failed=0
 {
-  [[ -d "$HOME/.config/omarchy/themes" ]] && find ~/.config/omarchy/themes/ -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -printf '%f\n'
-  [[ -d "$OMARCHY_PATH/themes" ]] && find "$OMARCHY_PATH/themes/" -mindepth 1 -maxdepth 1 -type d -printf '%f\n'
+  if [[ -d $HOME/.config/omarchy/themes ]]; then
+    find ~/.config/omarchy/themes/ -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -printf '%f\n' || scan_failed=1
+  fi
+  if [[ -d $OMARCHY_PATH/themes ]]; then
+    find "$OMARCHY_PATH/themes/" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' || scan_failed=1
+  fi
+  (( scan_failed == 0 ))
 } | sort -u | sed -E 's/(^|-)([a-z])/\1\u\2/g; s/-/ /g'
Runnable regression test

Save this as regression-test.py, then run:

python3 regression-test.py ./bin/omarchy-theme-list

Run unprivileged. It checks real permission-denied failures using temporary theme directories and a temporary HOME, without changing your actual themes. If privileges bypass the fixture permissions, it reports that instead of claiming a pass.

"""Run: python3 regression-test.py path/to/bin/omarchy-theme-list (unprivileged)."""
import subprocess
import sys
import tempfile
from pathlib import Path

script = Path(sys.argv[1]).resolve()
failed = 0
for unreadable in ("packaged", "user"):
  with tempfile.TemporaryDirectory() as temporary:
    root = Path(temporary)
    home = root / "home"
    package = root / "package"
    user_themes = home / ".config/omarchy/themes"
    packaged_themes = package / "themes"
    (user_themes / "custom-theme").mkdir(parents=True)
    (packaged_themes / "packaged-theme").mkdir(parents=True)
    denied = packaged_themes if unreadable == "packaged" else user_themes
    denied.chmod(0)
    try:
      result = subprocess.run(["/bin/bash", "--noprofile", "--norc", str(script)],
        env={"HOME": str(home), "OMARCHY_PATH": str(package), "PATH": "/usr/bin:/bin", "LC_ALL": "C.UTF-8"},
        capture_output=True, text=True, timeout=5)
    finally:
      denied.chmod(0o700)
    if "Permission denied" not in result.stderr:
      raise RuntimeError("Fixture wasn't unreadable. Run without root/DAC-override privileges.")
    ok = result.returncode != 0
    print(f"{'ok' if ok else 'not ok'} - {unreadable} scan failure exits {result.returncode}")
    failed += not ok
sys.exit(1 if failed else 0)

AI-assisted; tested offline.

@omarchybot

Copy link
Copy Markdown
Collaborator

The second opinion that was missing from the review on October 1 has now run. Codex Medium read this branch at 4206914 against current quattro. It found no defects in the diff, and it agrees with the earlier reading, which it could see, so its agreement is not guaranteed to be independent. The bin/omarchy router execs the subcommand after exporting OMARCHY_PATH, so the router change alone fixes omarchy theme list and omarchy theme set. The two per-command copies only matter when omarchy-theme-* is called directly. All three conflict with the Runtime Environment rule in AGENTS.md on quattro, which still says not to default OMARCHY_PATH in bin/. The branch still merges cleanly, and bin/omarchy-theme-list has not changed on quattro since it was tested on a worker.

On @SafiullahRattar's suggested patch: it's true that an unreadable theme directory makes find fail while the script still exits 0, because sed at the end of the pipeline sets the exit status. Codex confirmed this, but quattro behaves the same way today, so this PR didn't introduce it. It is a separate error-handling change, and it's not being added here while the approach in this PR is still undecided. If it's wanted, it would make a small pull request of its own.

Nothing has been pushed. This is waiting on the maintainer to decide whether OMARCHY_PATH should be defaulted in the router, reach non-interactive shells some other way, or be left as the rule says.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy theme list fails silently (exit 0) in non-interactive shells; theme set reports a wrong reason — OMARCHY_PATH is only exported by ~/.bashrc

3 participants