I created a new profile for gnome-terminal and I can switch between "Implicit" profile and the new created profile as you can see in the below image:
Now I wonder how can I switch between profiles using a command-line/script or maybe using a shortcut for this.
Note: Solutions like:
gnome-terminal --tab-with-profile=Implicit && exit
are excluded because I prefer not to close and open another terminal or get another terminal window in this process of changing the profile.
A lot of great answers already but I wanted to add one more variation using xdotool that does not require the menu bar to be visible...
The key combo shift+F10 will open a pop-up menu (the equivalent of right-clicking on terminal) and from there the profile can be changed.
e.g.
xdotool key shift+F10 r 3
to get to the third profileI've also found that this method does not require setting a delay for xdotool (which I found necessary for the menu bar method) so it's therefore a little faster.
I tend to change profiles a lot so I wrap this into a function:
so I can just call
chp N
to switch to the Nth profile.Some more tips and idiosyncrasies of my setup:
By adding a
chp
command to my .bashrc I can force new tabs to always switch to the default profileI color code my ssh sessions based on host but I don't like my ssh alias to open new tabs or windows AND I want the profile to change back to the default when I exit ssh. My solution:
alias somehost="chp 2; ssh user@somehost; chp 1"
I give xdotool the flag
--clearmodifiers
so that if I happen to be holding a modifier key (when opening a tab/window, exiting ssh, etc.), it won't interfere with xdotool.I prepend my profile names with numbers so that if I add a new one, it doesn't shift all the others due to the alphabetizing of the profile menu
To switch to the "implicit" profile:
To switch to the second profile:
xdotool
is not installed by default in Ubuntu, so it must to be installed first.Of course, for these commands can be added custom keyboard shortcuts.
There is no shortcut that allows you to change the profile within the terminal (without navigating the menus as you said in comments), without the use of the GUI. Quoting the manual (stable, development 3.9):
(You can propose this as suggestion in the bug tracker)
I was looking to do the same and finally got a script working, I put it up on my GitHub.
Like I explain in the README.md, it doesn't actually switch, but loads a profiles configuration into the Default profile. To do this, the configuration of each profile is saved to file on the first run of the script. The script makes it seem like you're switching between profiles, which is good enough for me. Hope it helps anyone...
Depending on your purpose, you may find this script to be useful: https://github.com/xyrix/gnome-terminal-profile-switcher
It does a sort of monkey patch and generates a new profile for each terminal, then sets some environment variables to expose a program for switching the theme of the profile for your current terminal.
Hopefully the example safe_ssh script will make things clear :-). I've been using it for just over a year now and it's helped me not destroy the company's live database ^_^
If you have a list of servers that you access often, I believe the easiest solution would be to simply invoke a second window just for that box's session.
First, make a separate gnome-terminal profile for each remote location that you use often. Then, in each profile, specify that the terminal should execute the SSH login command for that box, instead of a plain shell.
Finally, write a short script to kick off a new remote window given a profile ID.
Using this strategy you can "infinitely" vary the look of each box's terminal window, and kick them off from a single "control" terminal. For example, if we call this script "rlv", then we can spawn a remote window by simply invoking the script with a profile name.
If you ever fat-finger a host name, or neglect to set up a profile for that host, then you'll just get another default-profile window on the local box. There's a way to code the script to avoid this, by putting the login into the script itself, rather than in the gnome-terminal :
...but then you lose the flexibility of defining your login username for that box. That additional feature of the script I leave as an exercise to the reader.
I've just noticed that my original solution has been already rejected in the question. While there seems no simple way to change the profile, you can change background / foreground color by using
setterm
command.So, this
setterm -term linux -background black -foreground green
would give you black background with green text. The only problem is that ls has colorized output, so you might wanna turn ls coloring off. Otherwise it resets to previous color schemeOriginal post: There is a sort-of way around. From man gnome-terminal :
Here's example from my machine. I have three profiles: B&G(black on green), ForPrinting(black font, white background), and Default. So what I do is in current window type
gnome-terminal --window-with-profile=ForPrinting
. Then I can either kill old window from command line or switch and close it graphically.B&G profile doesn't work. Probably because & is not a valid character, so keep that in mind when naming profiles.
It would be great of gnome-terminal offered a "next profile" command and shortcut; unfortunately, it does not.
A workaround for those with
Alt+T
disabled (Edit > Preferences > Enable mnemonics - unchecked) is:F10 left left down right
and select the profile. Ouch.Even though the question is about GNOME Terminal and the command line, it's worth knowing that MATE Terminal (a GNOME Terminal fork) allows profile switching via a simple keyboard shortcut.
The very ugly solution I've ended up using is
(This selects the second profile, but you could change that to say the htir profile by changing the second "key Down" command to
xdotool key --delay 50 --repeat 2 Down
.What's this doing:
You'll need xdotool installed
sudo apt install xdotool
.Kind of extraordinary that the terminal itself doesn't doesn't allow configuration via the terminal!