Make config/uwsm something you should never need to edit

This commit is contained in:
David Heinemeier Hansson
2026-05-19 21:42:02 +02:00
parent 877c5d02f8
commit d468c392a9
4 changed files with 49 additions and 12 deletions
+11 -5
View File
@@ -1,11 +1,17 @@
#!/bin/bash #!/bin/bash
# omarchy:summary=Set the default editor for $EDITOR # omarchy:summary=Set the default editor used by omarchy-launch-editor
# omarchy:args=[code|cursor|zed|sublime_text|helix|vim|emacs|nvim] # omarchy:args=[code|cursor|zed|sublime_text|helix|vim|emacs|nvim]
# omarchy:examples=omarchy default editor | omarchy default editor code | omarchy default editor helix # omarchy:examples=omarchy default editor | omarchy default editor code | omarchy default editor helix
editor_file="$HOME/.local/state/omarchy/defaults/editor"
if (($# == 0)); then if (($# == 0)); then
sed -n 's/^export EDITOR=//p' ~/.config/uwsm/default | head -n 1 if [[ -f $editor_file ]]; then
read -r editor <"$editor_file"
fi
[[ -n $editor ]] && echo "$editor" || echo "nvim"
exit 0 exit 0
fi fi
@@ -24,7 +30,7 @@ nvim) editor="nvim"; name="Neovim"; glyph= ;;
;; ;;
esac esac
sed -i "s/^export EDITOR=.*/export EDITOR=$editor/" ~/.config/uwsm/default mkdir -p "$(dirname "$editor_file")"
printf '%s\n' "$editor" >"$editor_file"
export EDITOR="$editor" omarchy-notification-send -g $glyph "$name is now the default editor"
omarchy-notification-send -g $glyph "$name is now the default editor" "Effective after logging out"
+13 -5
View File
@@ -1,15 +1,23 @@
#!/bin/bash #!/bin/bash
# omarchy:summary=Launch the default editor as determined by $EDITOR (set via ~/.config/uwsm/default) (or nvim if missing). # omarchy:summary=Launch the default editor selected via Omarchy defaults.
# omarchy:args=<path> # omarchy:args=<path>
omarchy-cmd-present "$EDITOR" || EDITOR=nvim editor_file="$HOME/.local/state/omarchy/defaults/editor"
editor="nvim"
case "$EDITOR" in if [[ -f $editor_file ]]; then
read -r editor <"$editor_file"
fi
[[ -n $editor ]] || editor="nvim"
omarchy-cmd-present "$editor" || editor="nvim"
case "${editor##*/}" in
nvim | vim | nano | micro | hx | helix | fresh) nvim | vim | nano | micro | hx | helix | fresh)
exec omarchy-launch-tui "$EDITOR" "$@" exec omarchy-launch-tui "$editor" "$@"
;; ;;
*) *)
exec setsid uwsm-app -- "$EDITOR" "$@" exec setsid uwsm-app -- "$editor" "$@"
;; ;;
esac esac
+2 -2
View File
@@ -6,8 +6,8 @@ export TERMINAL=xdg-terminal-exec
# Used by terminal programs (like gh) to open URLs detached from the terminal process tree # Used by terminal programs (like gh) to open URLs detached from the terminal process tree
export BROWSER=omarchy-launch-browser export BROWSER=omarchy-launch-browser
# Use code for VSCode # Used by terminal programs to open files with the selected Omarchy default editor
export EDITOR=nvim export EDITOR=omarchy-launch-editor
# Use a custom directory for screenshots (remember to make the directory!) # Use a custom directory for screenshots (remember to make the directory!)
# export OMARCHY_SCREENSHOT_DIR="$HOME/Pictures/Screenshots" # export OMARCHY_SCREENSHOT_DIR="$HOME/Pictures/Screenshots"
+23
View File
@@ -0,0 +1,23 @@
echo "Move default editor selection to ~/.local/state/omarchy/defaults/editor"
editor=$(sed -n 's/^export EDITOR=//p' ~/.config/uwsm/default 2>/dev/null | head -n 1)
if [[ -z $editor || $editor == "omarchy-launch-editor" ]]; then
editor="nvim"
fi
mkdir -p "$HOME/.local/state/omarchy/defaults"
if [[ ! -f $HOME/.local/state/omarchy/defaults/editor ]]; then
printf '%s\n' "$editor" >"$HOME/.local/state/omarchy/defaults/editor"
fi
if [[ -f ~/.config/uwsm/default ]]; then
if grep -q '^export EDITOR=' ~/.config/uwsm/default; then
sed -i 's|^export EDITOR=.*|export EDITOR=omarchy-launch-editor|' ~/.config/uwsm/default
else
printf '\n# Used by terminal programs to open files with the selected Omarchy default editor\nexport EDITOR=omarchy-launch-editor\n' >>~/.config/uwsm/default
fi
else
omarchy-refresh-config uwsm/default
fi