You are not logged in.
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
Did you get it? I am also looking for a solution.
Offline
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.
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
Hi ToZ,
thanks for your reply.
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)
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
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
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
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
[ Generated in 0.009 seconds, 7 queries executed - Memory usage: 551.23 KiB (Peak: 568.51 KiB) ]