7
1
I like to make sure I'm logged into the right host by having a specific color for each host. I copy my .bashrc
around to different hosts, and edit it with a different color for each one.
However, I would like to not have to manually edit the color on each host, but instead automatically populate the colors for my bash prompt on each host, with a distinctive one for each hostname.
I'm imagining a command in .bashrc
that gets the hostname, turns it into a unique color, and sets it to be the bash prompt color.
Question: How can I hash the hostname into a color in bash?
It might even make a judgment about the set of reasonable colors based on the terminal background color.
Just write a
case
statement on the contents ofhostname
(which means you have to edit your .bashrc once with an entry for each host, but then you can copy it to all hosts). Making a "reasonable" choice automatically isn't trivial (what colors look well on what background is an art), and you will probably not like the result. But of course you can hash the hostname in some way and use this as a color. – dirkt – 2016-09-13T06:00:18.923Again, you might not like the result, but it would be relatively trivial to hash the first or last 3 figures of the IP address, straight to RGB. – Tetsujin – 2016-09-13T07:45:34.023