Skip to content
21 changes: 15 additions & 6 deletions bin/omarchy-display-text-size
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,26 @@ 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)
[[ -f ~/.config/kitty/kitty.conf ]] || return 0
grep -oP '^font_size[[:space:]]+\K[0-9.]+' ~/.config/kitty/kitty.conf | head -1
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
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"