1
0
Fork 0

color prompt by hostname

This commit is contained in:
Massaki Archambault 2018-10-25 18:08:31 -04:00
parent b4f3a5ad42
commit d1dd69b515
3 changed files with 13 additions and 5 deletions

View File

@ -23,3 +23,5 @@ export IS_ROOT
export GPG_TTY=$(tty)
gpg-connect-agent updatestartuptty /bye >/dev/null
# Color
export ZSH_THEME_HOSTNAME_COLOR="$(printf "%03d" "$(hostname | md5sum | head -c2)")"

View File

@ -1,8 +1,13 @@
setopt prompt_subst # enable command substitution in prompt
# enable command substitution in prompt
setopt prompt_subst
PROMPT='$(prompt_cmd)'
RPROMPT=''
[[ -v ZSH_THEME_HOSTNAME_COLOR ]] || ZSH_THEME_HOSTNAME_COLOR="$(printf "%03d" "$(hostname | md5sum | head -c2)")"
# we export this for motd
export ZSH_THEME_HOSTNAME_COLOR
ZSH_THEME_GIT_PROMPT_PREFIX="%{$FG[008]%} on %{$fg[cyan]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX=""
@ -46,12 +51,11 @@ prompt_cmd() {
fi
# name@hostname
local default_color="green"
local user_color="$default_color"
local user_color="$ZSH_THEME_HOSTNAME_COLOR"
if __is_root; then
local user_color="red"
fi
local name_hostname="%{$fg[$user_color]%}$USER%{$fg[$default_color]%}@%m"
local name_hostname="%{$FG[$user_color]%}$USER%{$FG[$ZSH_THEME_HOSTNAME_COLOR]%}@%m"
# working directory
local wd_base="${PWD/$HOME/~}"

View File

@ -33,6 +33,8 @@ class Termutils:
GREY = '\33[30;1m'
DISABLE = '\033[0m'
HOSTNAME_COLOR = '\033[38;5;%sm' % os.environ.get('ZSH_THEME_HOSTNAME_COLOR', '004')
PADDING = ' '
@staticmethod
@ -71,7 +73,7 @@ def to_gb(bytes_count):
def print_hostname():
print(
Termutils.CYAN
Termutils.HOSTNAME_COLOR
+ figlet_format(os.uname()[1], 'slant')
+ Termutils.DISABLE
+ '\n'