Skip to content

Instantly share code, notes, and snippets.

@smuuf
Created December 19, 2018 23:02
Show Gist options
  • Save smuuf/d1aba3088b174e23b0cde03d4f3213c0 to your computer and use it in GitHub Desktop.
Save smuuf/d1aba3088b174e23b0cde03d4f3213c0 to your computer and use it in GitHub Desktop.
# Sets the color of next text output to be a random color based on hostname's md5 hash.
# (If the terminal supports true colour (RGB) colors.)
set_host_based_color() {
HOSTHASH=$(hostname | md5sum)
printf "\x1b[38;2;%d;%d;%dm" 0x${HOSTHASH:0:2} 0x${HOSTHASH:2:2} 0x${HOSTHASH:4:2}
}
# Example usage:
# PS1="[\$(set_host_based_color)\$(hostname)\033[0m]: "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment