Last active
December 30, 2015 17:09
-
-
Save piger/7858892 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
# assign a prompt color by hashing the letters of the hostname | |
# idea copied from the irssi script 'nickcolor.pl' | |
# Daniel Kertesz <[email protected]> | |
autoload -U colors | |
colors | |
setopt prompt_subst | |
colnames=( | |
black | |
red | |
green | |
yellow | |
blue | |
magenta | |
cyan | |
white | |
default | |
) | |
# Create color variables for foreground and background colors | |
for color in $colnames; do | |
eval f$color='%{${fg[$color]}%}' | |
eval b$color='%{${bg[$color]}%}' | |
done | |
# Hash the hostname and return a fixed "random" color | |
function _hostname_color() { | |
local chash=0 | |
foreach letter ( ${(ws::)HOST[(ws:.:)1]} ) | |
(( chash += #letter )) | |
end | |
local crand=$(( $chash % $#colnames )) | |
local crandname=$colnames[$crand] | |
echo "%{${fg[$crandname]}%}" | |
} | |
hostname_color=$(_hostname_color) | |
PROMPT='${hostname_color}%n${fdefault}@${hostname_color}%m${fdefault} %# ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment