6

I would like to be able to switch between a light and dark color scheme in an existing rxvt-unicode terminal window, in the same vein as switching profiles in gnome-terminal.

Would the best way to do this be to define the colors in a script outside of .Xresources?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
coffeecola
  • 63
  • 1
  • 5
  • 1
    Have you looked at the `xrdb` command? – Stephen Harris Jul 16 '16 at 00:57
  • @StephenHarris, very cool! I was not familiar with this command. Loading new settings through `xrdb` only seem to take effect once I open a new instance of `rxvt`, though. – coffeecola Jul 16 '16 at 01:07
  • Right; it modifies the resource database that's read when new processes start up. It won't affect existing processes. Sorry, it wasn't clear to me you wanted to modify existing windows. – Stephen Harris Jul 16 '16 at 01:11

2 Answers2

5

I added the following to my ~/.Xresources file to change to colors on the fly pressing Ctrl and 7 or 8 or 9.

! change to red background
URxvt.keysym.C-7: command:\033]11;#ff0000\007

! change to light background
URxvt.keysym.C-8: command:\033]11;#ffffff\007

! change to dark gray background
URxvt.keysym.C-9: command:\033]11;#777777\007

If you want to set foreground and background color at the same time, just concatenate the commands (some colors are defined by names):

! change to red background
URxvt.keysym.C-7: command:\033]11;#ff0000\007\033]10;yellow\007

You can test your colors with a simple echo command, like this one:

echo -e '\033]11;#ff0000\007\033]10;yellow\007'   # changes to red background and yellow foreground

Attention

I used code 11 for background color and code 10 for foreground color. The definitions for Urxvt cited by Thomas Dickey indicate to use 49 and 39 instead (which I tested and also work).

erik
  • 16,959
  • 4
  • 32
  • 46
2

If you want to switch profiles just like gnome-terminal (or konsole), that is making changes to a running terminal. xrdb will not do that.

If you want to change the foreground/background default colors, you can use the xterm dynamic colors escape sequences (which rxvt-unicode implements, as I noted in Urxvt: change background color on the fly).

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • I am surprised I did not find that question before posting this one, as this is surely a duplicate. Just to clarify, the best way to switch colors would be to have a bash scripts with a `printf` for each color by number? – coffeecola Jul 16 '16 at 01:30
  • yes, you can change the default foreground/background colors using a script. "ANSI" colors override that. – Thomas Dickey Jul 16 '16 at 01:32