Repository navigation
feat: add omarchy font size for the terminal
#20232
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
Open
ekollof
wants to merge
3
commits into
omacom:quattro
Choose a base branch
from
ekollof:feature/font-size
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Show or set the terminal font size | ||
| # omarchy:args=[size|reset] | ||
| # omarchy:examples=omarchy font size | omarchy font size 12 | omarchy font size reset | ||
|
|
||
| # Sets the font point size in every terminal config Omarchy manages: Alacritty, | ||
| # Ghostty, Kitty and Foot. The font family is omarchy-font-set's job, and | ||
| # omarchy-display-text-size calls this to keep terminals in proportion with the | ||
| # shell and GTK, so a size set here lasts until the next desktop text size change. | ||
| # Accepts an integer from 6 to 24 (pt). | ||
|
|
||
| MIN=6 | ||
| MAX=24 | ||
| DEFAULT_PT=9 | ||
|
|
||
| usage() { | ||
| echo "Usage: omarchy-font-size [size|reset]" | ||
| echo " (no args) print the current terminal font size in pt" | ||
| echo " <size> set the terminal font size in pt ($MIN–$MAX)" | ||
| echo " reset return terminals to the default ${DEFAULT_PT}pt" | ||
| } | ||
|
|
||
| # Set the font point size in terminal configs, creating Kitty overrides when | ||
| # it inherits its size from the system config. Live-reload signals mirror | ||
| # omarchy-font-set; foot has no reload signal, so running instances are nudged. | ||
| set_terminal_size() { | ||
| local pt="$1" | ||
|
|
||
| if [[ -f ~/.config/alacritty/alacritty.toml ]]; then | ||
| sed --follow-symlinks -i -E "s/^[[:space:]]*size[[:space:]]*=.*/size = $pt/" ~/.config/alacritty/alacritty.toml | ||
| fi | ||
|
|
||
| if [[ -f ~/.config/kitty/kitty.conf ]] || omarchy-cmd-present kitty; then | ||
| mkdir -p ~/.config/kitty | ||
| if grep -qE '^[[:space:]]*font_size[[:space:]]+' ~/.config/kitty/kitty.conf 2>/dev/null; then | ||
| sed --follow-symlinks -i -E "s/^[[:space:]]*font_size[[:space:]]+.*/font_size $pt.0/" ~/.config/kitty/kitty.conf | ||
| else | ||
| printf '\nfont_size %s.0\n' "$pt" >>~/.config/kitty/kitty.conf | ||
| fi | ||
| pkill -USR1 kitty 2>/dev/null || true | ||
| fi | ||
|
|
||
| if [[ -f ~/.config/ghostty/config ]]; then | ||
| sed --follow-symlinks -i -E "s/^[[:space:]]*font-size[[:space:]]*=.*/font-size = $pt/" ~/.config/ghostty/config | ||
| pkill -SIGUSR2 ghostty 2>/dev/null || true | ||
| fi | ||
|
|
||
| if [[ -f ~/.config/foot/foot.ini ]]; then | ||
| # Foot keeps fallback fonts after the primary on the same line; change only | ||
| # the primary font's size, not a fallback's. | ||
| sed --follow-symlinks -i -E "/^font=/ s/(:size=)[0-9.]+/\1$pt/" ~/.config/foot/foot.ini | ||
| # Foot has no config-reload signal, so a running instance keeps its startup | ||
| # size until relaunched (new windows pick up the change). Nudge the user — | ||
| # but reuse the same notification id (freedesktop replaces_id) so dragging | ||
| # through several sizes refreshes one toast instead of stacking a pile. | ||
| if pgrep -x foot >/dev/null 2>&1; then | ||
| local id_file="${XDG_RUNTIME_DIR:-/tmp}/omarchy-font-size.foot-notif-id" | ||
| local prev_id="" | ||
| [[ -f $id_file ]] && read -r prev_id <"$id_file" 2>/dev/null | ||
| local replace=() | ||
| [[ $prev_id =~ ^[0-9]+$ ]] && replace=(-r "$prev_id") | ||
| local new_id | ||
| new_id="$(omarchy-notification-send \ | ||
| "$(omarchy-i18n display.restartFootForFontSize)" \ | ||
| "${replace[@]}" -p 2>/dev/null)" || true | ||
| [[ $new_id =~ ^[0-9]+$ ]] && printf '%s\n' "$new_id" >"$id_file" | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| # Print the current terminal point size from whichever config we find first. | ||
| current_size() { | ||
| if [[ -f ~/.config/ghostty/config ]]; then | ||
| grep -oP '^[[:space:]]*font-size[[:space:]]*=[[:space:]]*\K[0-9.]+' ~/.config/ghostty/config | head -1 | ||
| elif [[ -f ~/.config/alacritty/alacritty.toml ]]; then | ||
| grep -oP '^[[:space:]]*size[[:space:]]*=[[:space:]]*\K[0-9.]+' ~/.config/alacritty/alacritty.toml | head -1 | ||
| elif [[ -f ~/.config/kitty/kitty.conf ]]; then | ||
| local pt | ||
| pt=$(grep -oP '^[[:space:]]*font_size[[:space:]]+\K[0-9.]+' ~/.config/kitty/kitty.conf | tail -1) | ||
| echo "${pt:-$DEFAULT_PT}" | ||
| elif [[ -f ~/.config/foot/foot.ini ]]; then | ||
| grep -oP ':size=\K[0-9.]+' ~/.config/foot/foot.ini | head -1 | ||
| elif omarchy-cmd-present kitty; then | ||
| echo "$DEFAULT_PT" | ||
| fi | ||
| } | ||
|
|
||
| case "${1:-}" in | ||
| -h | --help) | ||
| usage | ||
| ;; | ||
| "") | ||
| current_size | ||
| ;; | ||
| reset | default) | ||
| set_terminal_size "$DEFAULT_PT" | ||
| ;; | ||
| *) | ||
| if [[ $1 =~ ^[0-9]+$ ]] && ((10#$1 >= MIN && 10#$1 <= MAX)); then | ||
| set_terminal_size "$((10#$1))" | ||
| else | ||
| echo "Size must be an integer between $MIN and $MAX (pt)." >&2 | ||
| usage >&2 | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| esac | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| test_dir=$(mktemp -d) | ||
| trap 'rm -rf "$test_dir"' EXIT | ||
| test_home="$test_dir/home" | ||
| stubs="$test_dir/bin" | ||
| calls="$test_dir/calls.log" | ||
| mkdir -p "$stubs" "$test_home/.config"/{alacritty,ghostty,kitty,foot} | ||
|
|
||
| cp "$ROOT/config/alacritty/alacritty.toml" "$test_home/.config/alacritty/alacritty.toml" | ||
| cp "$ROOT/config/ghostty/config" "$test_home/.config/ghostty/config" | ||
| cp "$ROOT/config/kitty/kitty.conf" "$test_home/.config/kitty/kitty.conf" | ||
| cp "$ROOT/config/foot/foot.ini" "$test_home/.config/foot/foot.ini" | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| # Nothing may signal or notify the real session. pgrep reports no running | ||
| # terminals; fc-list knows one font, for omarchy-font-set. | ||
| for name in pkill gsettings omarchy-notification-send omarchy-restart-shell omarchy-hook; do | ||
| printf '#!/bin/bash\nprintf "%s %%s\\n" "$*" >>"%s"\n' "$name" "$calls" >"$stubs/$name" | ||
| done | ||
| printf '#!/bin/bash\nexit 1\n' >"$stubs/pgrep" | ||
| printf '#!/bin/bash\necho "/usr/share/fonts/Test.ttf: Test Mono:style=Regular"\n' >"$stubs/fc-list" | ||
| chmod +x "$stubs"/* | ||
|
|
||
| run() { | ||
| env HOME="$test_home" OMARCHY_PATH="$ROOT" XDG_RUNTIME_DIR="$test_dir" PATH="$stubs:$ROOT/bin:$PATH" "$@" | ||
| } | ||
|
|
||
| sizes() { | ||
| printf '%s|%s|%s|%s' \ | ||
| "$(grep -oP '^size = \K.*' "$test_home/.config/alacritty/alacritty.toml")" \ | ||
| "$(grep -oP '^font-size = \K.*' "$test_home/.config/ghostty/config")" \ | ||
| "$(grep -oP '^font_size \K.*' "$test_home/.config/kitty/kitty.conf" | tail -1)" \ | ||
| "$(grep -oP ':size=\K[0-9.]+' "$test_home/.config/foot/foot.ini")" | ||
| } | ||
|
|
||
| [[ $(run omarchy font size) == "9" ]] || fail "reports the stock terminal size" "$(run omarchy font size)" | ||
| pass "reports the stock terminal size" | ||
|
|
||
| run omarchy font size 12 | ||
| [[ $(sizes) == "12|12|12.0|12" ]] || fail "sets every terminal's size" "$(sizes)" | ||
| [[ $(run omarchy font size) == "12" ]] || fail "reads back the new size" | ||
| grep -q 'font-family = "JetBrainsMono Nerd Font"' "$test_home/.config/ghostty/config" || fail "leaves the font family alone" | ||
| grep -q '^font=JetBrainsMono Nerd Font:size=12' "$test_home/.config/foot/foot.ini" || fail "leaves Foot's font family alone" | ||
| grep -q '^pkill -SIGUSR2 ghostty' "$calls" || fail "reloads Ghostty" | ||
| grep -q '^pkill -USR1 kitty' "$calls" || fail "reloads Kitty" | ||
| ! grep -q '^gsettings' "$calls" || fail "leaves GTK text scaling alone" | ||
| [[ ! -e $test_home/.config/omarchy/shell.toml ]] || fail "leaves the shell text size alone" | ||
| pass "sets only the terminal size, in every terminal" | ||
|
|
||
| run omarchy font size 08 | ||
| [[ $(sizes) == "8|8|8.0|8" ]] || fail "reads a leading zero as decimal" "$(sizes)" | ||
| pass "reads a leading zero as decimal" | ||
|
|
||
| for bad in 5 25 abc 1.5; do | ||
| if run omarchy font size "$bad" 2>/dev/null; then | ||
| fail "rejects $bad" | ||
| fi | ||
| done | ||
| [[ $(sizes) == "8|8|8.0|8" ]] || fail "a rejected size changes nothing" "$(sizes)" | ||
| pass "rejects sizes outside 6–24 and non-integers" | ||
|
|
||
| run omarchy font size reset | ||
| [[ $(sizes) == "9|9|9.0|9" ]] || fail "reset returns to 9pt" "$(sizes)" | ||
| pass "reset returns to 9pt" | ||
|
|
||
| : >"$calls" | ||
| run omarchy display text size 16 | ||
| [[ $(sizes) == "12|12|12.0|12" ]] || fail "desktop text size keeps terminals in proportion" "$(sizes)" | ||
| grep -q '^gsettings set org.gnome.desktop.interface text-scaling-factor' "$calls" || fail "desktop text size still scales GTK" | ||
| grep -q '^base-size = 16' "$test_home/.config/omarchy/shell.toml" || fail "desktop text size still scales the shell" | ||
| [[ $(run omarchy display text size) == *"terminal font: 12 pt"* ]] || fail "desktop text size reports the terminal size" | ||
| pass "desktop text size sets terminals through omarchy-font-size" | ||
|
|
||
| run omarchy font size 14 | ||
| run omarchy font set "Test Mono" | ||
| grep -q '^font=Test Mono:size=14' "$test_home/.config/foot/foot.ini" || fail "changing the font keeps Foot's size" "$(grep '^font=' "$test_home/.config/foot/foot.ini")" | ||
| pass "changing the font keeps Foot's size" | ||
|
|
||
| # Terminal configs can be symlinked from dotfiles. The size must be written | ||
| # through the link, not replace it. | ||
| mkdir -p "$test_home/dotfiles" | ||
| for pair in "alacritty/alacritty.toml alacritty.toml" \ | ||
| "ghostty/config ghostty.conf" \ | ||
| "kitty/kitty.conf kitty.conf" \ | ||
| "foot/foot.ini foot.ini"; do | ||
| read -r source_rel target_rel <<<"$pair" | ||
| source_file="$test_home/.config/$source_rel" | ||
| target_file="$test_home/dotfiles/$target_rel" | ||
| mv "$source_file" "$target_file" | ||
| ln -s "$target_file" "$source_file" | ||
| done | ||
|
|
||
| run omarchy font size 13 | ||
| [[ $(sizes) == "13|13|13.0|13" ]] || fail "writes the size through symlinked configs" "$(sizes)" | ||
| for link in alacritty/alacritty.toml ghostty/config kitty/kitty.conf foot/foot.ini; do | ||
| [[ -L $test_home/.config/$link ]] || fail "keeps $link a symlink" | ||
| done | ||
| pass "writes through symlinked terminal configs" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.