Set tmux status line color based on hostname

colorstmux

I'd like tmux to pick a color dynamically based on the hostname of the machine. Since I share my tmux.conf across several machines, assigning an unique color for each of those hosts would be handy visually, especially when working on more than one of the simultaneously. Is this doable?

Best Answer

I wanted this feature as well. I basically merged everything into this .tmux.conf

# cat <<__DATA__ >/dev/null
# Embed shell scripts

set -g status-utf8 on
set -g utf8 on

set -g default-terminal "screen-256color"

run "cut -c3- ~/.tmux.conf | bash -s apply_configuration"

# __DATA__
#
# apply_configuration() {
#    tmux set -g status-bg colour$(hash_string256 $(hostname))
# }
# hash_string256() {
#      hash_value=$(printf "%s" "$1" | md5sum | sed -e 's/[^[:alnum:]]\+//g' | tr "a-f" "A-F")
#      if [ "x" != "x$2" ]
#      then
#          v2="+ $2"
#      fi
#      echo "$(((0x$hash_value $v2) % 255))" | tr -d "-"
# }
# 
# $1

I removed using bc because I didn't have it in my git-bash. Thus I wanted it to work on both my linux systems and windows with cygwin without adding extra stuff.