You might be interested in context-color
, which I've put together for that exact purpose: https://github.com/ramnes/context-color
It's a simple script that, when executed, outputs a color based on a command output's hash. With it installed somewhere in your $PATH
, you could do something like this in your .bashrc
:
export PS1="$(context-color -p)$PS1\[\e[0m\]"
(where --prompt/-p
is the switch so that the color is escaped for prompts, and \[\e[0m\]
the escape sequence to reset color)
By default, the command used to generate the hash is whoami; hostname
. If you just want the color to change according to the hostname, you can change the $CONTEXT
variable environment (export CONTEXT="hostname"
) or simply use the --context/-c
option (context-color -c "hostname"
).
See below for an example:
