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
78 changes: 23 additions & 55 deletions bin/omarchy-display-text-size
Original file line number Diff line number Diff line change
Expand Up @@ -133,68 +133,36 @@ term_pt_for() {
'BEGIN { printf "%d", int(s * p / b + 0.5) }'
}

# Set the font point size in terminal configs, creating Kitty overrides when
# it inherits its size from the system config. Family is left
# untouched — that is omarchy-font-set's job. Live-reload signals mirror
# omarchy-font-set; foot has no reload signal, so running instances are nudged.
# Write point size to per-machine overlays (not the shared terminal configs).
# Family is left untouched — that is omarchy-font-set's job. omarchy-font-size
# reloads Kitty/Ghostty; 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/^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/^font-size = .*/font-size = $pt/" ~/.config/ghostty/config
pkill -SIGUSR2 ghostty 2>/dev/null || true
fi

if [[ -f ~/.config/foot/foot.ini ]]; then
sed --follow-symlinks -i -E "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-display-text-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
omarchy-font-size --quiet "$pt"

# 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-display-text-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
}

# Report the current terminal point size from whichever config we find first.
# Report the current terminal point size from the machine-local overlay,
# falling back to shared configs (pre-migration) and the 9pt default.
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
omarchy-font-size
}

case "${1:-}" in
Expand Down
70 changes: 55 additions & 15 deletions bin/omarchy-font-set
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ if ! fc-list | grep -Fqi -- "$font_name"; then
exit 1
fi

config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
alacritty_config="$config_home/alacritty/alacritty.toml"
kitty_config="$config_home/kitty/kitty.conf"
ghostty_config="$config_home/ghostty/config"
foot_config="$config_home/foot/foot.ini"
foot_local="$config_home/foot/local.ini"

sed_escape() {
local value="$1"
value=${value//\\/\\\\}
Expand All @@ -53,36 +60,69 @@ quoted_font_name=${font_name//\\/\\\\}
quoted_font_name=${quoted_font_name//\"/\\\"}
quoted_sed_font_name=$(sed_escape "$quoted_font_name")

if [[ -f ~/.config/alacritty/alacritty.toml ]]; then
sed --follow-symlinks -i "s/family = \".*\"/family = \"$quoted_sed_font_name\"/g" ~/.config/alacritty/alacritty.toml
if [[ -f $alacritty_config ]]; then
sed --follow-symlinks -i "s/family = \".*\"/family = \"$quoted_sed_font_name\"/g" "$alacritty_config"
fi

if [[ -f ~/.config/kitty/kitty.conf ]] || omarchy-cmd-present kitty; then
mkdir -p ~/.config/kitty
if grep -qE '^[[:space:]]*font_family[[:space:]]+' ~/.config/kitty/kitty.conf 2>/dev/null; then
sed --follow-symlinks -i -E "s/^[[:space:]]*font_family[[:space:]]+.*/font_family $sed_font_name/" ~/.config/kitty/kitty.conf
if [[ -f $kitty_config ]] || omarchy-cmd-present kitty; then
mkdir -p "$(dirname "$kitty_config")"
if grep -qE '^[[:space:]]*font_family[[:space:]]+' "$kitty_config" 2>/dev/null; then
sed --follow-symlinks -i -E "s/^[[:space:]]*font_family[[:space:]]+.*/font_family $sed_font_name/" "$kitty_config"
else
printf '\nfont_family %s\n' "$font_name" >>~/.config/kitty/kitty.conf
printf '\nfont_family %s\n' "$font_name" >>"$kitty_config"
fi
if ! $headless; then
pkill -USR1 kitty
fi
fi

if [[ -f ~/.config/ghostty/config ]]; then
sed --follow-symlinks -i "s/font-family = \".*\"/font-family = \"$quoted_sed_font_name\"/g" ~/.config/ghostty/config
if [[ -f $ghostty_config ]]; then
sed --follow-symlinks -i "s/font-family = \".*\"/font-family = \"$quoted_sed_font_name\"/g" "$ghostty_config"
if ! $headless; then
pkill -SIGUSR2 ghostty
fi
fi

if [[ -f ~/.config/foot/foot.ini ]]; then
# Preserve the primary font's size, not a fallback's; Omarchy ships 9 when none is present.
foot_size="$(sed -n 's/^font=[^,]*:size=\([0-9.]\+\).*/\1/p' ~/.config/foot/foot.ini | head -1)"
if [[ -z $foot_size ]]; then
foot_size=9
if [[ -f $foot_config ]]; then
# The family ends at the first colon or the first comma. Stopping only at
# a colon turns "Old, Emoji:size=10" into "New:size=10" and drops the fallback.
sed --follow-symlinks -i -E "s/^font=[^:,]+/font=$sed_font_name/" "$foot_config"
fi

# Foot's one font= key replaces the whole list, so the overlay keeps this
# family and its fallbacks. Change the primary family only. A later fallback's
# size is not this machine's text size.
if [[ -f $foot_local ]]; then
size=$(sed -n 's/^[[:space:]]*font[[:space:]]*=[^,]*:size=\([0-9.][0-9.]*\).*/\1/p' "$foot_local" | head -1 || true)
size=${size:-9}
size=${size%.0}
if grep -qE '^[[:space:]]*font[[:space:]]*=' "$foot_local"; then
value=$(grep -E '^[[:space:]]*font[[:space:]]*=' "$foot_local" | head -1 || true)
value=${value#*=}
value=$(printf '%s\n' "$value" | sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//')
if [[ $value == *,* ]]; then
first=${value%%,*}
rest=",${value#*,}"
else
first=$value
rest=""
fi
if [[ $first == *:* ]]; then
attrs=":${first#*:}"
else
attrs=""
fi
[[ $attrs == *:size=* ]] || attrs="${attrs}:size=${size}"
tmp=$(mktemp)
awk -v line="font=${font_name}${attrs}${rest}" '
/^[[:space:]]*font[[:space:]]*=/ { if (!done) print line; done = 1; next }
{ print }
' "$foot_local" >"$tmp"
cat "$tmp" >"$foot_local"
rm -f "$tmp"
else
printf '\nfont=%s:size=%s\n' "$font_name" "$size" >>"$foot_local"
fi
sed --follow-symlinks -i "s/^font=.*/font=$sed_font_name:size=$foot_size/g" ~/.config/foot/foot.ini
fi

# fontconfig is the canonical source of truth — the omarchy shell, Qt apps,
Expand Down
Loading