Skip to content

Instantly share code, notes, and snippets.

@tamboer
Created June 27, 2020 09:08
Show Gist options
  • Save tamboer/8b8bafe92930267bdb39d767bf005b7d to your computer and use it in GitHub Desktop.
Save tamboer/8b8bafe92930267bdb39d767bf005b7d to your computer and use it in GitHub Desktop.
bash-shell-color-changer.sh
//https://askubuntu.com/questions/809590/automatically-get-different-terminal-colors-each-time-i-open-terminal
//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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment