Xfce Forum

Sub domains
 

You are not logged in.

#1 2013-11-23 18:01:56

qwazer
Member
Registered: 2013-11-23
Posts: 1

Is it possible to change color of terminal in runtime by command-line?

I want to write some automation scripts for terminal.
For example, after invoking 'ssh' command change color of terminal.

Is it possible to change color of terminal in runtime with command-line command?

May be it's possible reload .config/Terminal/terminal inside launched terminal.

Offline

#2 2015-06-24 12:11:54

khambrecht
Member
Registered: 2015-06-24
Posts: 3

Re: Is it possible to change color of terminal in runtime by command-line?

Did you get it? I am also looking for a solution.

Offline

#3 2015-06-24 13:48:49

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: Is it possible to change color of terminal in runtime by command-line?

If you're talking about changing the whole color scheme (the properties) on the fly, then I don't believe its possible.

However, you can manipulate prompt and output colours on the fly. Have a read through the Arch Color Bash Prompt wiki (and associated links at the bottom of the page) for a general introduction.

For example, in my ~/.bashrc file, I have 3 functions:

green () {
	PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[m\]\[\e[0;32m\] '
}

red () {
	PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[m\]\[\e[0;31m\] '
}

grey () {
    PS1='[\u@\h \W]\$\e[0m '
}

Whenever I want to change the colour scheme to green, I enter "green" and whenever I want to change the color scheme to red, I enter "red". "grey" to return to my default.

You can do much more than that, as per the link above.
A8eOuuy.png

If you're looking to change the prompt colours based on each ssh host you connect to, have a look at this post and answer. Basically, you adjust the PS1 prompt for each host you connect to.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#4 2015-06-24 14:13:41

khambrecht
Member
Registered: 2015-06-24
Posts: 3

Re: Is it possible to change color of terminal in runtime by command-line?

Hi ToZ,

thanks for your reply.

ToZ wrote:

If you're talking about changing the whole color scheme (the properties) on the fly, then I don't believe its possible.

kind of. I'm looking for a solution to just set the foreground and/or background color. For example when invoking xterm like this:

xterm -bg "#000000" -fg "#EEBB88"

But just for the running (xfce)-terminal instance (instead of invoking a new one)

ToZ wrote:

If you're looking to change the prompt colours based on each ssh host you connect to, have a look at this post and answer. Basically, you adjust the PS1 prompt for each host you connect to.

Exactly for this purpose ;-) But setting PS1 prompt would require to modify this on every target machine. Also setting PS1 does not work permanently sometimes. So I would like to change the colors on the source machine when connecting via ssh.

Offline

#5 2015-06-24 19:00:15

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: Is it possible to change color of terminal in runtime by command-line?

Unfortunately, xfce4-terminal doesn't support setting foreground/background colours via command line parameters.

There is one way to work around this. xfce4-terminal gets its configuration information from XDG_CONFIG_HOME/xfce4/terminal/terminalrc. You can specify different XDG_CONFIG_HOMEs (each with its own copy of xfce4/terminal/terminalrc - which can contain different colour settings) and run it with the --disable-server parameter. For example:

1. Create ~/.config2/xfce4/terminal:

mkdir -p ~/.config2/xfce4/terminal

2. Run xfce4-terminal like this:

XDG_CONFIG_HOME=~/.config2 xfce4-terminal --disable-server

3. Edit the preferences as you wish.

Each time you start xfce4-terminal with XDG_CONFIG_HOME pointing to .config2 (and the server disabled), you'll get those specific preferences. You can create as many config homes as you want.

------------------------

EDIT: I just re-read your last post and noticed that you said on the fly instead of starting a new terminal. As per http://stackoverflow.com/questions/2755 … r-over-ssh, and building on the previous PS1 prompt suggestion, you can create specific functions to connect to ssh hosts and change the terminal colours before and reset after the session. For example:

function ssh_server1
{
    printf "\e[41m\e[34m"    # blue on red
    clear
    \ssh $@ || read           # Actual ssh command
    printf "\e[0m"           # Reset terminal
    clear
}

...and then:

ssh_server1 -l toz 192.168.1.254

Last edited by ToZ (2015-06-24 19:00:51)


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#6 2015-06-28 19:30:18

Beartooth
Member
Registered: 2015-06-28
Posts: 2

Re: Is it possible to change color of terminal in runtime by command-line?

mate-terminal and gnome-terminal will both let you change color schemes on the fly; you might want to keep one of them open -- I use nothing else, just because I keep every tab color-coded to tell me whether it's on its own or a remote machine, whether it's root, etc. etc.

     In either terminal, hitting Edit will give you a chance to edit profiles. So you set up several profiles with color combinations according to what you often use -- such as whether the tab of the moment is on the same machine as the rest, or ssh'd into another on your LAN, for instance.  (I suggest that you become root  ONLY on a profile with all its text in deep blod red -- and its background different if that tab is actually working on a different machine of your LAN, through ssh.)


Beartooth Implacable, Curmudgeonly Codger
On the Internet, you can never tell who is a dog --
supposing you care --
but you can tell who has a mind.

Offline

#7 2015-07-14 09:31:19

khambrecht
Member
Registered: 2015-06-24
Posts: 3

Re: Is it possible to change color of terminal in runtime by command-line?

Thanks for your reply, ToZ and Beartooth,

but both solutions are not exactly what I'm looking for. Setting colour via printf (and also via setterm) will not work fine, if you have a colourized PS1 prompt as colours will mix up. Also changing colours in mate-terminal or gnome-terminal via profile editing is not the way to go.

But I found a solution with roxterm where you can switch colour profiles and define colours via DBus interface on the fly. To get the logic for colours depending on the ssh hostname, I modified this ruby script to change dynamically the colour profile of roxterm. You may find this modified script here.

Maybe changing colours via DBus is also possible in xfce terminal, however I did not find any hints on this yet.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.009 seconds, 7 queries executed - Memory usage: 551.23 KiB (Peak: 568.51 KiB) ]