Reputation:
I'm using Gnome terminal and I want to change the background color or the profile through a command so I can group some commands in an alias to visually differentiate my windows when I run certain processes. I'm running Ubuntu, and bash is my shell. Are there commands in to do this?
Upvotes: 28
Views: 61554
Reputation: 28742
In the gnome terminal on ubuntu 20lts you can run a command like:
echo -e '\e]11;rgb:aa/bb/cc\a'
where aa, bb, cc are hexadecimal numbers from 0 to 255.
If you wish to change the foreground color, use \e]10;
instead of \e]11;
To get the correct color commands you can use the color pickers in the snippet below.
let bg = document.getElementById('bg');
let fg = document.getElementById('fg');
let binp = document.getElementById('numberbg');
let finp = document.getElementById('numberfg');
binp.addEventListener('input', (e) => {
let val = spl(e);
bg.innerText = "echo -e '\\e]11;rgb:"+val+"\\a'";
up(bg); up(fg);
});
finp.addEventListener('input', (e) => {
let val = spl(e);;
fg.innerText = "echo -e '\\e]10;rgb:"+val+"\\a'";
up(bg); up(fg);
});
function spl(e) {
return e.target.value.substring(1).match(/.{1,2}/g).join('/');
}
function up(i) {
i.style.backgroundColor = binp.value;
i.style.color = finp.value;
}
code {
margin: 20px;
background: #ddd;
border: 1px solid #333;
padding:20px;
clear:both;
display: inline-block;
}
<div>
<label for="numberbg">set background: </label>
<input id="numberbg" type="color" value="#000000"> <BR>
<code id="bg">
echo -e '\e]11;rgb:00/00/00\a'
</code>
</div>
<div>
<label for="numberfg">set foreground: </label>
<input id="numberfg" type="color" value="#eeeeee"> <BR>
<code id="fg">
echo -e '\e]10;rgb:ee/ee/ee\a'
</code>
</div>
Upvotes: 5
Reputation: 11
You don't have to do this via command you can go to Edit>>Preferences>>color to change it.
Upvotes: 1
Reputation: 595
i have created some functions, based on github code from other threads. Sorry i don't remember.
You can put these functions in your ~/.bashrc file
As you can see, if you call "create_random_profile",
First, it will check and delte any previous random profile you have created.
Second, it will create a random name profile in gnome terminals.
Third, it will set that name in an environment variable that you can use to change your color in predefined functions. See last function function setcolord().
This should be useful, to have many terminals with different colors. Besides, with predefined functions you can change these colors on the fly. Enjoy it!
function create_random_profile() {
#delete previous profiles in case there were something
#delete_one_random_profile
prof="`mktemp -u HACK_PROFILE_XXXXXXXXXX`"
gconftool-2 --type list --list-type string --set $prof_list "`gconftool-2 --get $prof_list | sed "s/]/,$prof]/"`"
file="`mktemp`"
gconftool-2 --dump "/apps/gnome-terminal/profiles/Default" | sed "s,profiles/$2,profiles/$prof,g" > "$file"
gconftool-2 --load "$file"
gconftool-2 --type string --set "/apps/gnome-terminal/profiles/$prof/visible_name" "$prof"
gconftool-2 --set "/apps/gnome-terminal/profiles/$prof/use_theme_colors" --type bool false
rm -f -- "$file"
export __TERM_PROF=$prof
}
function delete_one_random_profile() {
regular="HACK_PROFILE_"
prof=$(gconftool-2 --get /apps/gnome-terminal/global/profile_list | sed -n "s/.*\(HACK_PROFILE_..........\).*/\1/p")
if [ ! -z "$prof"]; then
echo "size ${#prof}"
echo "size of regular ${#regular}"
echo "DO DELETE of $prof"
#if not empty
gconftool-2 --type list --list-type string --set $prof_list "`gconftool-2 --get $prof_list | sed "s/$prof//;s/\[,/[/;s/,,/,/;s/,]/]/"`"
gconftool-2 --unset "/apps/gnome-terminal/profiles/$prof"
else
echo "NOTHING TO DELETE"
fi
}
function setcolord()
{
echo "Dont forget to change to Profile0 in the menu of your terminal->Change Profile->Profile_0"
gconftool-2 --set "/apps/gnome-terminal/profiles/$__TERM_PROF/background_color" --type string white
gconftool-2 --set "/apps/gnome-terminal/profiles/$__TERM_PROF/foreground_color" --type string black
}
function setcolor_cyan()
{
echo "Dont forget to change to $__TERM_PROF in the menu of your terminal->Change Profile->Profile_0"
gconftool-2 --set "/apps/gnome-terminal/profiles/$__TERM_PROF/background_color" --type string "#8DCBCC"
gconftool-2 --set "/apps/gnome-terminal/profiles/$__TERM_PROF/foreground_color" --type string black
}
By the way you can save time if you create the terminal using already the random. You can do that calling:
gnome-terminal --working-directory=$HOME --window-with-profile="$prof"
Upvotes: 0
Reputation: 41
try the following command from a desktop launcher:
gnome-terminal --window-with-profile=site2 -x ssh site2
Using -x ssh
means that the terminal will only be active on the remote site, so completely removing the possibility of typing a command on the wrong machine because you've exited from a terminal command line ssh.
Upvotes: 4
Reputation: 1489
To create 4 terminals with different backgrounds and titles you need to add the below lines to the .bashrc_profile file
$.bash_profile
add the below lines to file
alias term1='gnome-terminal –window-with-profile=term1'
alias term2='gnome-terminal –window-with-profile=term2'
alias term3='gnome-terminal –window-with-profile=term3'
alias term4='gnome-terminal –window-with-profile=term4'
close any open terminals you may have then re-open a new terminal and type 'term1' hit enter and repeat for all 4 now you have 4 unique terminals open!
Upvotes: 1
Reputation: 21
1) Create a terminal profile with the color and settings you desire, and call it "myGterm"
2) Edit your .bashrc
file.
3) Add the following line:
alias Gterm='gnome-terminal --window-with-profile=myGterm'
4) Save and close .bashrc
5) Open a terminal and type:
$ Gterm
6) Voila!
Upvotes: 2
Reputation: 1481
you can use setterm like this
setterm -term linux -back blue -fore white -clear
Upvotes: 14
Reputation: 4037
I looked into it and it turns out this is not possible. I filed bug: http://bugzilla.gnome.org/show_bug.cgi?id=569869
gconftool-2 can get/set profile properties, but there is no way to script an existing, open gnome-terminal.
Upvotes: 1
Reputation: 78922
Assuming you know what profile you want before you open your terminal:
Right-click on your Panel and "Add to Panel" and add a custom application launcher
You can define position, size and profile (which takes care of colours, fonts, etc)
gnome-terminal --hide-menubar --geometry 115x40+0+0
gnome-terminal --window-with-profile=logs --hide-menubar --geometry=144x15+0-55
"man gnome-terminal" has lots of useful information
Upvotes: 4
Reputation:
You want to use gconftool.
Gnome holds its settings in a hierarchy similar to the Windows Registry. Once you know the path to the item you want to change you can set that item's value with gconftool from the command line.
Use gconf-editor to browse through the Gnome settings.
Use gconftool to set the value of an item in your script.
In your case, you want to do the following:
gconftool --type string --set /desktop/gnome/background/primary_color "#dadab0b08282"
Obviously you'll want to replace that color value with whatever color you want.
Upvotes: 2
Reputation: 182878
I used to do this with command line arguments to xterm. I set up my .olvwm (am I dating myself) to execute 4 xterms with different background colours.
Upvotes: 0