Eu vim com a seguinte função shell:
hash_string256() {
# Hash $1 into a number
hash_value=$(printf "%s" "$1" | md5sum |tr -d " -"| tr "a-f" "A-F")
# Add the hash with $2 and modulo 256 the result
# if $2 == "" it is 0
printf "ibase=16; (%s + %X) %% 100\n" $hash_value "$2" | bc
}
Esta função pode ser usada assim (os resultados são verdadeiros, se $HOSThouver LOL):
$hash_string256 $HOST
113
$hash_string256 $HOST 127
240
Para conectá-lo, tmuxvocê pode usar um script que inicia e configura tmux.
#!/bin/sh
SESSION=$USER
hash_string256() {
hash_value=$(printf "%s" "$1" | md5sum |tr -d " -"| tr "a-f" "A-F")
printf "ibase=16; (%s + %X) %% 100 \n" $hash_value "$2" | bc
}
tmux -2 new-session -d -s $SESSION
tmux set -g status-fg colour$(hash_string256 $HOST)
tmux set -g status-bg colour$(hash_string256 $HOST 127)
# Attach to session
tmux -2 attach-session -t $SESSION
Para o nome do host, LOLele definiria status-fgpara colour113e status-bgpara colour240. O número 127 in $(hash_string256 $HOST 127)está lá, portanto o plano de fundo não será o mesmo que a cor do primeiro plano e estará um distante do outro.
Para nenhum sistema GNU
Se o seu sistema tiver em md5vez da md5sumlinha
hash_value=$(printf "%s" "$1" | md5sum |tr -d " -"| tr "a-f" "A-F")
pode ser substituído por
hash_value=$(printf "%s" "$1" | md5 | tr "a-f" "A-F")
.tmux.confeu consegui"cut -c3- ~/.tmux.conf | bash -s apply_configuration" returned 1. No entanto, minha barra de status ficou vermelha !!!