Created
July 27, 2016 22:33
-
-
Save jedahan/a0ea60498e9f0fcbd942566a9b0c5647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hash() { | |
local sum=0 | |
primes=(1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191) | |
ord_period=$(printf '%d' "'.") | |
for i in {1..${#1}}; do | |
letter=${1[$i]} | |
ord=$(printf '%d' "'$letter") | |
sum=$(($sum + $primes[$i] * $primes[1 + $(($ord - $ord_period))])) | |
done | |
echo $sum | |
} | |
hostname_to_color() { | |
num_colors=$(echotc Co) | |
hostname_hash=$(prompt_geometry_hash_string ${HOST:u}) | |
echo $(($hostname_hash % $num_colors)) | |
} | |
RPROMPT="%F{$(hostname_to_color)}$(hostname)%f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment