Repository navigation
Harden tui launcher install and removal #9150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: quattro
Are you sure you want to change the base?
Changes from 4 commits
62b1ca3
3332efa
d110144
d0bcaf3
5cbd41d
3b7b242
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,39 @@ ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps" | |
| OLD_ICON_DIR="$HOME/.local/share/applications/icons" | ||
| DESKTOP_DIR="$HOME/.local/share/applications/" | ||
|
|
||
| if (( $# == 0 )); then | ||
| # Find all TUIs | ||
| while IFS= read -r -d '' file; do | ||
| if grep -qE '^Exec=.*(\$TERMINAL|xdg-terminal-exec).*-e' "$file"; then | ||
| TUIS+=("$(basename "${file%.desktop}")") | ||
| # Always index the launchers, so removal deletes the file that was found rather | ||
| # than a path rebuilt from the displayed name. Installs predating the name | ||
| # validation could nest the launcher inside directories, and those are exactly | ||
| # the ones a reconstructed path cannot reach. | ||
| TUI_PATHS=() | ||
| while IFS= read -r -d '' file; do | ||
| if grep -qE '^Exec=.*(\$TERMINAL|xdg-terminal-exec).*-e' "$file"; then | ||
| TUIS+=("$(basename "${file%.desktop}")") | ||
| TUI_PATHS+=("$file") | ||
| fi | ||
| done < <(find "$DESKTOP_DIR" -name '*.desktop' -print0 2>/dev/null) | ||
|
|
||
| # The launcher matching a chosen name, or empty when nothing was indexed under | ||
| # it (a TUI removed between the scan and the pick, say). A top-level launcher | ||
| # wins over a nested legacy one of the same name, whatever order find walks in. | ||
| path_for_tui() { | ||
| local wanted="$1" found="" i | ||
| for i in "${!TUIS[@]}"; do | ||
| if [[ ${TUIS[$i]} == "$wanted" ]]; then | ||
| if [[ ${TUI_PATHS[$i]} == "$DESKTOP_DIR$wanted.desktop" ]]; then | ||
| printf '%s\n' "${TUI_PATHS[$i]}" | ||
| return 0 | ||
| fi | ||
| found=${found:-${TUI_PATHS[$i]}} | ||
| fi | ||
| done < <(find "$DESKTOP_DIR" -name '*.desktop' -print0) | ||
| done | ||
|
|
||
| if [[ -n $found ]]; then | ||
| printf '%s\n' "$found" | ||
| fi | ||
| } | ||
|
|
||
| if (( $# == 0 )); then | ||
| if ((${#TUIS[@]})); then | ||
| mapfile -t SORTED_TUIS < <(printf '%s\n' "${TUIS[@]}" | sort) | ||
| APP_NAME=$(omarchy-menu-select "Select TUI to remove" "${SORTED_TUIS[@]}" -- --width 520 --maxheight 520) | ||
|
|
@@ -34,7 +59,8 @@ if [[ -z $APP_NAME ]]; then | |
| fi | ||
|
|
||
| icon_name=$(printf '%s\n' "$APP_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^[:alnum:]]\+/-/g; s/^-//; s/-$//') | ||
| rm -f "$DESKTOP_DIR/$APP_NAME.desktop" | ||
| desktop_file=$(path_for_tui "$APP_NAME") | ||
| rm -f "${desktop_file:-$DESKTOP_DIR/$APP_NAME.desktop}" | ||
| rm -f "$ICON_DIR/$icon_name.png" "$ICON_DIR/$APP_NAME.png" "$OLD_ICON_DIR/$APP_NAME.png" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this lookup removes a legacy launcher such as
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At 3b7b242, the nested-entry lookup and icon cleanup come from Checked by Codex High, Opus 5.5 High and muse-wonder via pi (thinking high); the reviewers agreed, and independence is not guaranteed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. The icon-name mismatch is inherited behavior, not introduced by this PR; the diff’s production change only makes an indexed top-level launcher take precedence over a nested namesake. I’ll withdraw this finding as out of scope for the change. |
||
| if [[ ${OMARCHY_REMOVE_NOTIFY:-true} != "false" ]]; then | ||
| omarchy-notification-send -g "TUI removed" "$APP_NAME" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| tmp_dir=$(mktemp -d) | ||
| trap 'rm -rf "$tmp_dir"' EXIT | ||
| mkdir -p "$tmp_dir/bin" "$tmp_dir/home" | ||
|
|
||
| for stub in gtk-update-icon-cache update-desktop-database omarchy-notification-send; do | ||
| printf '#!/bin/bash\n:\n' >"$tmp_dir/bin/$stub" | ||
| chmod +x "$tmp_dir/bin/$stub" | ||
| done | ||
|
|
||
| run_install() { | ||
| HOME="$tmp_dir/home" PATH="$tmp_dir/bin:$PATH" \ | ||
| "$ROOT/bin/omarchy-tui-install" "$@" | ||
| } | ||
|
|
||
| run_remove() { | ||
| HOME="$tmp_dir/home" PATH="$tmp_dir/bin:$PATH" OMARCHY_REMOVE_NOTIFY=false \ | ||
| "$ROOT/bin/omarchy-tui-remove" "$@" | ||
| } | ||
|
|
||
| apps_dir="$tmp_dir/home/.local/share/applications" | ||
|
|
||
| # A URL typed into the name field is the reported way in. Every slash used to | ||
| # become a directory level, leaving a launcher nothing could address. Assert on | ||
| # the message: creating the launcher directly in the applications directory | ||
| # already makes the path failure indistinguishable from no validation at all. | ||
| output=$(run_install "http://example.test/oops" "lazydocker" tile hey 2>&1) && | ||
| fail "tui install rejects a name containing a slash" | ||
| [[ $output == *"App name cannot contain '/'"* ]] || | ||
| fail "tui install says why it refused a slashed name" "$output" | ||
| [[ -e "$apps_dir/http:" ]] && | ||
| fail "tui install does not create a directory from a slashed name" | ||
| pass "tui install rejects a name that would nest the launcher" | ||
|
|
||
| # The name was a path fragment until something said otherwise, so ../ climbed | ||
| # out of the applications directory entirely and wrote wherever it landed. | ||
| if run_install "../../../../escaped" "lazydocker" tile hey >/dev/null 2>&1; then | ||
| fail "tui install rejects a name that climbs out of the applications directory" | ||
| fi | ||
| [[ -e "$tmp_dir/escaped.desktop" ]] && | ||
| fail "tui install writes no launcher outside the applications directory" | ||
| pass "tui install refuses a name that would escape the applications directory" | ||
|
|
||
| # The interactive prompt reads the name first, so refusal has to happen right | ||
| # then rather than after the window-style pick and icon questions. | ||
| mkdir -p "$tmp_dir/ibin" | ||
| cp "$tmp_dir/bin"/* "$tmp_dir/ibin/" | ||
| cat >"$tmp_dir/ibin/gum" <<'STUB' | ||
| #!/bin/bash | ||
| count=$(cat "$GUM_STUB_COUNT" 2>/dev/null || echo 0) | ||
| count=$((count + 1)) | ||
| echo "$count" >"$GUM_STUB_COUNT" | ||
| sed -n "${count}p" "$GUM_ANSWERS" | ||
| STUB | ||
| chmod +x "$tmp_dir/ibin/gum" | ||
|
|
||
| printf 'http://example.test/oops\n' >"$tmp_dir/answers" | ||
| : >"$tmp_dir/gum-count" | ||
| if HOME="$tmp_dir/home" PATH="$tmp_dir/ibin:$PATH" GUM_STUB_COUNT="$tmp_dir/gum-count" \ | ||
| GUM_ANSWERS="$tmp_dir/answers" "$ROOT/bin/omarchy-tui-install" >/dev/null 2>&1; then | ||
| fail "interactive tui install rejects a name containing a slash" | ||
| fi | ||
| [[ $(cat "$tmp_dir/gum-count") == 1 ]] || | ||
| fail "interactive tui install refuses the name before asking the next question" | ||
| pass "interactive tui install refuses a slashed name before any launcher work" | ||
|
|
||
| # The property the escaping exists for: a newline in a value must not be able to | ||
| # start a second key line, in the Name field or anywhere else -- the Exec line | ||
| # included. | ||
| inject_name=$(printf 'Inject\nExec=evil') | ||
| run_install "$inject_name" "lazydocker" tile hey >/dev/null | ||
| inject_file="$apps_dir/$inject_name.desktop" | ||
| [[ -f $inject_file ]] || | ||
| fail "tui install writes a desktop entry for a name containing a newline" | ||
| (( $(grep -c '^Exec=' "$inject_file") == 1 )) || | ||
| fail "a newline in the name cannot inject a second Exec" "$(cat "$inject_file")" | ||
| grep -Fqx 'Name=Inject\nExec=evil' "$inject_file" || | ||
| fail "a newline in the name is escaped in the Name field" "$(cat "$inject_file")" | ||
| pass "tui install escapes newlines instead of writing a second Exec" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This test injects a newline only through the app name, although the change also escapes the Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At 3b7b242, desktop-value escaping is unchanged from Checked by Codex High, Opus 5.5 High and muse-wonder via pi (thinking high); the reviewers agreed, and independence is not guaranteed. |
||
|
|
||
| # A normal name still installs and removes. | ||
| run_install "Example App" "lazydocker" tile hey >/dev/null | ||
| [[ -f "$apps_dir/Example App.desktop" ]] || | ||
| fail "tui install writes the launcher for an ordinary name" | ||
| grep -Fqx 'Exec=xdg-terminal-exec --app-id=TUI.tile -e lazydocker' "$apps_dir/Example App.desktop" || | ||
| fail "tui install writes the launch command" "$(cat "$apps_dir/Example App.desktop")" | ||
| run_remove "Example App" >/dev/null | ||
| [[ -f "$apps_dir/Example App.desktop" ]] && | ||
| fail "tui remove deletes the launcher it installed" | ||
| pass "tui install and remove round-trip an ordinary name" | ||
|
|
||
| # Anything installed by an older version can still be nested. Removal has to | ||
| # reach it, which a path rebuilt from the displayed name never could. | ||
| mkdir -p "$apps_dir/legacy/sub" | ||
| cat >"$apps_dir/legacy/sub/Nested.desktop" <<'DESKTOP' | ||
| [Desktop Entry] | ||
| Name=Nested | ||
| Exec=xdg-terminal-exec --app-id=TUI.tile -e lazydocker | ||
| Type=Application | ||
| DESKTOP | ||
|
|
||
| run_remove "Nested" >/dev/null | ||
| [[ -f "$apps_dir/legacy/sub/Nested.desktop" ]] && | ||
| fail "tui remove deletes a launcher left nested by an older install" | ||
| pass "tui remove reaches a nested legacy launcher" | ||
|
|
||
| # The launcher's own remove action names the top-level entry, so a nested legacy | ||
| # launcher sharing its name must not be the one deleted, whichever find meets first. | ||
| for order in "nested-first" "top-first"; do | ||
| if [[ $order == "nested-first" ]]; then | ||
| mkdir -p "$apps_dir/legacy" | ||
| launchers=("$apps_dir/legacy/Docker.desktop" "$apps_dir/Docker.desktop") | ||
| else | ||
| launchers=("$apps_dir/Docker.desktop" "$apps_dir/legacy/Docker.desktop") | ||
| fi | ||
| for launcher in "${launchers[@]}"; do | ||
| mkdir -p "$(dirname "$launcher")" | ||
| printf '[Desktop Entry]\nName=Docker\nExec=xdg-terminal-exec --app-id=TUI.tile -e lazydocker\nType=Application\n' >"$launcher" | ||
| done | ||
|
|
||
| run_remove "Docker" >/dev/null | ||
| [[ -f "$apps_dir/Docker.desktop" ]] && | ||
| fail "tui remove deletes the top-level launcher it was named for ($order)" | ||
| [[ -f "$apps_dir/legacy/Docker.desktop" ]] || | ||
| fail "tui remove leaves a nested launcher of the same name alone ($order)" | ||
| rm -rf "$apps_dir/legacy" | ||
| done | ||
| pass "tui remove prefers the top-level launcher over a nested one of the same name" | ||
|
|
||
| # Removing by name on a machine with no applications directory yet must stay | ||
| # quiet: this removal is called by the launcher without hiding stderr. | ||
| noise=$(HOME="$tmp_dir/empty" PATH="$tmp_dir/bin:$PATH" OMARCHY_REMOVE_NOTIFY=false \ | ||
| "$ROOT/bin/omarchy-tui-remove" "Example App" 2>&1 >/dev/null) | ||
| [[ -n $noise ]] && | ||
| fail "tui remove stays quiet with no applications directory" "$noise" | ||
| pass "tui remove stays quiet when there is no applications directory" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new guard accepts names containing newlines, and the new test installs one. During interactive removal,
omarchy-tui-removeprints each indexed name on a separate line before sorting, so that name becomes multiple menu choices. Selecting a fragment cannot remove the launcher and may instead remove a different launcher named after that fragment. Reject newlines in names or preserve names intact through selection.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At 3b7b242, the installer comes unchanged from
quattro: #19965 already merged its name guard and desktop-value escaping. This PR now changes only the remover's top-level namesake preference and regression coverage. Newline names splitting in the picker is inherited fromquattro, including its webapp picker, and is unchanged by this fix.Checked by Codex High, Opus 5.5 High and muse-wonder via pi (thinking high); the reviewers agreed, and independence is not guaranteed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. At
3b7b242,omarchy-tui-install’s name guard and desktop escaping are already present in the base branch, and this PR does not change the picker’s line-based handling. The newline-name picker issue is pre-existing (and also affects the webapp picker), so I’m withdrawing the finding as out of scope for this change. The underlying behavior may still merit a separate fix.