From d1dd69b5150dd5c362f11d31a88478a43d96ea69 Mon Sep 17 00:00:00 2001 From: Massaki Archambault Date: Thu, 25 Oct 2018 18:08:31 -0400 Subject: [PATCH] color prompt by hostname --- files/.config/zsh/custom/000-env.zsh | 2 ++ files/.config/zsh/custom/themes/custom.zsh-theme | 12 ++++++++---- files/.local/bin/motd | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/files/.config/zsh/custom/000-env.zsh b/files/.config/zsh/custom/000-env.zsh index 968b8ac..d17157c 100644 --- a/files/.config/zsh/custom/000-env.zsh +++ b/files/.config/zsh/custom/000-env.zsh @@ -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)")" diff --git a/files/.config/zsh/custom/themes/custom.zsh-theme b/files/.config/zsh/custom/themes/custom.zsh-theme index d76d6d9..924aefd 100644 --- a/files/.config/zsh/custom/themes/custom.zsh-theme +++ b/files/.config/zsh/custom/themes/custom.zsh-theme @@ -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/~}" diff --git a/files/.local/bin/motd b/files/.local/bin/motd index c4d665c..e452b05 100755 --- a/files/.local/bin/motd +++ b/files/.local/bin/motd @@ -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'