17

I often find myself opening three terminals and I really like the look and feel of having distinct color palettes on each.

I have a few color palettes saved and I would like the default to progress through my saved profiles each time I open a terminal, so that if I open 3 they are each different colors without me having to manually change profile on 2.

Any thoughts?

Thanks!

1
  • Just edited my answer with a script that does what you want. It should be added to the ./bashrc file. Hope it suits your need!
    – IanC
    Aug 12, 2016 at 21:18

4 Answers 4

12

One option could be using xfce4-terminal. It's very similar to default Ubuntu terminal (which is gnome-terminal) and many of it's dependency packages use gtk component, which makes it a suitable alternative.

First install it with

sudo apt-get install xfce4-terminal

Then open it, Go to Edit -> Preferences , Select Colors Tab and check the option that says, Vary the background color for each Tab, and Now exit.

Make the default terminal xfce4-terminal or change the shortcut of Ctrl-Alt-T to open it.

Now, each time you open, you will be presented with different color palette. different colored terminal

Useful Links:

11

Functional Version

Instructions:

This script considers that you are using gnome-terminal, which is the default Ubuntu terminal.

Before running the script, open the gnome-terminal and create some profiles (Edit>Preference>Profiles) with different settings as you wish (background color, text color, ..). You can name them Profile1, Profile2, Profile3 and so on. Create enough profiles to cover the quantity of terminals that will be opened, but if a higher number of terminals are opened, the default profile will be used.

The script creates a file ~/.Bash_Color_Changer, which it depends on, since it will tell the script if the terminal was opened regularly or after a call on .bashrc.

Add the script to the end of your ~/.bashrc file.

Script:

Add to .bashrc:

#Change color according to the number of Bash shells opened
#Creates the .Bash_Color_Changer file if it's not present
if ! [ -f ~/.Bash_Color_Changer ]; then
    echo ORIGINAL > ~/.Bash_Color_Changer
fi

#Array holding the name of the profiles: Substitute it for the names you're using
Color_counter=(Profile1 Profile2 Profile3)
#Finds out the number of opened bashs counting the lines containing "bash"
#in the pstree function. (-c deactivates compact display to avoid it showing
#lines with "2*[bash]" instead of one for each bash)
Number_of_bashs=$(($(pstree -c | grep "bash" | wc -l)-1))

#Checks if the terminal being opened was opened by the user or by
#the script, and act according to it
if [ $(cat ~/.Bash_Color_Changer) = ORIGINAL ]; then 
    if ((Number_of_bashs < ${#Color_counter[*]})); then
        echo COPY > ~/.Bash_Color_Changer
        gnome-terminal --tab-with-profile-internal-id=${Color_counter[${Number_of_bashs}]} 
        exit
    fi
else 
    echo ORIGINAL > ~/.Bash_Color_Changer
fi

Tested but not extensively. Enjoy!

5
  • Idea for tomorrow is adding a conditional for exit based on some file like ~/bashcolor.txt. It could have a line to say if the bash being opened is the "original" or the "copy". So if cat ~/bashcolor.txt returns "ORIGINAL" the exit command is run and echo COPY > ~/bashcolor.txt. Else, the exit doesn't run but the file goes back to original (echo ORIGINAL > ~/bashcolor.txt). It would solve the flashing terminal issue.
    – IanC
    Aug 12, 2016 at 3:53
  • Fun script to make, might even use it myself :) Any improvements suggestions are welcome!
    – IanC
    Aug 12, 2016 at 21:19
  • This works in trusty +1
    – user527600
    Aug 12, 2016 at 21:30
  • 3
    I made 1 change in my version... This way it keeps cycling when you open more terminals than you have profiles. Number_of_bashs=$(($(($(pstree -c | grep "bash" | wc -l)-1))%${#Color_counter[@]}))
    – kpie
    Aug 13, 2016 at 2:24
  • Nice! It didn't came to my mind to use modulus to keep the iteration cyclic :p
    – IanC
    Aug 13, 2016 at 23:43
5
+100

Haha, very interesting. I might try doing this as well. I mostly only run multiple terminals and a browser.

So I looked around and found this - https://github.com/sos4nt/dynamic-colors. A very neat little project that helps you achieve a part of what you want.

Now, in the directory colorschemes/ of that project, you'll see that it currently has 4 colour schemes. You can add as many as you need/want.

So to get every terminal to choose a different color-scheme, I would add a function to my .bash_profile or .bashrc or wherever, such that the function does two things:

  1. Figures out how many terminals are currently running
  2. Issue a dynamic-colors switch colorscheme-name command based on (1).

Hope this helps!

P.S. I would write a script for you, but I hate spoon-feeding and I'm lazy af. :)

5
  • good one...creating an wrapper/alias to the terminal command would be achieve it. Aug 11, 2016 at 11:46
  • @VishnuKumar, yep, this is what first came to mind though it might not be the best solution. glad you like it. Aug 11, 2016 at 11:48
  • +1 for an ok answer, I really don't want to fight with "works" but this answer requires that I use the proprietary style definitions used my the dynamic-colors project, additionally (and this is what really got me) it doesn't support opacity : ( I feel like the answer should involve some combination of the gnome-terminal --load-config=FILE
    – kpie
    Aug 11, 2016 at 23:04
  • @kpie, haha. No fair, opacity wasn't mentioned in the question. Also, it is difficult to set opacity from command line and depends a lot on a lot of things. Also, this question may be answered in various ways, but I thought my answer was pretty convenient (if only for me, haha) :) Aug 11, 2016 at 23:06
  • I hope I can make up for knit picking by providing the required scripts... github.com/Krewn/stylingTerminalOnOpen And I should specify it doesn't support variable opacity, the color schemes will maintain the opacity of your default profile.
    – kpie
    Aug 12, 2016 at 0:10
2

Konsole actually supports this functionality natively. Konsole is really powerful and highly customizable.

If you don't have Konsole then simply sudo apt install konsole

  1. Go to Settings
  2. Konsole Settings
  3. Select the Appearance tab
  4. Select your color scheme
  5. Select "Edit" on the right
  6. There's a box to set "Vary the background color for each tab"

On top of that, if you're working on three servers at the same time you can include some nifty aliases shown here

7
  • +1 for an ok answer but I don't have konsole. @<MemoryAddress>'s answer supports more terminal interfaces (any that support OSC escape sequences). But yours is easier to use. I'll give the bounty to whoever has the most up votes in a couple days. Thanks for your answer!
    – kpie
    Aug 12, 2016 at 0:45
  • You'd be surprised how many people would actually comment on here telling me I need to tell you how to install it -_-
    – Matt O.
    Aug 12, 2016 at 0:51
  • Did you read the comments on teh other ans?
    – kpie
    Aug 12, 2016 at 0:52
  • I did. Maybe I'm missing something but you're looking for variable opacity and something that doesn't require aliases. Konsole achieves both of those, but I'm not sure about the escape sequences.
    – Matt O.
    Aug 12, 2016 at 0:55
  • 1
    haha I get it. Don't blame me, after having enough nutty people on here suggest edits I just do it automatically. I'm not trying to insult your intelligence.
    – Matt O.
    Aug 12, 2016 at 0:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .