-
-
Notifications
You must be signed in to change notification settings - Fork 85
Display Apple symbols in keybinding menus #307
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 all commits
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 |
|---|---|---|
|
|
@@ -575,8 +575,39 @@ output_binding_records() { | |
| fi | ||
| } | ||
|
|
||
| format_display_records() { | ||
| awk -F '\t' ' | ||
| BEGIN { OFS = "\t" } | ||
| { | ||
| delimiter = index($1, "→") | ||
| display = substr($1, 1, delimiter - 1) | ||
| sub(/[[:space:]]+$/, "", display) | ||
|
|
||
| count = split(display, parts, /[[:space:]]+/) | ||
| display = "" | ||
| for (i = 1; i <= count; i++) { | ||
| if (parts[i] == "SUPER") parts[i] = "⌘" | ||
|
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. bug: this runs for everyone. Please wrap the symbol mapping so it only applies when |
||
| else if (parts[i] == "ALT") parts[i] = "⌥" | ||
| else if (parts[i] == "CTRL" || parts[i] == "CONTROL") parts[i] = "⌃" | ||
| else if (parts[i] == "SHIFT") parts[i] = "⇧" | ||
|
|
||
| display = display (display == "" ? "" : " ") parts[i] | ||
| } | ||
|
|
||
| action = substr($1, delimiter + length("→")) | ||
| sub(/^[[:space:]]+/, "", action) | ||
| measured = display | ||
| gsub(/⌘|⌥|⌃|⇧/, "x", measured) | ||
| padding = 35 - length(measured) | ||
| if (padding > 0) display = display sprintf("%*s", padding, "") | ||
|
|
||
| $1 = display " → " action | ||
| }' | ||
| } | ||
|
|
||
| output_keybindings() { | ||
| output_binding_records | cut -f1 | ||
| output_binding_records | format_display_records | cut -f1 | ||
| } | ||
|
|
||
| trim() { | ||
|
|
@@ -661,7 +692,7 @@ dispatch_binding() { | |
| if [[ $1 == "--print" || $1 == "-p" ]]; then | ||
| output_keybindings | ||
| else | ||
| records=$(output_binding_records) | ||
| records=$(output_binding_records | format_display_records) | ||
| selection=$(cut -f1 <<<"$records" | | ||
| omarchy-menu-select 'Keybindings' -- --width 800 --height 500) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,12 +53,12 @@ output_keybindings() ( | |
| function key_part_text(part, is_modifier, part_count) { | ||
| gsub(/^\\/, "", part) | ||
|
|
||
| if (is_modifier && part == "C") return "CTRL" | ||
| if (is_modifier && part == "M") return "ALT" | ||
| if (is_modifier && part == "S") return "SHIFT" | ||
| if (is_modifier && part == "C") return "⌃" | ||
|
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. Same gate needed here: the tmux menu should only switch to ⌃/⌥/⇧ on Apple hardware. |
||
| if (is_modifier && part == "M") return "⌥" | ||
| if (is_modifier && part == "S") return "⇧" | ||
| if (part == "Space") return "SPACE" | ||
| if (part == "BSpace") return "BACKSPACE" | ||
| if (part == "BTab") return "SHIFT + TAB" | ||
| if (part == "BTab") return "⇧ + TAB" | ||
| if (part == "PPage") return "PAGE UP" | ||
| if (part == "NPage") return "PAGE DOWN" | ||
| if (part == "DC") return "DELETE" | ||
|
|
@@ -90,6 +90,14 @@ function table_text(table) { | |
| return toupper(table) | ||
| } | ||
|
|
||
| function padded(text, width, measured) { | ||
| measured = text | ||
| gsub(/⌘|⌥|⌃|⇧/, "x", measured) | ||
| if (length(measured) >= width) return text | ||
|
|
||
| return text sprintf("%*s", width - length(measured), "") | ||
| } | ||
|
|
||
| $1 == "prefix" && NF == 2 { prefix = $2; next } | ||
| $1 == "prefix2" && NF == 2 { prefix2 = $2; next } | ||
|
|
||
|
|
@@ -101,7 +109,7 @@ $1 == "prefix2" && NF == 2 { prefix2 = $2; next } | |
| prefix_description = prefix_description " / " key_text(prefix2) | ||
| } | ||
|
|
||
| printf "%-32s → %s\n", "PREFIX", prefix_description | ||
| printf "%s → %s\n", padded("PREFIX", 32), prefix_description | ||
| header_printed = 1 | ||
| } | ||
|
|
||
|
|
@@ -116,7 +124,7 @@ $1 == "prefix2" && NF == 2 { prefix2 = $2; next } | |
| combo = table_text(table) " + " key_text(key) | ||
| } | ||
|
|
||
| printf "%-32s → %s\n", combo, note | ||
| printf "%s → %s\n", padded(combo, 32), note | ||
| }' | ||
| ) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/bin/bash | ||
|
|
||
| source "$(dirname "${BASH_SOURCE[0]}")/base-test.sh" | ||
|
|
||
| tmpdir=$(mktemp -d) && [[ -n $tmpdir && -d $tmpdir ]] || | ||
| fail "the test gets a temporary directory for keybinding command stubs" | ||
| trap 'rm -rf "$tmpdir"' EXIT | ||
|
|
||
| stub_bin="$tmpdir/bin" | ||
| mkdir -p "$stub_bin" | ||
|
|
||
| cat >"$stub_bin/tmux" <<'TMUX' | ||
| #!/bin/bash | ||
| cat <<'OUTPUT' | ||
| prefix C-a | ||
| prefix2 M-b | ||
| prefix C-S-x Example binding | ||
| root M-y Root binding | ||
| copy-mode-vi C-z Copy binding | ||
| copy-mode-vi BTab Reverse selection | ||
| OUTPUT | ||
| TMUX | ||
| chmod +x "$stub_bin/tmux" | ||
|
|
||
| touch "$tmpdir/tmux.conf" | ||
| tmux_output=$(PATH="$stub_bin:$PATH" OMARCHY_PATH="$ROOT" \ | ||
| "$ROOT/bin/omarchy-menu-tmux-keybindings" --print --config "$tmpdir/tmux.conf") | ||
|
|
||
| grep -q '^PREFIX *→ ⌃ + A / ⌥ + B$' <<<"$tmux_output" || | ||
| fail "Tmux prefix modifiers use Apple symbols" "$tmux_output" | ||
| grep -qF 'PREFIX + ⌃ + ⇧ + X' <<<"$tmux_output" || | ||
| fail "Tmux binding modifiers use Apple symbols" "$tmux_output" | ||
| grep -qF '⌥ + Y' <<<"$tmux_output" || | ||
| fail "Tmux root modifiers use Apple symbols" "$tmux_output" | ||
| grep -qF 'COPY MODE + ⇧ + TAB' <<<"$tmux_output" || | ||
| fail "Tmux BTab uses the Apple Shift symbol" "$tmux_output" | ||
| pass "Tmux keybindings use Apple modifier symbols" | ||
|
|
||
| cat >"$stub_bin/herdr" <<'HERDR' | ||
| #!/bin/bash | ||
| cat <<'OUTPUT' | ||
| #[keys] | ||
| # prefix = "control+a" | ||
| # navigate_left = "super+alt+shift+h" | ||
| # close = "ctrl+w" | ||
| # toggle = ["super+control+shift+alt+a", "super+control+shift+alt+b", "super+control+shift+alt+c", "super+control+shift+alt+d"] | ||
| OUTPUT | ||
| HERDR | ||
| chmod +x "$stub_bin/herdr" | ||
|
|
||
| herdr_output=$(PATH="$stub_bin:$PATH" \ | ||
| "$ROOT/bin/omarchy-menu-herdr-keybindings" --print --config /dev/null) | ||
|
|
||
| grep -q '^PREFIX *→ ⌃ + A$' <<<"$herdr_output" || | ||
| fail "Herdr prefix modifiers use Apple symbols" "$herdr_output" | ||
| grep -qF 'NAVIGATE + ⌘ + ⌥ + ⇧ + H' <<<"$herdr_output" || | ||
| fail "Herdr navigation modifiers use Apple symbols" "$herdr_output" | ||
| grep -qF '⌃ + W' <<<"$herdr_output" || | ||
| fail "Herdr CTRL aliases use the Control symbol" "$herdr_output" | ||
| grep -qF '⌘ + ⌃ + ⇧ + ⌥ + A / ⌘ + ⌃ + ⇧ + ⌥ + B / ⌘ + ⌃ + ⇧ + ⌥ + C / ⌘ + ⌃ + ⇧ + ⌥ + D → Toggle' <<<"$herdr_output" || | ||
| fail "Herdr chords longer than the display column are not padded backwards" "$herdr_output" | ||
| pass "Herdr keybindings use Apple modifier symbols" |
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.
nit:
partis not in the parameter list, so awk makes it a global. The rest of this file declares locals as trailing parameters (key_text(key, count, parts, i, text)), sopartbelongs there too.