14

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?

mitrx
  • 143

4 Answers4

13

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.

muru
  • 207,228
10

A better approach would be: create your own color scheme and allow yourself to choose one across many.

To do that, create the directory:

mkdir -p ~/.local/share/xfce4/terminal/colorschemes

And place files like that inside:

[Scheme]
Name=my good profile
ColorForeground=#4ccd4ccd4ccd
ColorBackground=#f851f465ebe7
TabActivityColor=#d8d8a9a97f7f
ColorCursor=#f0f0b6b66666
ColorSelection=#16163b3b5959
ColorPalette=rgb(0,0,0);rgb(170,0,0);rgb(0,170,0);rgb(170,85,0);rgb(0,0,170);rgb(170,0,170);rgb(0,138,138);rgb(170,170,170);rgb(85,85,85);rgb(255,85,85);rgb(85,255,85);rgb(196,160,0);rgb(85,85,255);rgb(255,85,255);rgb(68,204,204);rgb(255,255,255)

If you have an already configured terminalrc file in your ~/.config/xfce4/terminal directory, you can just copy the appropriate lines.

After doing so, your new color scheme appears inside the main list. So you can, for example, have both a custom white color theme, and a custom black.

1

terminalrc does not seem to be the way to do it anymore; according to the docs:

As of version 1.1.0, xfce4-terminal has migrated to using xfconf to store its settings. You can view these settings in the xfce4-terminal channel through the xfce4-settings-editor application, and manually manipulate them using xfconf-query.

While terminalrc still exists, changes made through the preferences dialog are not reflected there, so it is probably safer to avoid it.

The relevant config while -- which I assume can also be edited manually -- is .config/xfce4/xfconf/xfce-perchannel-xml/xfce4-terminal.xml.

Raphael
  • 2,052
0

From Gogh apply color themes for xfce4-terminal (https://github.com/Gogh-Co/Gogh/blob/master/apply-colors.sh#L809):

# XFCE4 terminal has no profiles, instead it uses color presets
SCHEMEDIR="${HOME}/.local/share/xfce4/terminal/colorschemes"
CONFFILE="${HOME}/.config/xfce4/terminal/terminalrc"

if [[ ! (-w "${CONFFILE}") ]]; then if [[ -r "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ]]; then cp "${XDG_CONFIG_DIRS%%:*}/Terminal/terminalrc" ${CONFFILE} else echo "ERROR: config file not present or not writable!" exit 1 fi fi

[[ -d "${SCHEMEDIR}" ]] || mkdir -p "${SCHEMEDIR}"

F_NAME=${PROFILE_NAME// /-} F_NAME=$(echo ${F_NAME} | tr -d ":()") F_NAME=$(echo "${F_NAME}" | awk '{print tolower($0)}')

FF_NAME="${SCHEMEDIR}/${F_NAME}.theme"

touch "${FF_NAME}"

L_COLORCURSOR="ColorCursor=${CURSOR_COLOR}" L_COLORPALETTE="ColorPalette=${COLOR_01};${COLOR_02};${COLOR_03};${COLOR_04};${COLOR_05};${COLOR_06};${COLOR_07};${COLOR_08};${COLOR_09};${COLOR_10};${COLOR_11};${COLOR_12};${COLOR_13};${COLOR_14};${COLOR_15};${COLOR_16}"

printf '%s\n'
"; Generated by Gogh"
"; https://Gogh-Co.github.io/Gogh"
"[Scheme]"
"Name=${PROFILE_NAME}"
"ColorForeground=${FOREGROUND_COLOR}"
"ColorBackground=${BACKGROUND_COLOR}"
"${L_COLORCURSOR}"
"${L_COLORPALETTE}"
"ColorCursorUseDefault=FALSE" > ${FF_NAME}

apply last theme in queue

xfce4-terminal monitors its rc file and doesn't reference

any of the themes in there. The color settings need to

be written there directly.

if ((LOOP == OPTLENGTH)); then read -r -p "All done - apply new theme? [y/N] " -n 1 XFCE4_APPLY_CURR_THEME if [[ ${XFCE4_APPLY_CURR_THEME::1} =~ ^(y|Y)$ ]]; then if grep -q "^ColorPalette=" "${CONFFILE}"; then sed -i -r -e "s/^ColorPalette=.*/${L_COLORPALETTE}/" "${CONFFILE}" else echo "${L_COLORPALETTE}" >> "${CONFFILE}" fi

    if grep -q &quot;^ColorCursor=&quot; &quot;${CONFFILE}&quot;; then
        sed -i -r -e &quot;s/^ColorCursor=.*/${L_COLORCURSOR}/&quot; &quot;${CONFFILE}&quot;
    else
        echo &quot;${L_COLORCURSOR}&quot; &gt;&gt; &quot;${CONFFILE}&quot;
    fi

    if grep -q &quot;^ColorForeground=&quot; &quot;${CONFFILE}&quot;; then
        sed -i -r -e &quot;s/^ColorForeground=.*/ColorForeground=${FOREGROUND_COLOR}/&quot; &quot;${CONFFILE}&quot;
    else
        echo &quot;ColorForeground=${FOREGROUND_COLOR}&quot; &gt;&gt; &quot;${CONFFILE}&quot;
    fi

    if grep -q &quot;^ColorBackground=&quot; &quot;${CONFFILE}&quot;; then
        sed -i -r -e &quot;s/^ColorBackground=.*/ColorBackground=${BACKGROUND_COLOR}/&quot; &quot;${CONFFILE}&quot;
    else
        echo &quot;ColorBackground=${BACKGROUND_COLOR}&quot; &gt;&gt; &quot;${CONFFILE}&quot;
    fi

    if grep -q &quot;^ColorCursorUseDefault=FALSE&quot; &quot;${CONFFILE}&quot;; then
        true
    else
        echo &quot;ColorCursorUseDefault=FALSE&quot; &gt;&gt; &quot;${CONFFILE}&quot;
    fi
fi

fi

unset SCHEMEDIR unset CONFFILE unset PROFILE_NAME unset F_NAME unset FF_NAME unset L_COLORCURSOR unset L_COLORPALETTE exit 0

Its not full code, but may be helpfull.

FRiMN
  • 111