Ubuntu – Change color scheme for xfce4 terminal manually

colorsthemesxfcexfce4-terminal

I want to bind a shortcut to change my solarized color schemes (dark and light). For this purpose I need to know a command for terminal to change its color scheme, but I haven't found such one and I have to go time after time to preferences menu and switch preseted schemes. Is there any way to make such kind of switcher for terminal color schemes?

Best Answer

XFCE4 terminal stores user preferences in $XDG_CONFIG_HOME/xfce4/terminal/terminalrc (typically, ~/.config/xfce4/terminal/terminalrc - might not exist if you haven't changed any preferences). I found that XFCE4 Terminal watches this file and reloads settings when it changes, so you can write to this file to change settings.

However, there is no single entry you can edit to change the colours. The various palettes are actually a set of settings. For example:

$ cat /usr/share/xfce4/terminal/colorschemes/solarized-dark.theme 
[Scheme]
Name=Solarized (dark)
Name[bg]=Златисто (тъмно)
Name[fr]=Solarisé (foncé)
Name[nl]=Overbelicht (donker)
Name[th]=ในแสงแดด (มืด)
Name[uk]=Золотистий (темний)
ColorForeground=#839496
ColorBackground=#002b36
ColorCursor=#93a1a1
TabActivityColor=#dc322f
ColorPalette=#073642;#dc322f;#859900;#b58900;#268bd2;#d33682;#2aa198;#eee8d5;#002b36;#cb4b16;#586e75;#657b83;#839496;#6c71c4;#93a1a1;#fdf6e3
ColorBold=#93a1a1
ColorBoldUseDefault=FALSE

And terminalrc will look like:

$ cat .config/xfce4/terminal/terminalrc                           
[Configuration]
ColorForeground=#839496
FontName=Ubuntu Mono 12
ColorBackground=#002b36
ColorCursor=#93a1a1
ColorBold=#93a1a1
ColorBoldUseDefault=FALSE
ColorPalette=#073642;#dc322f;#859900;#b58900;#268bd2;#d33682;#2aa198;#eee8d5;#002b36;#cb4b16;#586e75;#657b83;#839496;#6c71c4;#93a1a1;#fdf6e3
TabActivityColor=#dc322f
TabActivityColor=#dc322f

As can be seen, there's no way to easily identify which palette the colours came from.

Scripting this doesn't seem safe, but here's an inefficient attempt:

#! /bin/bash
if ! [[ -f /usr/share/xfce4/terminal/colorschemes/$1.theme ]]
then
    echo "No such colorscheme: $1"
    exit 1
fi
cd ~/.config/xfce4/terminal
# strip settings from any themes
grep -Fxvf <(cat /usr/share/xfce4/terminal/colorschemes/*.theme) terminalrc > .terminalrc.tmp
grep -v -e Name -e Scheme "/usr/share/xfce4/terminal/colorschemes/$1.theme" >> .terminalrc.tmp
cp terminalrc terminalrc.bak
mv .terminalrc.tmp terminalrc

Copy this to somewhere in your PATH (for example, ~/bin/xfce-color-switch). Then:

$ xfce4-color-switch dark-pastels

enter image description here

$ xfce4-color-switch solarized   
No such colorscheme: solarized
$ xfce4-color-switch solarized-dark

enter image description here

You'll have to remember colorscheme names for this, but I'll add instructions on how to add tab-completion once I figure them out.

Related Question