Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions bin/omarchy-display-text-size
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,25 @@ set_terminal_size() {
fi
}

# Report the current terminal point size from whichever config we find first.
# Report the current point size of the default terminal. Every terminal's
# config ships on install, so finding one says nothing about what is in use.
term_current_pt() {
if [[ -f ~/.config/ghostty/config ]]; then
grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config | head -1
elif [[ -f ~/.config/alacritty/alacritty.toml ]]; then
grep -oP '^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:-$TERM_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 "$TERM_DEFAULT_PT"
fi
case "$(omarchy-default-terminal)" in
alacritty)
grep -oP '^size[[:space:]]*=[[:space:]]*\K[0-9.]+' ~/.config/alacritty/alacritty.toml 2>/dev/null | head -1
;;
foot)
grep -oP ':size=\K[0-9.]+' ~/.config/foot/foot.ini 2>/dev/null | head -1
;;
ghostty)
grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config 2>/dev/null | head -1
;;
kitty)
local pt
pt=$(grep -oP '^[[:space:]]*font_size[[:space:]]+\K[0-9.]+' ~/.config/kitty/kitty.conf 2>/dev/null | tail -1)
echo "${pt:-$TERM_DEFAULT_PT}"
;;
esac
}

case "${1:-}" in
Expand Down
37 changes: 37 additions & 0 deletions test/shell.d/display-text-size-terminal-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/base-test.sh"

test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT
test_home="$test_dir/home"
mkdir -p "$test_home/.config" "$test_dir/bin"

# Every terminal's stock config is present, as on an ISO install, each with a
# different size so the report shows which one it read.
for terminal in alacritty foot ghostty kitty; do
cp -r "$ROOT/config/$terminal" "$test_home/.config/"
done
sed -i -E 's/^size = .*/size = 10/' "$test_home/.config/alacritty/alacritty.toml"
sed -i -E 's/(:size=)[0-9.]+/\19.5/' "$test_home/.config/foot/foot.ini"
sed -i -E 's/^font-size = .*/font-size = 11/' "$test_home/.config/ghostty/config"
printf 'font_size 13\n' >>"$test_home/.config/kitty/kitty.conf"

printf '#!/bin/bash\necho 1.0\n' >"$test_dir/bin/gsettings"
cat >"$test_dir/bin/xdg-terminal-exec" <<'SH'
#!/bin/bash
[[ $1 == "--print-id" ]] && echo "$TEST_TERMINAL_ID"
SH
chmod +x "$test_dir/bin/"*

reported_pt() {
env HOME="$test_home" OMARCHY_PATH="$ROOT" PATH="$test_dir/bin:$ROOT/bin:$PATH" TEST_TERMINAL_ID="$1" \
"$ROOT/bin/omarchy-display-text-size" | sed -n 's/^terminal font: \(.*\) pt$/\1/p'
}

[[ $(reported_pt Alacritty.desktop) == "10" ]] || fail "reports the Alacritty size when Alacritty is the default"
[[ $(reported_pt foot.desktop) == "9.5" ]] || fail "reports the Foot size when Foot is the default"
[[ $(reported_pt com.mitchellh.ghostty.desktop) == "11" ]] || fail "reports the Ghostty size when Ghostty is the default"
[[ $(reported_pt kitty.desktop) == "13" ]] || fail "reports the Kitty size when Kitty is the default"
pass "size report reads the default terminal's config, not the first one found"
1 change: 1 addition & 0 deletions test/shell.d/kitty-config-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ done
printf '#!/bin/bash\nexit 1\n' >"$test_dir/bin/pgrep"
printf '#!/bin/bash\nprintf "Test Font\\n"\n' >"$test_dir/bin/fc-list"
printf '#!/bin/bash\nexit 0\n' >"$test_dir/bin/kitty"
printf '#!/bin/bash\necho kitty.desktop\n' >"$test_dir/bin/xdg-terminal-exec"
cat >"$test_dir/bin/gsettings" <<'SH'
#!/bin/bash
if [[ $1 == "get" ]]; then
Expand Down