简体   繁体   中英

Change the background color in Gnome terminal through a command?

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?

你可以像这样使用 setterm

setterm -term linux -back blue -fore white -clear

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.

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

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.

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!

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'
  1. Now edit / create your 4 terminal profiles
  2. open > terminal > edit > profiles > new > profile name = term1
  3. colors tab > choose your font and background colors
  4. Title and Command tab > initial title = term1
  5. repeat the above commands for 3 remaining terminals.

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!

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.

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.

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" 

您不必通过命令执行此操作,您可以转到 Edit>>Preferences>>color 来更改它。

sudo apt-get install dconf-cli uuid-runtime
bash -c  "$(wget -qO- https://git.io/vQgMr)"

Select theme you want by enter the number Gogh - Color Scheme

well, xterm has direct methods to change colours, fonts and size:

xterm -bg Blue1 -fg white -fa 'Monospace' -fs 9

why use gnome-terminal?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM