From d84b580b3eb0893635fd8b76f8236103209f7f9f Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 13:43:03 +0330 Subject: [PATCH 01/10] Fix font removal menu behavior Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 64 ++++++++++++++++++++++----------------- default/i18n/en/cli.json | 10 ++++++ default/i18n/en/menu.json | 4 +++ 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index ab8368c91818..fae2b6f0982d 100644 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -1,5 +1,6 @@ #!/bin/bash # omarchy-font-remove — Remove an installed system font package. +# omarchy:summary=Remove an installed system font package # # Intended for the omarchy menu: SUPER+SPACE → Remove → Fonts # (wired up in ~/.config/omarchy/extensions/omarchy-menu.jsonc) @@ -27,7 +28,7 @@ set -u usage() { - echo "Usage: omarchy-font-remove [--list|]" + echo "Usage: omarchy-font-remove [--list||--do ]" } CURRENT_FONT=$(omarchy-font-current 2>/dev/null | head -n1) @@ -78,7 +79,7 @@ for row in "${font_rows[@]}"; do file=${row#*|} # Only package-managed system fonts; anything else (e.g. user fonts in # ~/.local/share/fonts) is not tracked by pacman and is skipped. - [[ -n $family && -n $file && $family != "$row" ]] || continue + [[ -n $family && -n $file && $family != $row ]] || continue case $file in /usr/share/fonts/*) ;; *) continue ;; esac family_file[$family]="${family_file[$family]:-$file}" done @@ -127,7 +128,7 @@ if (( ${#family_file[@]} > 0 )); then ""|"omarchy"|"omarchy-"*|"noto-fonts-emoji") continue ;; esac family_pkg[$family]=$pkg - [[ $family == "$CURRENT_FONT" ]] && current_pkg=$pkg + [[ $family == $CURRENT_FONT ]] && current_pkg=$pkg done # One label per package: the first alphabetical monospace family it @@ -244,23 +245,22 @@ if (( ${#family_pkg[@]} > 0 )); then done < <(LC_ALL=C pacman -Qi 2>/dev/null | awk -v pkgs="$candidates" "$BLOCKER_AWK") fi -# label -> package. pkg_label is keyed by package, so the picker and --list -# are sorted and walked through this inverse map to get family/package the -# right way round. +# Family -> package. pkg_label is keyed by package, so invert it to sort and +# display the representative family together with its owning package. declare -A label_pkg=() for pkg in "${!pkg_label[@]}"; do label_pkg[${pkg_label[$pkg]}]=$pkg done -sorted_labels=() -while IFS= read -r label; do - sorted_labels+=("$label") +sorted_families=() +while IFS= read -r family; do + sorted_families+=("$family") done < <(printf '%s\n' "${!label_pkg[@]}" | LC_ALL=C sort) pick_family() { # --do sets COMMAND_MODE itself; never clobber it. [[ -n $COMMAND_MODE ]] && return - if [[ $FAMILY_ARG == --list ]]; then + if [[ $FAMILY_ARG == "--list" ]]; then COMMAND_MODE=list elif [[ -z $FAMILY_ARG ]]; then COMMAND_MODE=menu @@ -277,7 +277,7 @@ lookup_font() { local chosen=$1 lowered candidate family pkg local -a parts=() local rest=$chosen - while [[ $rest == *"$TAB"* ]]; do + while [[ $rest == *$TAB* ]]; do parts+=("${rest%%${TAB}*}") rest=${rest#*${TAB}} done @@ -295,13 +295,13 @@ lookup_font() { fi if [[ -n $lowered ]]; then for family in "${!family_pkg[@]}"; do - if [[ $(printf '%s' "$family" | tr '[:upper:]' '[:lower:]') == "$lowered" ]]; then + if [[ $(printf '%s' "$family" | tr '[:upper:]' '[:lower:]') == $lowered ]]; then printf '%s\n' "$family${TAB}${family_pkg[$family]}" return 0 fi done for pkg in "${!pkg_label[@]}"; do - if [[ $(printf '%s' "$pkg" | tr '[:upper:]' '[:lower:]') == "$lowered" ]]; then + if [[ $(printf '%s' "$pkg" | tr '[:upper:]' '[:lower:]') == $lowered ]]; then printf '%s\n' "${pkg_label[$pkg]}${TAB}$pkg" return 0 fi @@ -316,7 +316,7 @@ uninstall_font() { echo "==> Removing font package: $pkg" log=$(mktemp) - sudo pacman -Rns --noconfirm -- "$pkg" 2>&1 | tee "$log" + omarchy-pkg-drop "$pkg" 2>&1 | tee "$log" status=${PIPESTATUS[0]} if (( status != 0 )); then @@ -331,13 +331,17 @@ uninstall_font() { fi rm -f -- "$log" echo "==> Failed to remove $pkg${reason:+: $reason}" - omarchy-notification-send "Font removal failed" "$label: ${reason:-see terminal output}" || true + omarchy-notification-send \ + "$(omarchy-i18n font.removeFailed)" \ + "$(omarchy-i18n font.removeFailedBody "$label" "${reason:-$(omarchy-i18n font.removeSeeTerminal)}")" || true exit 1 fi rm -f -- "$log" fc-cache -f >/dev/null 2>&1 - omarchy-notification-send "Font removed" "$label ($pkg)" || true + omarchy-notification-send \ + "$(omarchy-i18n font.removed)" \ + "$(omarchy-i18n font.removedBody "$label" "$pkg")" || true echo "==> Removed $label." echo " Running apps may need a restart to drop the old font." } @@ -348,7 +352,9 @@ remove_font() { if [[ -n $current_pkg && $pkg == "$current_pkg" ]]; then echo "==> '$label' is the font currently in use." echo " Set a different font first (Settings → Font), then remove it." - omarchy-notification-send "Font removal skipped" "'$label' is the active font" || true + omarchy-notification-send \ + "$(omarchy-i18n font.removeSkipped)" \ + "$(omarchy-i18n font.removeActive "$label")" || true exit 1 fi @@ -359,13 +365,15 @@ remove_font() { reason=${blocked[$pkg]} echo "==> Can't remove '$label' ($pkg): $reason." echo " Remove or replace whatever depends on it first, or keep the font." - omarchy-notification-send "Font removal blocked" "$label: $reason" || true + omarchy-notification-send \ + "$(omarchy-i18n font.removeBlocked)" \ + "$(omarchy-i18n font.removeBlockedBody "$label" "$reason")" || true exit 1 fi # Menu actions run detached (no TTY), so sudo would have nowhere to ask # for a password: finish the uninstall inside a floating terminal instead. - if [[ -t 1 || $COMMAND_MODE == do ]]; then + if [[ -t 1 || $COMMAND_MODE == "do" ]]; then uninstall_font "$pkg" "$label" else printf -v quoted_label '%q' "$label" @@ -378,11 +386,13 @@ pick_family case $COMMAND_MODE in list) - for label in ${sorted_labels[@]+"${sorted_labels[@]}"}; do - pkg=${label_pkg[$label]} + for family in ${sorted_families[@]+"${sorted_families[@]}"}; do + pkg=${label_pkg[$family]} + # The active font package cannot be removed, so don't advertise it. + [[ -n $current_pkg && $pkg == $current_pkg ]] && continue # Fonts other packages still need can't be removed; don't list them. [[ -n ${blocked[$pkg]+x} ]] && continue - printf '%s\n' "$label${TAB}$pkg" + printf '%s\n' "$family${TAB}$pkg" done exit 0 ;; @@ -393,13 +403,13 @@ case $COMMAND_MODE in fi options=() - for label in ${sorted_labels[@]+"${sorted_labels[@]}"}; do - pkg=${label_pkg[$label]} + for family in ${sorted_families[@]+"${sorted_families[@]}"}; do + pkg=${label_pkg[$family]} # The active font's package is never offered for removal. - [[ -n $current_pkg && $pkg == "$current_pkg" ]] && continue + [[ -n $current_pkg && $pkg == $current_pkg ]] && continue # Nor are fonts that other installed packages still depend on. [[ -n ${blocked[$pkg]+x} ]] && continue - options+=("$FONT_GLYPH${TAB}${label}${TAB}${pkg}") + options+=("$FONT_GLYPH${TAB}${family}${TAB}${pkg}") done if (( ${#options[@]} == 0 )); then @@ -407,7 +417,7 @@ case $COMMAND_MODE in exit 0 fi - chosen=$(omarchy-menu-select "Remove font" "${options[@]}" -- --width 520 --maxheight 520) || exit 0 + chosen=$(omarchy-menu-select "$(omarchy-i18n font.removeSelect)" "${options[@]}" -- --width 520 --maxheight 520) || exit 0 if resolved=$(lookup_font "$chosen"); then label=${resolved%%${TAB}*} diff --git a/default/i18n/en/cli.json b/default/i18n/en/cli.json index d9e80076c80b..0992f8f26d86 100644 --- a/default/i18n/en/cli.json +++ b/default/i18n/en/cli.json @@ -94,6 +94,16 @@ "drive.select": "Select drive", "files.selectFile": "Select file", "font.cjkChanged": "Chinese, Japanese, and Korean glyph forms changed", + "font.removeActive": "%1 is the active font", + "font.removeBlocked": "Font removal blocked", + "font.removeBlockedBody": "%1: %2", + "font.removeFailed": "Font removal failed", + "font.removeFailedBody": "%1: %2", + "font.removeSkipped": "Font removal skipped", + "font.removeSeeTerminal": "see terminal output", + "font.removeSelect": "Select font to remove", + "font.removed": "Font removed", + "font.removedBody": "%1 (%2)", "font.restartAppsToSeeChange": "Restart open apps to see the change", "font.restartToSeeChange": "You must restart %1 to see font change", "games.corePrompt": "RetroArch core", diff --git a/default/i18n/en/menu.json b/default/i18n/en/menu.json index b0297c34e3bc..b295852896f5 100644 --- a/default/i18n/en/menu.json +++ b/default/i18n/en/menu.json @@ -985,6 +985,10 @@ "remove.webapp": { "label": "Web App" }, + "remove.font": { + "label": "Fonts", + "description": "Remove an installed font package" + }, "remove.tui": { "label": "TUI" }, From bfb6a002a192df84351a97a0a46bc429cacee0ef Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 13:49:24 +0330 Subject: [PATCH 02/10] Match font names literally Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 4 +-- test/shell.d/font-remove-test.sh | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 test/shell.d/font-remove-test.sh diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index fae2b6f0982d..7cfb6250341e 100644 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -295,13 +295,13 @@ lookup_font() { fi if [[ -n $lowered ]]; then for family in "${!family_pkg[@]}"; do - if [[ $(printf '%s' "$family" | tr '[:upper:]' '[:lower:]') == $lowered ]]; then + if [[ $(printf '%s' "$family" | tr '[:upper:]' '[:lower:]') == "$lowered" ]]; then printf '%s\n' "$family${TAB}${family_pkg[$family]}" return 0 fi done for pkg in "${!pkg_label[@]}"; do - if [[ $(printf '%s' "$pkg" | tr '[:upper:]' '[:lower:]') == $lowered ]]; then + if [[ $(printf '%s' "$pkg" | tr '[:upper:]' '[:lower:]') == "$lowered" ]]; then printf '%s\n' "${pkg_label[$pkg]}${TAB}$pkg" return 0 fi diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh new file mode 100644 index 000000000000..89bf18361e3d --- /dev/null +++ b/test/shell.d/font-remove-test.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +test_tmp=$(mktemp -d) +trap 'rm -rf "$test_tmp"' EXIT + +mock_bin="$test_tmp/bin" +mkdir -p "$mock_bin" + +cat >"$mock_bin/fc-list" <<'SH' +#!/bin/bash +if [[ $1 == "-f" ]]; then + printf '%s\n' 'Liberation Mono|/usr/share/fonts/TTF/liberation.ttf' +fi +SH + +cat >"$mock_bin/pacman" <<'SH' +#!/bin/bash +case $1 in + -Ql) + printf '%s\n' 'liberation-font /usr/share/fonts/TTF/liberation.ttf' + ;; + -Qi) + cat <<'INFO' +Name : liberation-font +Provides : None +Depends On : None + +INFO + ;; +esac +SH + +cat >"$mock_bin/omarchy-font-current" <<'SH' +#!/bin/bash +echo "Some other font" +SH + +chmod +x "$mock_bin/fc-list" "$mock_bin/pacman" "$mock_bin/omarchy-font-current" + +for requested in 'Liberation Mono?' 'liberation-font?'; do + if PATH="$mock_bin:$ROOT/bin:$PATH" bash "$ROOT/bin/omarchy-font-remove" "$requested" >"$test_tmp/output" 2>&1; then + fail "wildcard characters in an unknown font name are rejected: $requested" + fi + + grep -q "Font '$requested' was not found" "$test_tmp/output" || + fail "unknown font name reports not found: $requested" "$(cat "$test_tmp/output")" +done +pass "unknown family and package globs do not resolve to installed fonts" From c423564bfc8358fd7d5980072fc804b6369bcd0c Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 13:54:17 +0330 Subject: [PATCH 03/10] Show active font in removal picker Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 8 +++--- default/i18n/en/cli.json | 1 + test/shell.d/font-remove-test.sh | 43 ++++++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index 7cfb6250341e..929f21bfba34 100644 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -405,11 +405,13 @@ case $COMMAND_MODE in options=() for family in ${sorted_families[@]+"${sorted_families[@]}"}; do pkg=${label_pkg[$family]} - # The active font's package is never offered for removal. - [[ -n $current_pkg && $pkg == $current_pkg ]] && continue # Nor are fonts that other installed packages still depend on. [[ -n ${blocked[$pkg]+x} ]] && continue - options+=("$FONT_GLYPH${TAB}${family}${TAB}${pkg}") + if [[ -n $current_pkg && $pkg == $current_pkg ]]; then + options+=("$FONT_GLYPH $(omarchy-i18n font.active)${TAB}${family}${TAB}${pkg}") + else + options+=("$FONT_GLYPH${TAB}${family}${TAB}${pkg}") + fi done if (( ${#options[@]} == 0 )); then diff --git a/default/i18n/en/cli.json b/default/i18n/en/cli.json index 0992f8f26d86..225f9f191a68 100644 --- a/default/i18n/en/cli.json +++ b/default/i18n/en/cli.json @@ -94,6 +94,7 @@ "drive.select": "Select drive", "files.selectFile": "Select file", "font.cjkChanged": "Chinese, Japanese, and Korean glyph forms changed", + "font.active": "Active", "font.removeActive": "%1 is the active font", "font.removeBlocked": "Font removal blocked", "font.removeBlockedBody": "%1: %2", diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh index 89bf18361e3d..37be0e480f21 100644 --- a/test/shell.d/font-remove-test.sh +++ b/test/shell.d/font-remove-test.sh @@ -36,10 +36,36 @@ SH cat >"$mock_bin/omarchy-font-current" <<'SH' #!/bin/bash -echo "Some other font" +echo "${TEST_CURRENT_FONT:-Some other font}" SH -chmod +x "$mock_bin/fc-list" "$mock_bin/pacman" "$mock_bin/omarchy-font-current" +cat >"$mock_bin/omarchy-menu-select" <<'SH' +#!/bin/bash +printf '%s\n' "$2" >"$TEST_MENU_SELECTION" +printf '%s\n' "$2" +SH + +cat >"$mock_bin/omarchy-i18n" <<'SH' +#!/bin/bash +case $1 in + font.active) echo "Active" ;; + font.removeSkipped) echo "Font removal skipped" ;; + font.removeActive) printf '%s is the active font\n' "$2" ;; +esac +SH + +cat >"$mock_bin/omarchy-notification-send" <<'SH' +#!/bin/bash +: +SH + +cat >"$mock_bin/omarchy-pkg-drop" <<'SH' +#!/bin/bash +printf '%s\n' "$*" >>"$TEST_PKG_DROP_LOG" +SH +chmod +x "$mock_bin/fc-list" "$mock_bin/pacman" "$mock_bin/omarchy-font-current" \ + "$mock_bin/omarchy-menu-select" "$mock_bin/omarchy-i18n" \ + "$mock_bin/omarchy-notification-send" "$mock_bin/omarchy-pkg-drop" for requested in 'Liberation Mono?' 'liberation-font?'; do if PATH="$mock_bin:$ROOT/bin:$PATH" bash "$ROOT/bin/omarchy-font-remove" "$requested" >"$test_tmp/output" 2>&1; then @@ -50,3 +76,16 @@ for requested in 'Liberation Mono?' 'liberation-font?'; do fail "unknown font name reports not found: $requested" "$(cat "$test_tmp/output")" done pass "unknown family and package globs do not resolve to installed fonts" + +if TEST_CURRENT_FONT="Liberation Mono" TEST_MENU_SELECTION="$test_tmp/menu-selection" \ + TEST_PKG_DROP_LOG="$test_tmp/pkg-drop.log" \ + PATH="$mock_bin:$ROOT/bin:$PATH" bash "$ROOT/bin/omarchy-font-remove" >"$test_tmp/output" 2>&1; then + fail "active font cannot be removed from the picker" +fi + +grep -q "Liberation Mono.*currently in use" "$test_tmp/output" || + fail "active font is identified after selection" "$(cat "$test_tmp/output")" +grep -q "Active.*Liberation Mono" "$test_tmp/menu-selection" || + fail "active font is visibly marked in the picker" "$(cat "$test_tmp/menu-selection")" +[[ ! -e $test_tmp/pkg-drop.log ]] || fail "active font package is never removed" +pass "active installed font appears in the picker but remains protected" From 461f3aa47a4f1dacb9ea4451d1211453c0e938db Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 13:58:07 +0330 Subject: [PATCH 04/10] Fix active font picker display Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 2 +- test/shell.d/font-remove-test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 bin/omarchy-font-remove diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove old mode 100644 new mode 100755 index 929f21bfba34..2405e1bc7f80 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -408,7 +408,7 @@ case $COMMAND_MODE in # Nor are fonts that other installed packages still depend on. [[ -n ${blocked[$pkg]+x} ]] && continue if [[ -n $current_pkg && $pkg == $current_pkg ]]; then - options+=("$FONT_GLYPH $(omarchy-i18n font.active)${TAB}${family}${TAB}${pkg}") + options+=("$FONT_GLYPH${TAB}${family} ($(omarchy-i18n font.active))${TAB}${pkg}") else options+=("$FONT_GLYPH${TAB}${family}${TAB}${pkg}") fi diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh index 37be0e480f21..d5b4d59cfec3 100644 --- a/test/shell.d/font-remove-test.sh +++ b/test/shell.d/font-remove-test.sh @@ -85,7 +85,7 @@ fi grep -q "Liberation Mono.*currently in use" "$test_tmp/output" || fail "active font is identified after selection" "$(cat "$test_tmp/output")" -grep -q "Active.*Liberation Mono" "$test_tmp/menu-selection" || +grep -q $'\tLiberation Mono (Active)\tliberation-font' "$test_tmp/menu-selection" || fail "active font is visibly marked in the picker" "$(cat "$test_tmp/menu-selection")" [[ ! -e $test_tmp/pkg-drop.log ]] || fail "active font package is never removed" pass "active installed font appears in the picker but remains protected" From 91ea12ef6f562e4cd6b6a5152f85090236c89d89 Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 14:03:07 +0330 Subject: [PATCH 05/10] Add font glyph to removal notifications Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 8 ++++---- test/shell.d/font-remove-test.sh | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index 2405e1bc7f80..f358333d5ec1 100755 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -331,7 +331,7 @@ uninstall_font() { fi rm -f -- "$log" echo "==> Failed to remove $pkg${reason:+: $reason}" - omarchy-notification-send \ + omarchy-notification-send -g "$FONT_GLYPH" \ "$(omarchy-i18n font.removeFailed)" \ "$(omarchy-i18n font.removeFailedBody "$label" "${reason:-$(omarchy-i18n font.removeSeeTerminal)}")" || true exit 1 @@ -339,7 +339,7 @@ uninstall_font() { rm -f -- "$log" fc-cache -f >/dev/null 2>&1 - omarchy-notification-send \ + omarchy-notification-send -g "$FONT_GLYPH" \ "$(omarchy-i18n font.removed)" \ "$(omarchy-i18n font.removedBody "$label" "$pkg")" || true echo "==> Removed $label." @@ -352,7 +352,7 @@ remove_font() { if [[ -n $current_pkg && $pkg == "$current_pkg" ]]; then echo "==> '$label' is the font currently in use." echo " Set a different font first (Settings → Font), then remove it." - omarchy-notification-send \ + omarchy-notification-send -g "$FONT_GLYPH" \ "$(omarchy-i18n font.removeSkipped)" \ "$(omarchy-i18n font.removeActive "$label")" || true exit 1 @@ -365,7 +365,7 @@ remove_font() { reason=${blocked[$pkg]} echo "==> Can't remove '$label' ($pkg): $reason." echo " Remove or replace whatever depends on it first, or keep the font." - omarchy-notification-send \ + omarchy-notification-send -g "$FONT_GLYPH" \ "$(omarchy-i18n font.removeBlocked)" \ "$(omarchy-i18n font.removeBlockedBody "$label" "$reason")" || true exit 1 diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh index d5b4d59cfec3..6cfad585d097 100644 --- a/test/shell.d/font-remove-test.sh +++ b/test/shell.d/font-remove-test.sh @@ -56,7 +56,7 @@ SH cat >"$mock_bin/omarchy-notification-send" <<'SH' #!/bin/bash -: +printf '%s\n' "$@" >>"$TEST_NOTIFICATION_LOG" SH cat >"$mock_bin/omarchy-pkg-drop" <<'SH' @@ -79,6 +79,7 @@ pass "unknown family and package globs do not resolve to installed fonts" if TEST_CURRENT_FONT="Liberation Mono" TEST_MENU_SELECTION="$test_tmp/menu-selection" \ TEST_PKG_DROP_LOG="$test_tmp/pkg-drop.log" \ + TEST_NOTIFICATION_LOG="$test_tmp/notification.log" \ PATH="$mock_bin:$ROOT/bin:$PATH" bash "$ROOT/bin/omarchy-font-remove" >"$test_tmp/output" 2>&1; then fail "active font cannot be removed from the picker" fi @@ -88,4 +89,8 @@ grep -q "Liberation Mono.*currently in use" "$test_tmp/output" || grep -q $'\tLiberation Mono (Active)\tliberation-font' "$test_tmp/menu-selection" || fail "active font is visibly marked in the picker" "$(cat "$test_tmp/menu-selection")" [[ ! -e $test_tmp/pkg-drop.log ]] || fail "active font package is never removed" +[[ $(sed -n '1p' "$test_tmp/notification.log") == "-g" ]] || + fail "font notifications include the glyph option" +[[ $(sed -n '2p' "$test_tmp/notification.log") == "$(printf '\ue659')" ]] || + fail "font notifications use the font glyph" "$(cat "$test_tmp/notification.log")" pass "active installed font appears in the picker but remains protected" From fd2fcba267597ca8939b98e0dae66a4c59402057 Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 14:05:05 +0330 Subject: [PATCH 06/10] Name the removed font in notification Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 3 +-- default/i18n/en/cli.json | 3 +-- test/shell.d/font-remove-test.sh | 12 ++++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index f358333d5ec1..51ca4260d14b 100755 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -340,8 +340,7 @@ uninstall_font() { fc-cache -f >/dev/null 2>&1 omarchy-notification-send -g "$FONT_GLYPH" \ - "$(omarchy-i18n font.removed)" \ - "$(omarchy-i18n font.removedBody "$label" "$pkg")" || true + "$(omarchy-i18n font.removed "$label")" || true echo "==> Removed $label." echo " Running apps may need a restart to drop the old font." } diff --git a/default/i18n/en/cli.json b/default/i18n/en/cli.json index 225f9f191a68..59bb8eac7925 100644 --- a/default/i18n/en/cli.json +++ b/default/i18n/en/cli.json @@ -103,8 +103,7 @@ "font.removeSkipped": "Font removal skipped", "font.removeSeeTerminal": "see terminal output", "font.removeSelect": "Select font to remove", - "font.removed": "Font removed", - "font.removedBody": "%1 (%2)", + "font.removed": "%1 font removed", "font.restartAppsToSeeChange": "Restart open apps to see the change", "font.restartToSeeChange": "You must restart %1 to see font change", "games.corePrompt": "RetroArch core", diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh index 6cfad585d097..808bfac6185a 100644 --- a/test/shell.d/font-remove-test.sh +++ b/test/shell.d/font-remove-test.sh @@ -49,6 +49,7 @@ cat >"$mock_bin/omarchy-i18n" <<'SH' #!/bin/bash case $1 in font.active) echo "Active" ;; + font.removed) printf '%s font removed\n' "$2" ;; font.removeSkipped) echo "Font removal skipped" ;; font.removeActive) printf '%s is the active font\n' "$2" ;; esac @@ -94,3 +95,14 @@ grep -q $'\tLiberation Mono (Active)\tliberation-font' "$test_tmp/menu-selection [[ $(sed -n '2p' "$test_tmp/notification.log") == "$(printf '\ue659')" ]] || fail "font notifications use the font glyph" "$(cat "$test_tmp/notification.log")" pass "active installed font appears in the picker but remains protected" + +TEST_CURRENT_FONT="Some other font" TEST_PKG_DROP_LOG="$test_tmp/pkg-drop-success.log" \ + TEST_NOTIFICATION_LOG="$test_tmp/notification-success.log" \ + PATH="$mock_bin:$ROOT/bin:$PATH" bash "$ROOT/bin/omarchy-font-remove" --do "Liberation Mono" >"$test_tmp/output" 2>&1 || + fail "removing a non-active font succeeds" "$(cat "$test_tmp/output")" + +[[ $(sed -n '3p' "$test_tmp/notification-success.log") == "Liberation Mono font removed" ]] || + fail "success notification names the removed font" "$(cat "$test_tmp/notification-success.log")" +[[ $(cat "$test_tmp/pkg-drop-success.log") == "liberation-font" ]] || + fail "success path removes the selected font package" +pass "success notification says which font was removed" From cff2e8c958c9e691486ac5dda16c6b31546c09e8 Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 14:08:24 +0330 Subject: [PATCH 07/10] Improve font removal success notification Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 5 +++-- default/i18n/en/cli.json | 3 ++- test/shell.d/font-remove-test.sh | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index 51ca4260d14b..916293e13496 100755 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -339,8 +339,9 @@ uninstall_font() { rm -f -- "$log" fc-cache -f >/dev/null 2>&1 - omarchy-notification-send -g "$FONT_GLYPH" \ - "$(omarchy-i18n font.removed "$label")" || true + omarchy-notification-send -g "$FONT_GLYPH" -u normal \ + "$(omarchy-i18n font.removed)" \ + "$(omarchy-i18n font.removeSuccessBody "$label")" || true echo "==> Removed $label." echo " Running apps may need a restart to drop the old font." } diff --git a/default/i18n/en/cli.json b/default/i18n/en/cli.json index 59bb8eac7925..fa8b586e51c1 100644 --- a/default/i18n/en/cli.json +++ b/default/i18n/en/cli.json @@ -103,7 +103,8 @@ "font.removeSkipped": "Font removal skipped", "font.removeSeeTerminal": "see terminal output", "font.removeSelect": "Select font to remove", - "font.removed": "%1 font removed", + "font.removeSuccessBody": "The %1 font has been removed successfully.", + "font.removed": "Font removed", "font.restartAppsToSeeChange": "Restart open apps to see the change", "font.restartToSeeChange": "You must restart %1 to see font change", "games.corePrompt": "RetroArch core", diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh index 808bfac6185a..6f67f062c098 100644 --- a/test/shell.d/font-remove-test.sh +++ b/test/shell.d/font-remove-test.sh @@ -49,7 +49,8 @@ cat >"$mock_bin/omarchy-i18n" <<'SH' #!/bin/bash case $1 in font.active) echo "Active" ;; - font.removed) printf '%s font removed\n' "$2" ;; + font.removeSuccessBody) printf 'The %s font has been removed successfully.\n' "$2" ;; + font.removed) echo "Font removed" ;; font.removeSkipped) echo "Font removal skipped" ;; font.removeActive) printf '%s is the active font\n' "$2" ;; esac @@ -101,8 +102,16 @@ TEST_CURRENT_FONT="Some other font" TEST_PKG_DROP_LOG="$test_tmp/pkg-drop-succes PATH="$mock_bin:$ROOT/bin:$PATH" bash "$ROOT/bin/omarchy-font-remove" --do "Liberation Mono" >"$test_tmp/output" 2>&1 || fail "removing a non-active font succeeds" "$(cat "$test_tmp/output")" -[[ $(sed -n '3p' "$test_tmp/notification-success.log") == "Liberation Mono font removed" ]] || - fail "success notification names the removed font" "$(cat "$test_tmp/notification-success.log")" +[[ $(sed -n '1p' "$test_tmp/notification-success.log") == "-g" && + $(sed -n '2p' "$test_tmp/notification-success.log") == "$(printf '\ue659')" ]] || + fail "success notification uses the font glyph" "$(cat "$test_tmp/notification-success.log")" +[[ $(sed -n '3p' "$test_tmp/notification-success.log") == "-u" && + $(sed -n '4p' "$test_tmp/notification-success.log") == "normal" ]] || + fail "success notification uses normal urgency" "$(cat "$test_tmp/notification-success.log")" +[[ $(sed -n '5p' "$test_tmp/notification-success.log") == "Font removed" ]] || + fail "success notification has a concise title" "$(cat "$test_tmp/notification-success.log")" +[[ $(sed -n '6p' "$test_tmp/notification-success.log") == "The Liberation Mono font has been removed successfully." ]] || + fail "success notification says which font was removed" "$(cat "$test_tmp/notification-success.log")" [[ $(cat "$test_tmp/pkg-drop-success.log") == "liberation-font" ]] || fail "success path removes the selected font package" pass "success notification says which font was removed" From d5c017a47e84a6586503c844886972a04ebf33f1 Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 14:24:25 +0330 Subject: [PATCH 08/10] Add font notification translation fallback Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 47 ++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index 916293e13496..db45db26e6fd 100755 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -37,6 +37,33 @@ TAB=$'\t' COMMAND_MODE="" FAMILY_ARG="" +# Translate a string via omarchy-i18n, falling back to built-in English when +# the catalog has no entry (omarchy-i18n then echoes the raw key back, which is +# what showed up in notifications as "font.removeSuccessBody"). +t() { + local key=$1 out + shift + out=$(omarchy-i18n "$key" "$@" 2>/dev/null) || out="" + if [[ -n $out && $out != "$key"* ]]; then + printf '%s\n' "$out" + return 0 + fi + case $key in + font.removed) printf 'Font removed\n' ;; + font.removeSuccessBody) printf 'Font %s removed\n' "${1:-}" ;; + font.removeFailed) printf 'Font removal failed\n' ;; + font.removeFailedBody) printf "Couldn't remove %s: %s\n" "${1:-}" "${2:-}" ;; + font.removeSeeTerminal) printf 'see the terminal for details\n' ;; + font.removeSkipped) printf 'Font not removed\n' ;; + font.removeActive) printf '%s is the font currently in use\n' "${1:-}" ;; + font.removeBlocked) printf "Font can't be removed\n" ;; + font.removeBlockedBody) printf "%s can't be removed: %s\n" "${1:-}" "${2:-}" ;; + font.removeSelect) printf 'Remove font\n' ;; + font.active) printf 'active\n' ;; + *) printf '%s\n' "$key" ;; + esac +} + if (( $# > 2 )); then usage >&2 exit 1 @@ -332,16 +359,16 @@ uninstall_font() { rm -f -- "$log" echo "==> Failed to remove $pkg${reason:+: $reason}" omarchy-notification-send -g "$FONT_GLYPH" \ - "$(omarchy-i18n font.removeFailed)" \ - "$(omarchy-i18n font.removeFailedBody "$label" "${reason:-$(omarchy-i18n font.removeSeeTerminal)}")" || true + "$(t font.removeFailed)" \ + "$(t font.removeFailedBody "$label" "${reason:-$(t font.removeSeeTerminal)}")" || true exit 1 fi rm -f -- "$log" fc-cache -f >/dev/null 2>&1 omarchy-notification-send -g "$FONT_GLYPH" -u normal \ - "$(omarchy-i18n font.removed)" \ - "$(omarchy-i18n font.removeSuccessBody "$label")" || true + "$(t font.removed)" \ + "$(t font.removeSuccessBody "$label")" || true echo "==> Removed $label." echo " Running apps may need a restart to drop the old font." } @@ -353,8 +380,8 @@ remove_font() { echo "==> '$label' is the font currently in use." echo " Set a different font first (Settings → Font), then remove it." omarchy-notification-send -g "$FONT_GLYPH" \ - "$(omarchy-i18n font.removeSkipped)" \ - "$(omarchy-i18n font.removeActive "$label")" || true + "$(t font.removeSkipped)" \ + "$(t font.removeActive "$label")" || true exit 1 fi @@ -366,8 +393,8 @@ remove_font() { echo "==> Can't remove '$label' ($pkg): $reason." echo " Remove or replace whatever depends on it first, or keep the font." omarchy-notification-send -g "$FONT_GLYPH" \ - "$(omarchy-i18n font.removeBlocked)" \ - "$(omarchy-i18n font.removeBlockedBody "$label" "$reason")" || true + "$(t font.removeBlocked)" \ + "$(t font.removeBlockedBody "$label" "$reason")" || true exit 1 fi @@ -408,7 +435,7 @@ case $COMMAND_MODE in # Nor are fonts that other installed packages still depend on. [[ -n ${blocked[$pkg]+x} ]] && continue if [[ -n $current_pkg && $pkg == $current_pkg ]]; then - options+=("$FONT_GLYPH${TAB}${family} ($(omarchy-i18n font.active))${TAB}${pkg}") + options+=("$FONT_GLYPH${TAB}${family} ($(t font.active))${TAB}${pkg}") else options+=("$FONT_GLYPH${TAB}${family}${TAB}${pkg}") fi @@ -419,7 +446,7 @@ case $COMMAND_MODE in exit 0 fi - chosen=$(omarchy-menu-select "$(omarchy-i18n font.removeSelect)" "${options[@]}" -- --width 520 --maxheight 520) || exit 0 + chosen=$(omarchy-menu-select "$(t font.removeSelect)" "${options[@]}" -- --width 520 --maxheight 520) || exit 0 if resolved=$(lookup_font "$chosen"); then label=${resolved%%${TAB}*} From 881a7635d80b8d848df83420f67d1ba5cf0ba387 Mon Sep 17 00:00:00 2001 From: Saman Shirdel Date: Thu, 22 Oct 2026 14:30:39 +0330 Subject: [PATCH 09/10] Improve font removal command handling Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- bin/omarchy-font-remove | 302 +++++++++++++++++++------------ test/shell.d/font-remove-test.sh | 2 +- 2 files changed, 184 insertions(+), 120 deletions(-) diff --git a/bin/omarchy-font-remove b/bin/omarchy-font-remove index db45db26e6fd..b5bb91772f4e 100755 --- a/bin/omarchy-font-remove +++ b/bin/omarchy-font-remove @@ -8,16 +8,20 @@ # Usage: omarchy-font-remove [--list||--do ] # --list Print removable fonts as "familypackage" # no args Open the omarchy menu picker, then remove the chosen font -# Remove that font package (inline when a TTY is present, -# otherwise the uninstall is relaunched in a floating -# terminal, where sudo can prompt for a password) +# Remove that font package. Accepts a family or package name in +# any case; quotes are optional for multi-word names. Runs +# inline when a TTY is present, otherwise the uninstall is +# relaunched in a floating terminal, where sudo can prompt for +# a password. # --do Finish a pick from the menu context: run in the floating # terminal and uninstall the font package # -# Only fonts installed as packages under /usr/share/fonts are offered. The -# font currently in use (omarchy-font-current) is guarded and never offered, -# and emoji/signwriting/omarchy-icon fonts are excluded, same as the -# omarchy font list. +# Only fonts installed as packages under /usr/share/fonts are offered, and +# emoji/signwriting/omarchy-icon fonts are excluded, same as the omarchy font +# list. +# +# The font currently in use (omarchy-font-current) is guarded: --list hides it, +# the menu shows it marked "(active)", and asking to remove it is refused. # # Fonts that other installed packages still depend on (gsfonts <- evince and # graphviz, or the last provider of a virtual such as ttf-font) cannot be @@ -32,10 +36,19 @@ usage() { } CURRENT_FONT=$(omarchy-font-current 2>/dev/null | head -n1) -FONT_GLYPH=$(printf '\ue659') +# U+E659 as raw UTF-8 bytes, so it works regardless of the active locale. +FONT_GLYPH=$(printf '\xee\x99\x99') TAB=$'\t' COMMAND_MODE="" FAMILY_ARG="" +LOG_FILE="" + +cleanup() { + [[ -z $LOG_FILE ]] || rm -f -- "$LOG_FILE" +} +trap cleanup EXIT + +# ---- Messages --------------------------------------------------------------- # Translate a string via omarchy-i18n, falling back to built-in English when # the catalog has no entry (omarchy-i18n then echoes the raw key back, which is @@ -50,7 +63,7 @@ t() { fi case $key in font.removed) printf 'Font removed\n' ;; - font.removeSuccessBody) printf 'Font %s removed\n' "${1:-}" ;; + font.removeSuccessBody) printf '%s removed\n' "${1:-}" ;; font.removeFailed) printf 'Font removal failed\n' ;; font.removeFailedBody) printf "Couldn't remove %s: %s\n" "${1:-}" "${2:-}" ;; font.removeSeeTerminal) printf 'see the terminal for details\n' ;; @@ -58,80 +71,125 @@ t() { font.removeActive) printf '%s is the font currently in use\n' "${1:-}" ;; font.removeBlocked) printf "Font can't be removed\n" ;; font.removeBlockedBody) printf "%s can't be removed: %s\n" "${1:-}" "${2:-}" ;; + font.removeNone) printf 'Nothing to remove\n' ;; + font.removeNoneBody) printf 'No package-installed fonts found\n' ;; + font.removeNoneLeft) printf 'The remaining fonts are in use or needed by other packages\n' ;; + font.removeNotFound) printf 'Font not found\n' ;; + font.removeNotFoundBody) printf "%s is not among the removable fonts\n" "${1:-}" ;; font.removeSelect) printf 'Remove font\n' ;; font.active) printf 'active\n' ;; *) printf '%s\n' "$key" ;; esac } -if (( $# > 2 )); then - usage >&2 - exit 1 -fi +# notify [-u level] <body>; never fails the script. +notify() { + omarchy-notification-send -g "$FONT_GLYPH" "$@" || true +} + +# ---- Arguments -------------------------------------------------------------- case ${1:-} in --do) # Finish the picked font inside the floating terminal: sudo runs there. COMMAND_MODE=do - FAMILY_ARG=${2:-} + shift + FAMILY_ARG="$*" + if [[ -z $FAMILY_ARG ]]; then + usage >&2 + exit 1 + fi + ;; + --list) + if (( $# > 1 )); then + usage >&2 + exit 1 + fi + COMMAND_MODE=list ;; -h|--help) usage exit 0 ;; + -*) + echo "Unknown option: $1" >&2 + usage >&2 + exit 1 + ;; "") - FAMILY_ARG="" + COMMAND_MODE=menu ;; *) - FAMILY_ARG=$1 + # Unquoted multi-word names work too: omarchy-font-remove Fira Code + COMMAND_MODE=direct + FAMILY_ARG="$*" ;; esac -declare -A family_pkg=() # family -> owning package -declare -A pkg_label=() # package -> representative family +# Lower-case, trim, and keep only the first name of a comma-separated list, so +# the active-font check is not thrown off by case or aliases. Result in REPLY. +normalize_font() { + local f=${1%%,*} + f=${f,,} + f=${f#"${f%%[![:space:]]*}"} + f=${f%"${f##*[![:space:]]}"} + REPLY=$f +} + +normalize_font "$CURRENT_FONT" +CURRENT_NORM=$REPLY + +declare -A family_pkg=() # family -> owning package +declare -A pkg_label=() # package -> representative family +declare -A pkg_families=() # package -> number of families it provides +declare -A family_file=() # family -> one font file of that family +declare -A file_pkg=() # font file -> owning package +declare -A mono_family=() # families that are fixed-width +declare -A blocked=() # package -> reason it cannot be removed current_pkg="" -# ---- Collect family -> package ------------------------------------------- +# ---- Collect family -> package ---------------------------------------------- mapfile -t font_rows < <( - fc-list -f '%{family[0]}|%{file}\n' 2>/dev/null | + fc-list -f '%{family[0]}\t%{file}\n' 2>/dev/null | grep -v -i -E 'emoji|signwriting|omarchy' | sort -u ) # One file per family keeps the ownership lookup cheap. -declare -A family_file=() for row in "${font_rows[@]}"; do - family=${row%%|*} - file=${row#*|} + [[ $row == *"$TAB"* ]] || continue + family=${row%%${TAB}*} + file=${row#*${TAB}} + [[ -n $family && -n $file ]] || continue # Only package-managed system fonts; anything else (e.g. user fonts in # ~/.local/share/fonts) is not tracked by pacman and is skipped. - [[ -n $family && -n $file && $family != $row ]] || continue case $file in /usr/share/fonts/*) ;; *) continue ;; esac - family_file[$family]="${family_file[$family]:-$file}" + [[ -n ${family_file[$family]+x} ]] || family_file[$family]=$file done if (( ${#family_file[@]} > 0 )); then - # Single pacman -Ql pass gives every installed package's files; keep the - # font paths so each family's file can be attributed instantly and exactly. - mapfile -t owner_lines < <( - pacman -Ql 2>/dev/null | - awk '$2 ~ /^\/usr\/share\/fonts\// { print $2 "\t" $1 }' + # Single pacman -Ql pass, keeping only the files we care about. The path is + # everything after the first space, so file names containing spaces still + # resolve to their package. + while IFS=$'\t' read -r file pkg; do + [[ -n $file && -n $pkg ]] && file_pkg[$file]=$pkg + done < <( + awk ' + NR == FNR { want[$0] = 1; next } + { + i = index($0, " ") + if (i == 0) next + path = substr($0, i + 1) + if (path in want) print path "\t" substr($0, 1, i - 1) + } + ' <(printf '%s\n' "${family_file[@]}") <(LC_ALL=C pacman -Ql 2>/dev/null) ) - declare -A file_pkg=() - for line in "${owner_lines[@]}"; do - file=${line%%${TAB}*} - pkg=${line##*${TAB}} - [[ -n $file && -n $pkg ]] || continue - file_pkg[$file]=$pkg - done - # Families available as a monospace pick in `omarchy font list` get label # preference; otherwise the alphabetically first family of the package. # That list covers both fixed-width Fontconfig classes: spacing=100 (mono) # and spacing=90 (dual width, e.g. Iosevka Nerd Font, Lekton Nerd Font). - declare -A mono_family=() mapfile -t mono_rows < <( { fc-list :spacing=100 -f '%{family[0]}\n' @@ -150,19 +208,22 @@ if (( ${#family_file[@]} > 0 )); then ) for family in "${families[@]}"; do - pkg=${file_pkg[${family_file[$family]}]:-} + file=${family_file[$family]} + pkg=${file_pkg[$file]:-} case $pkg in ""|"omarchy"|"omarchy-"*|"noto-fonts-emoji") continue ;; esac family_pkg[$family]=$pkg - [[ $family == $CURRENT_FONT ]] && current_pkg=$pkg + pkg_families[$pkg]=$(( ${pkg_families[$pkg]:-0} + 1 )) + normalize_font "$family" + [[ -n $CURRENT_NORM && $REPLY == "$CURRENT_NORM" ]] && current_pkg=$pkg done # One label per package: the first alphabetical monospace family it # provides, else the first alphabetical family of any style. for family in "${families[@]}"; do pkg=${family_pkg[$family]:-} - [[ -z $pkg ]] && continue + [[ -n $pkg ]] || continue if [[ -n ${pkg_label[$pkg]+x} ]]; then # Prefer upgrading to a monospace family name over a plain label. if [[ -n ${mono_family[$family]+x} && -z ${mono_family[${pkg_label[$pkg]}]+x} ]]; then @@ -174,7 +235,7 @@ if (( ${#family_file[@]} > 0 )); then done fi -# ---- Find fonts that other installed packages still need ----------------- +# ---- Find fonts that other installed packages still need -------------------- # # pacman refuses to remove a package when something else depends on it, either # by name (evince -> gsfonts) or through a virtual provide (firefox -> @@ -182,7 +243,6 @@ fi # candidate, the installed packages whose dependency would be left without a # provider. A dependency that a second installed package also provides does # not block anything. -declare -A blocked=() # package -> reason it cannot be removed # Sorted, de-duplicated, comma-joined lines on stdin. join_lines() { @@ -279,39 +339,32 @@ for pkg in "${!pkg_label[@]}"; do label_pkg[${pkg_label[$pkg]}]=$pkg done -sorted_families=() -while IFS= read -r family; do - sorted_families+=("$family") -done < <(printf '%s\n' "${!label_pkg[@]}" | LC_ALL=C sort) +mapfile -t sorted_families < <(printf '%s\n' "${!label_pkg[@]}" | LC_ALL=C sort) -pick_family() { - # --do sets COMMAND_MODE itself; never clobber it. - [[ -n $COMMAND_MODE ]] && return - if [[ $FAMILY_ARG == "--list" ]]; then - COMMAND_MODE=list - elif [[ -z $FAMILY_ARG ]]; then - COMMAND_MODE=menu - else - COMMAND_MODE=direct - fi -} +# ---- Lookup ----------------------------------------------------------------- lookup_font() { # Resolve whatever the picker returns or the user passes — a font family, # a package name, or "family<TAB>package" in either order — into # "family<TAB>package". Every tab-separated piece is tried as a family or - # package name, exact match first, then case-insensitive. - local chosen=$1 lowered candidate family pkg - local -a parts=() - local rest=$chosen - while [[ $rest == *$TAB* ]]; do + # package name: exact matches first, then case-insensitive ones. + local chosen=$1 candidate lowered family pkg rest=$1 + local -a parts=() tries=() + + while [[ $rest == *"$TAB"* ]]; do parts+=("${rest%%${TAB}*}") rest=${rest#*${TAB}} done parts+=("$rest") - for candidate in ${parts[@]+"${parts[@]}"}; do - lowered=$(printf '%s' "$candidate" | tr '[:upper:]' '[:lower:]') + for candidate in "${parts[@]}"; do + [[ -n $candidate ]] || continue + tries+=("$candidate") + # The menu marks the active font "Family (active)"; also try without it. + [[ $candidate == *" ("*")" ]] && tries+=("${candidate% (*)}") + done + + for candidate in "${tries[@]}"; do if [[ -n ${family_pkg[$candidate]+x} ]]; then printf '%s\n' "$candidate${TAB}${family_pkg[$candidate]}" return 0 @@ -320,68 +373,76 @@ lookup_font() { printf '%s\n' "${pkg_label[$candidate]}${TAB}$candidate" return 0 fi - if [[ -n $lowered ]]; then - for family in "${!family_pkg[@]}"; do - if [[ $(printf '%s' "$family" | tr '[:upper:]' '[:lower:]') == "$lowered" ]]; then - printf '%s\n' "$family${TAB}${family_pkg[$family]}" - return 0 - fi - done - for pkg in "${!pkg_label[@]}"; do - if [[ $(printf '%s' "$pkg" | tr '[:upper:]' '[:lower:]') == "$lowered" ]]; then - printf '%s\n' "${pkg_label[$pkg]}${TAB}$pkg" - return 0 - fi - done - fi + done + + for candidate in "${tries[@]}"; do + lowered=${candidate,,} + for family in "${!family_pkg[@]}"; do + if [[ ${family,,} == "$lowered" ]]; then + printf '%s\n' "$family${TAB}${family_pkg[$family]}" + return 0 + fi + done + for pkg in "${!pkg_label[@]}"; do + if [[ ${pkg,,} == "$lowered" ]]; then + printf '%s\n' "${pkg_label[$pkg]}${TAB}$pkg" + return 0 + fi + done done return 1 } +# ---- Removal ---------------------------------------------------------------- + uninstall_font() { - local pkg=$1 label=$2 log status reason needed_by + local pkg=$1 label=$2 status reason needed_by count - echo "==> Removing font package: $pkg" - log=$(mktemp) - omarchy-pkg-drop "$pkg" 2>&1 | tee "$log" + count=${pkg_families[$pkg]:-1} + if (( count > 1 )); then + echo "==> Removing font package: $pkg ($count font families)" + else + echo "==> Removing font package: $pkg" + fi + + LOG_FILE=$(mktemp) + omarchy-pkg-drop "$pkg" 2>&1 | tee "$LOG_FILE" status=${PIPESTATUS[0]} if (( status != 0 )); then # pacman's own words: ":: removing <pkg> breaks dependency '<dep>' required by <other>" - needed_by=$(sed -n 's/.* required by //p' "$log" | join_lines) - if grep -q 'unable to lock database' "$log"; then + needed_by=$(sed -n 's/.* required by //p' "$LOG_FILE" | join_lines) + if grep -q 'unable to lock database' "$LOG_FILE"; then reason="pacman is busy (another install or update is running)" elif [[ -n $needed_by ]]; then reason="other packages depend on it (required by: $needed_by)" else - reason=$(sed -n 's/^error: //p' "$log" | head -n1) + reason=$(sed -n 's/^error: //p' "$LOG_FILE" | head -n1) fi - rm -f -- "$log" echo "==> Failed to remove $pkg${reason:+: $reason}" - omarchy-notification-send -g "$FONT_GLYPH" \ + notify \ "$(t font.removeFailed)" \ - "$(t font.removeFailedBody "$label" "${reason:-$(t font.removeSeeTerminal)}")" || true + "$(t font.removeFailedBody "$label" "${reason:-$(t font.removeSeeTerminal)}")" exit 1 fi - rm -f -- "$log" fc-cache -f >/dev/null 2>&1 - omarchy-notification-send -g "$FONT_GLYPH" -u normal \ + notify -u normal \ "$(t font.removed)" \ - "$(t font.removeSuccessBody "$label")" || true + "$(t font.removeSuccessBody "$label")" echo "==> Removed $label." echo " Running apps may need a restart to drop the old font." } remove_font() { - local pkg=$1 label=$2 reason + local pkg=$1 label=$2 reason quoted_label if [[ -n $current_pkg && $pkg == "$current_pkg" ]]; then echo "==> '$label' is the font currently in use." echo " Set a different font first (Settings → Font), then remove it." - omarchy-notification-send -g "$FONT_GLYPH" \ + notify \ "$(t font.removeSkipped)" \ - "$(t font.removeActive "$label")" || true + "$(t font.removeActive "$label")" exit 1 fi @@ -392,9 +453,9 @@ remove_font() { reason=${blocked[$pkg]} echo "==> Can't remove '$label' ($pkg): $reason." echo " Remove or replace whatever depends on it first, or keep the font." - omarchy-notification-send -g "$FONT_GLYPH" \ + notify \ "$(t font.removeBlocked)" \ - "$(t font.removeBlockedBody "$label" "$reason")" || true + "$(t font.removeBlockedBody "$label" "$reason")" exit 1 fi @@ -409,14 +470,23 @@ remove_font() { fi } -pick_family +# Report a lookup miss where the user can actually see it, even when the +# script was launched detached from the menu. +not_found() { + echo "Font '$1' was not found among removable fonts." + echo "Removable fonts can be listed with: omarchy-font-remove --list" + notify "$(t font.removeNotFound)" "$(t font.removeNotFoundBody "$1")" + exit 1 +} + +# ---- Main ------------------------------------------------------------------- case $COMMAND_MODE in list) - for family in ${sorted_families[@]+"${sorted_families[@]}"}; do + for family in "${sorted_families[@]}"; do pkg=${label_pkg[$family]} # The active font package cannot be removed, so don't advertise it. - [[ -n $current_pkg && $pkg == $current_pkg ]] && continue + [[ -n $current_pkg && $pkg == "$current_pkg" ]] && continue # Fonts other packages still need can't be removed; don't list them. [[ -n ${blocked[$pkg]+x} ]] && continue printf '%s\n' "$family${TAB}$pkg" @@ -426,16 +496,18 @@ case $COMMAND_MODE in menu) if (( ${#pkg_label[@]} == 0 )); then echo "No package-installed fonts found to remove." + notify "$(t font.removeNone)" "$(t font.removeNoneBody)" exit 0 fi + active_label=$(t font.active) options=() - for family in ${sorted_families[@]+"${sorted_families[@]}"}; do + for family in "${sorted_families[@]}"; do pkg=${label_pkg[$family]} # Nor are fonts that other installed packages still depend on. [[ -n ${blocked[$pkg]+x} ]] && continue - if [[ -n $current_pkg && $pkg == $current_pkg ]]; then - options+=("$FONT_GLYPH${TAB}${family} ($(t font.active))${TAB}${pkg}") + if [[ -n $current_pkg && $pkg == "$current_pkg" ]]; then + options+=("$FONT_GLYPH${TAB}${family} ($active_label)${TAB}${pkg}") else options+=("$FONT_GLYPH${TAB}${family}${TAB}${pkg}") fi @@ -443,35 +515,27 @@ case $COMMAND_MODE in if (( ${#options[@]} == 0 )); then echo "Nothing to remove: the remaining fonts are in use or needed by other packages." + notify "$(t font.removeNone)" "$(t font.removeNoneLeft)" exit 0 fi chosen=$(omarchy-menu-select "$(t font.removeSelect)" "${options[@]}" -- --width 520 --maxheight 520) || exit 0 + [[ -n $chosen ]] || exit 0 if resolved=$(lookup_font "$chosen"); then - label=${resolved%%${TAB}*} - pkg=${resolved##*${TAB}} - remove_font "$pkg" "$label" + remove_font "${resolved##*${TAB}}" "${resolved%%${TAB}*}" exit 0 fi echo "Selection '$chosen' could not be resolved to an installed font package." + notify "$(t font.removeNotFound)" "$(t font.removeNotFoundBody "${chosen//$TAB/ }")" exit 1 ;; esac -# Direct lookup (a family name or a package name, exact or case-insensitive). -if [[ -z $FAMILY_ARG ]]; then - exit 0 -fi - +# direct / do: a family name or a package name, exact or case-insensitive. if resolved=$(lookup_font "$FAMILY_ARG"); then - label=${resolved%%${TAB}*} - pkg=${resolved##*${TAB}} + remove_font "${resolved##*${TAB}}" "${resolved%%${TAB}*}" else - echo "Font '$FAMILY_ARG' was not found among removable fonts." - echo "Removable fonts can be listed with: omarchy-font-remove --list" - exit 1 + not_found "$FAMILY_ARG" fi - -remove_font "$pkg" "$label" diff --git a/test/shell.d/font-remove-test.sh b/test/shell.d/font-remove-test.sh index 6f67f062c098..9ac224b237bc 100644 --- a/test/shell.d/font-remove-test.sh +++ b/test/shell.d/font-remove-test.sh @@ -13,7 +13,7 @@ mkdir -p "$mock_bin" cat >"$mock_bin/fc-list" <<'SH' #!/bin/bash if [[ $1 == "-f" ]]; then - printf '%s\n' 'Liberation Mono|/usr/share/fonts/TTF/liberation.ttf' + printf '%s\t%s\n' 'Liberation Mono' '/usr/share/fonts/TTF/liberation.ttf' fi SH From 54a92340deccfe70820fef9fe8a0a4bc3ba41dc6 Mon Sep 17 00:00:00 2001 From: Saman Shirdel <ssh.workmaill@gmail.com> Date: Thu, 22 Oct 2026 14:33:28 +0330 Subject: [PATCH 10/10] Rename font removal menu entry Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- default/i18n/en/menu.json | 2 +- default/omarchy/omarchy-menu.jsonc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/default/i18n/en/menu.json b/default/i18n/en/menu.json index b295852896f5..ad14827cf1df 100644 --- a/default/i18n/en/menu.json +++ b/default/i18n/en/menu.json @@ -986,7 +986,7 @@ "label": "Web App" }, "remove.font": { - "label": "Fonts", + "label": "Font", "description": "Remove an installed font package" }, "remove.tui": { diff --git a/default/omarchy/omarchy-menu.jsonc b/default/omarchy/omarchy-menu.jsonc index 446a1c2c13f5..444025e26d63 100644 --- a/default/omarchy/omarchy-menu.jsonc +++ b/default/omarchy/omarchy-menu.jsonc @@ -362,7 +362,7 @@ "remove.tui": {"icon":"","label":"TUI","when":"grep -qE '^Exec=.*(\\$TERMINAL|xdg-terminal-exec).*-e' $HOME/.local/share/applications/*.desktop","action":"omarchy-tui-remove"}, "remove.windows": {"icon":"󰍲","label":"Windows","when":"[[ -f $HOME/.local/share/applications/windows-vm.desktop ]]","action":"omarchy-launch-floating-terminal-with-presentation 'omarchy-windows-vm remove'"}, "remove.preinstalls": {"icon":"󰏓","label":"Preinstalls","when":"[[ ! -f $HOME/.local/state/omarchy/preinstalls-removed ]]","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-preinstalls"}, - "remove.font": {"icon":"","label":"Fonts","description":"Remove an installed font package","action":"omarchy-font-remove"}, + "remove.font": {"icon":"","label":"Font","description":"Remove an installed font package","action":"omarchy-font-remove"}, "remove.security": {"icon":"","label":"Security","title":"Remove"}, "remove.security.fingerprint": {"icon":"󰈷","label":"Fingerprint","when":"omarchy-pkg-present fprintd","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-security-fingerprint"}, "remove.security.fido2": {"icon":"","label":"Fido2","when":"omarchy-pkg-present pam-u2f","action":"omarchy-launch-floating-terminal-with-presentation omarchy-remove-security-fido2"},