Skip to content

Add folder color command and Nautilus menu - #14408

Open
Christopher-Moreira wants to merge 1 commit into
omacom:quattrofrom
Christopher-Moreira:folder-color
Open

Christopher-Moreira wants to merge 1 commit into
omacom:quattrofrom
Christopher-Moreira:folder-color

Conversation

@Christopher-Moreira

@Christopher-Moreira Christopher-Moreira commented Oct 7, 2026 •

Copy link
Copy Markdown

What

Adds a way to give individual folders their own icon color from the CLI or a Nautilus right-click menu.

  • omarchy folder color set <folder> <color> plus clear, list, reapply, and colors
  • A Nautilus Folder color submenu on selected folders and the window background, with a Remove color entry

How it works

Colors reuse the Yaru accent variants Omarchy already ships through yaru-icon-theme, so there is no new dependency and folder shapes remain consistent with the active theme. The command points metadata::custom-icon at the matching icon from the selected Yaru-<color> variant.

  • Special folders keep their glyph — Downloads, Music, Pictures, and other XDG folders resolve to their matching colored icon instead of becoming plain folders.
  • Live refresh without changing dates or permissions — after changing metadata, the command briefly adds and removes a unique user xattr. This changes only ctime and emits ATTRIBUTE_CHANGED, so concurrent downloads, builds, file copies, and permission restrictions keep their real directory state.
  • Exact path handling — canonical paths are read as NUL-terminated data, preserving folder names that end in newlines instead of accidentally targeting a newline-less sibling.
  • Consistent under concurrency — icon and registry changes share one flock, so overlapping set, clear, and reapply operations cannot independently win the visible and saved state.
  • Failure-safe registry updates and restores — metadata, registry, and restore-read failures are returned to the caller; temporary files are removed; and success is printed only after the complete operation finishes.
  • Persistent — choices are recorded in ~/.local/state/omarchy/folder-colors.json. GIO normally persists the icon metadata itself; reapply is an explicitly manual recovery command for restoring all saved choices if that metadata is lost.

Files

  • bin/omarchy-folder-color — the omarchy folder color ... command
  • default/nautilus-python/extensions/omarchy_folder_color.py — the right-click menu, following the existing extension pattern
  • bin/omarchy — the new folder command group description
  • migrations/1791380131.sh — installs the extension for existing users
  • test/shell.d/folder-color-test.sh — regressions for exact paths, metadata and registry failures, restore failures, temporary-file cleanup, saved-state consistency, and safe refresh behavior

Scope / caveat

The color appears in Nautilus and on the desktop. It does not appear in the GTK Open/Save portal file chooser, which ignores per-folder custom-icon metadata.

Verification

  • ./test/cli
  • bash test/shell.d/folder-color-test.sh
  • Real GIO set/clear and concurrent set/clear checks
  • Real trailing-newline sibling targeting check
  • Real ATTRIBUTE_CHANGED check with atime/mtime preserved
  • Real concurrent permission restriction check (755 to 700 remains 700 across refresh)
  • Real jq failure/empty-input and failed-restore cleanup checks
  • Symlink substitution check

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Adds folder icon coloring feature with file manager integration.

The PR appears safe to merge based on the accepted findings and numbered previous thread.

What we checked:

  • Refresh leaves permissions alone: refresh_icon writes only a temporary extended attribute. It does not restore an earlier permission value.
  • Color changes share one lock: set, clear, and reapply hold the same lock while changing icon metadata and saved colors.

Summary

Adds folder colors through the CLI and a Nautilus right-click menu.

  • Saves choices for manual restoration.
  • Locks icon and saved-state changes together.
  • Replaces permission-based refresh with temporary extended attributes, addressing the numbered previous finding.
  • No new actionable findings were accepted.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[CLI or Nautilus menu] --> B[Acquire shared lock]
  B --> C[Set or clear icon metadata]
  C --> D[Refresh with temporary extended attribute]
  D --> E[Update saved colors]
  E --> F[Release lock]
Loading

Reviews (7) · Last reviewed commit: "Add folder color command and Nautilus me..." · Reviewed by Greptile

Comment thread bin/omarchy-folder-color Resolved
Comment thread bin/omarchy-folder-color Resolved
Comment thread bin/omarchy-folder-color Resolved
@Christopher-Moreira

Copy link
Copy Markdown
Author

Thanks for the review — all three findings are addressed in the latest push.

P1 (security) — chmod following a substituted symlink: the icon refresh no longer touches permissions. refresh_icon now uses touch -c -h, which never dereferences, so a symlink swapped in for a saved path can't redirect it onto another file; reapply also skips entries that are symlinks. Verified: a saved path replaced by a symlink to a 700 directory stays 700 after reapply (the old chmod made it 777).

P1 (race) — concurrent registry writes: registry_set / registry_remove now wrap the whole read-modify-write in flock, and the temp file shares the registry directory so the final mv is an atomic rename. Verified: 6 concurrent set calls all land, no lost writes.

P2 (tabs/newlines in paths): reapply now streams base64-encoded fields (@base64 in jq, base64 -d on read), so folder names containing spaces, tabs, or newlines round-trip intact. Verified with tab- and space-containing folder names.

./test/cli and omarchy commands --check pass.

Comment thread bin/omarchy-folder-color Resolved
Comment thread bin/omarchy-folder-color Resolved
@Christopher-Moreira
Christopher-Moreira force-pushed the folder-color branch 2 times, most recently from b38fc9f to ccb47fc Compare October 7, 2026 04:11
@Christopher-Moreira

Copy link
Copy Markdown
Author

The latest push (ccb47fcb) includes one additional failure-handling fix and focused regression coverage.

  • clear no longer suppresses failures from either metadata unset. The saved registry entry is now removed only after both metadata operations succeed, so a GIO/GVfs failure cannot leave a stale visible icon while reporting success and forgetting the saved color.
  • Added test/shell.d/folder-color-test.sh, covering failure of each metadata attribute independently, preservation of saved state on failure, successful cleanup, and full-precision timestamp preservation.

I also revalidated the earlier follow-ups: icon and registry updates remain serialized under the same lock, concurrent set/clear operations finish consistently, atime/mtime are preserved, and replacing a saved folder with a symlink does not alter the target's permissions.

./test/cli, omarchy commands --check, the focused shell test, and real GIO set/clear checks pass.

Comment thread bin/omarchy-folder-color Resolved
@jandrusk

jandrusk commented Oct 7, 2026

Copy link
Copy Markdown

Nice feature, and good use of the Yaru variants already installed.

BLOCKING: migration filename collision. migrations/1791210803.sh is also added by #14401 and #14410. Please regenerate it with a fresh date +%s right before merge so the three don't clash.

Smaller things:

  • Nothing calls omarchy folder color reapply (no autostart, hook, or menu entry), so as written it's manual-only. Is that intended? If so, maybe say that in the help text.
  • In registry_put/registry_del, if jq fails, the && means set -e doesn't fire. The temp file is left next to the registry and set still prints "Colored …". Something like jq … >"$tmp" || { rm -f "$tmp"; return 1; }; mv "$tmp" "$REGISTRY" would surface it.

@Christopher-Moreira

Copy link
Copy Markdown
Author

@jandrusk Addressed all three points in ca400761:

  • Regenerated the migration as migrations/1791380131.sh, removing the colliding 1791210803.sh filename.
  • reapply is intentionally manual recovery: GIO normally persists metadata::custom-icon, so there is no need to rewrite every saved folder at login. The command summary, examples, and direct usage output now say that it manually restores saved colors if icon metadata is lost.
  • registry_put and registry_del now use jq -e, remove their temporary file and return non-zero on either jq or mv failure. The outer command therefore does not print Colored ... / Cleared ... on failure. -e also catches an empty registry, where plain jq exits successfully without producing output.

Added focused regressions for set and clear registry failures, temporary-file cleanup, false-success suppression, and empty-registry handling. The focused test, ./test/cli, omarchy commands --check, the migration idempotence check, and real GIO/jq failure checks pass.

Comment thread bin/omarchy-folder-color Resolved
Comment thread bin/omarchy-folder-color Resolved
Comment thread test/shell.d/folder-color-test.sh Resolved
@Christopher-Moreira

Copy link
Copy Markdown
Author

@greptile-apps Addressed all four current findings in c2bc7909:

  • P1 trailing-newline paths: set and clear now read realpath -z with a NUL-delimited read, so command substitution cannot strip trailing newlines. Added a regression with both Projects and Projects\n, verifying that only the selected key is changed, plus a real GIO check against both sibling directories.
  • P2 failed restores: reapply now validates that the registry is a JSON object, materializes the encoded entries through a checked jq command, and cleans the temporary entries file through an EXIT trap. A failed registry read returns non-zero.
  • P2 tests reaching writes: tests now provide their own Yaru-red icon tree through a test-only icon-base override and make the failing jq stub log each invocation. Assertions verify that both set and clear reached the intended registry operation before failing.
  • P2 real dates overwritten: removed the timestamp snapshot/touch/restore sequence entirely. Refresh now reads and reapplies the current unix::mode with gio --nofollow-symlinks, which emits ATTRIBUTE_CHANGED by changing ctime without writing atime/mtime. Verified with real GIO that the event fires and that a directory mtime produced by creating a file remains byte-for-byte unchanged after refresh.

./test/cli, omarchy commands --check, nine focused shell regressions, the migration check, and the real GIO scenarios pass.

Comment thread bin/omarchy-folder-color Resolved
Color individual folders with the installed Yaru color variants via
`omarchy folder color` or a Nautilus "Folder color" right-click submenu.
Special folders like Downloads keep their glyph, colors persist through
gio metadata, and the icon updates live without a manual refresh.

A migration installs the Nautilus extension for existing users.
@Christopher-Moreira

Copy link
Copy Markdown
Author

@greptile-apps Fixed the permission refresh race in 6f225cda.

refresh_icon no longer reads or writes unix::mode (or any other existing mutable attribute). It now adds and removes a uniquely named temporary user xattr. Those operations emit ATTRIBUTE_CHANGED and change only ctime, without copying state that can become stale between two calls. They are best-effort on filesystems without xattr support.

The focused test now fails if refresh accesses unix::mode and verifies that exactly one temporary xattr is added and removed. I also validated the real GIO behavior by changing a folder from 755 to 700 between the xattr set and unset: it remained 700, while atime and mtime stayed byte-for-byte unchanged and the attribute events were emitted.

All nine focused regressions, ./test/cli, omarchy commands --check, bash -n, and git diff --check pass.

@greptile-apps

greptile-apps Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

The new refresh implementation addresses the race: it no longer reads or writes unix::mode, so a permission change between refresh operations cannot be overwritten. Using gio set -n also avoids dereferencing a substituted symlink, and the focused regression covers both the absence of mode access and the temporary xattr lifecycle. No further change is needed for this finding.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

Thanks, re-checked at 6f225cd. The migration is now 1791380131.sh, which doesn't collide with anything on quattro. reapply is documented as manual recovery, and registry_put/registry_del clean up and fail without printing "Colored …". That covers everything I raised, so LGTM from my side. Switching the icon refresh to a temporary xattr, so it no longer rewrites unix::mode, is a nice touch too.

@Christopher-Moreira

Copy link
Copy Markdown
Author

Hey @omacom, just following up on this PR.

All review feedback has been addressed, the latest changes have been validated, and CI is passing. @jandrusk also confirmed LGTM after the final fixes.

The implementation is ready for another look whenever you have a chance.

Happy to make any additional adjustments if needed. Thanks!

@omarchybot omarchybot added the enhancement New feature or request label Oct 16, 2026
@Christopher-Moreira

Copy link
Copy Markdown
Author

Hey @omacom, checking back on this. Is folder coloring something you’d like to include in Omarchy?

All review threads are resolved and checks are passing. If there’s any remaining concern about the feature or its scope, I’d appreciate your feedback so I can address it.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants