Skip to content

Instantly share code, notes, and snippets.

@sebble
Created May 4, 2016 20:16
Show Gist options
  • Save sebble/5e0a3ffdd83d5f0d475a158a5fcc447d to your computer and use it in GitHub Desktop.
Save sebble/5e0a3ffdd83d5f0d475a158a5fcc447d to your computer and use it in GitHub Desktop.
#!/bin/bash
# some utility functions (not used)
str256() { echo $((0x$(echo $1|md5sum|cut -c-4)%256)); }
str2color() { echo -e "\033[38;5;$(str256 "$1")m$1\033[00m"; }
# create a new host-colour file if not exists (allows manual override)
HOSTNAME_COLOUR_FILENAME="$HOME/.$(hostname)-colour"
test -f "$HOSTNAME_COLOUR_FILENAME" || \
echo $((0x$(hostname|md5sum|cut -c-4)%256)) > "$HOSTNAME_COLOUR_FILENAME"
# set new PS1
HOSTNAME_COLOUR=$(cat "$HOSTNAME_COLOUR_FILENAME")
PS1=$'\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]@\[$(tput bold)\]\[\033[38;5;${HOSTNAME_COLOUR}m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment