3

I found some escape codes for changing fonts in urxvt. I'd like to use these to dynamically change my font size. I've seen a few plugins that do this, but they're fairly opinionated about it and usually rely on a hardcoded list of fonts to toggle through. I'd prefer to query for the current font, change the size, and print the escape codes for that. Is this possible?

valadil
  • 1,648
  • 1
  • 14
  • 30
  • Take a look at this [https://bbs.archlinux.org/viewtopic.php?id=44121](https://bbs.archlinux.org/viewtopic.php?id=44121) – Chan Kha Vu Apr 16 '15 at 16:41
  • @FalconUA Almost what I want. I'd like to increase or decrease based on whatever the current font is, not switch to a fixed size. But if that's not possible this is certainly a good compromise. – valadil Apr 17 '15 at 15:32

2 Answers2

9

Press Control-Shift and click a character.

A small window will appear telling you what the font is for the character you clicked.

user34445
  • 191
  • 2
  • 5
4

You can use appres to query the font. Not sure what Linux you’re on, but if it happens to be Arch, install with: sudo pacman -S xorg-appres.

Example query on my system:

% appres urxvt |grep '\*font:' |awk '{print $2}'
-misc-orp-medium-r-*-*-12-*-75-75-*-60-iso10646-*

You could parse out the size info (12) from that to decide whether to increase or whatever:

% origsize=$(appres urxvt |grep '\*font:' |awk -F- '{print $8}')  # 12

You can use printf to increase that size, in a my-font-changer script, like:

printf "\033]710;-misc-orp-medium-r-*-*-$newsize-*-*-*-*-*-iso8859-*\007"
printf "\033]711;-misc-orp-bold-*-*-*-$newsize-*-*-*-*-*-iso8859-*\007"
printf "\033]712;-misc-orp-*-i-*-*-$newsize-*-*-*-*-*-iso8859-1\007"
printf "\033]713;-misc-orp-*-i-*-*-$newsize-*-*-*-*-*-iso8859-1\007"

Then you could assign a hotkey in ~/.Xdefaults:

URxvt.keysym.M-C-1: command: my-font-changer

(Most of this is untested, but you can piece it together.)

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54
  • @valadil: Were you able to get this working? Please update if you had any trouble, or accept so others will see it as a useful approach. – Micah Elliott Aug 25 '15 at 21:03
  • This doesn't work for me. It outputs the font that is currently defined in `~/.Xresources`. If you open a terminal, change the font, then `xrdb ~/.Xresources`, then execute the suggested command, you'll get the font defined in `~/.Xresources`, not the font that is currently used by the current terminal. – Andrii Tykhonov Sep 19 '21 at 19:55