Color zsh prompt depending on shell

Make yellow if within nix subshell.
Allows to run nix-shell --run zsh to have a zsh shell within nix shell.
Default shell is kept blue.
This commit is contained in:
Daniel Siepmann 2023-02-18 11:19:29 +01:00
parent c8b7b18575
commit ca56b18b8f
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4

View file

@ -50,9 +50,19 @@ setopt list_packed
setopt list_types
# Set Prompt
# Allow for functions in the prompt.
setopt PROMPT_SUBST
PROMPT=$'%{$fg[blue]%}%1~ > %{$reset_color%}'
autoload -Uz add-zsh-hook
setopt promptsubst
nix_subshell () {
prompt_color="blue"
# check for IN_NIX_SHELL
if [[ "$IN_NIX_SHELL" ]]; then
prompt_color="yellow"
fi
}
add-zsh-hook precmd nix_subshell
PROMPT=$'%{$fg[${prompt_color}]%}%1~ > %{$reset_color%}'
zstyle ':completion:*:descriptions' format '%F{blue}-- %d --%f'
zstyle ':completion:*:messages' format ' %F{purple} -- %d --%f'