Skip to content
24 changes: 15 additions & 9 deletions bin/omarchy-display-text-size
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,27 @@ set_terminal_size() {
fi
}

# Report the current terminal point size from whichever config we find first.
# Report the current point size from the terminal xdg-terminal-exec selects.
term_current_pt() {
if [[ -f ~/.config/ghostty/config ]]; then
case "$(omarchy-default-terminal)" in
ghostty)
[[ -f ~/.config/ghostty/config ]] || return 0
grep -oP '^font-size = \K[0-9.]+' ~/.config/ghostty/config | head -1
elif [[ -f ~/.config/alacritty/alacritty.toml ]]; then
;;
alacritty)
[[ -f ~/.config/alacritty/alacritty.toml ]] || return 0
grep -oP '^size[[:space:]]*=[[:space:]]*\K[0-9.]+' ~/.config/alacritty/alacritty.toml | head -1
elif [[ -f ~/.config/kitty/kitty.conf ]]; then
;;
kitty)
local pt
pt=$(grep -oP '^[[:space:]]*font_size[[:space:]]+\K[0-9.]+' ~/.config/kitty/kitty.conf | tail -1)
pt=$(grep -oP '^[[:space:]]*font_size[[:space:]]+\K[0-9.]+' ~/.config/kitty/kitty.conf 2>/dev/null | tail -1)
echo "${pt:-$TERM_DEFAULT_PT}"
elif [[ -f ~/.config/foot/foot.ini ]]; then
;;
foot)
[[ -f ~/.config/foot/foot.ini ]] || return 0
grep -oP ':size=\K[0-9.]+' ~/.config/foot/foot.ini | head -1
elif omarchy-cmd-present kitty; then
echo "$TERM_DEFAULT_PT"
fi
;;
esac
}

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

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

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

home="$tmpdir/home"
stub_bin="$tmpdir/bin"
mkdir -p "$home/.config/ghostty" "$home/.config/alacritty" \
"$home/.config/kitty" "$home/.config/foot" "$stub_bin"

cat >"$home/.config/ghostty/config" <<'EOF'
font-size = 11
EOF
cat >"$home/.config/alacritty/alacritty.toml" <<'EOF'
size = 12
EOF
cat >"$home/.config/kitty/kitty.conf" <<'EOF'
font_size 13.0
EOF
cat >"$home/.config/foot/foot.ini" <<'EOF'
font=JetBrainsMono:size=9.5
EOF

cat >"$stub_bin/omarchy-default-terminal" <<'SH'
#!/bin/bash
echo "$TEST_TERMINAL"
SH
chmod +x "$stub_bin/omarchy-default-terminal"

cat >"$stub_bin/gsettings" <<'SH'
#!/bin/bash
echo 1.0
SH
chmod +x "$stub_bin/gsettings"

reported_size() {
TEST_TERMINAL="$1" HOME="$home" PATH="$stub_bin:$PATH" \
bash "$ROOT/bin/omarchy-display-text-size" | sed -n 's/^terminal font: \(.*\) pt$/\1/p'
}

[[ $(reported_size foot) == "9.5" ]] ||
fail "text size reads the selected Foot config" "$(reported_size foot)"
pass "text size reads the selected Foot config"

[[ $(reported_size alacritty) == "12" ]] ||
fail "text size reads the selected Alacritty config" "$(reported_size alacritty)"
pass "text size reads the selected Alacritty config"

[[ $(reported_size kitty) == "13.0" ]] ||
fail "text size reads the selected Kitty config" "$(reported_size kitty)"
pass "text size reads the selected Kitty config"

[[ $(reported_size ghostty) == "11" ]] ||
fail "text size reads the selected Ghostty config" "$(reported_size ghostty)"
pass "text size reads the selected Ghostty config"
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 @@ -107,6 +107,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\n' >"$test_dir/bin/omarchy-default-terminal"
cat >"$test_dir/bin/gsettings" <<'SH'
#!/bin/bash
if [[ $1 == "get" ]]; then
Expand Down