agnoster: use %n instead of $USER to fix quoting

Fixes #7268

With `$USER`, we'd need to quote it in case special characters like `\` are present in
the $USER value, like if the user is part of an AD domain.

With `%n` the quoting is done automatically by zsh.
See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Login-information
This commit is contained in:
Marc Cornellà 2018-10-17 20:53:07 +02:00 committed by GitHub
parent ea7b886f70
commit 2fce9a4d44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -89,7 +89,7 @@ prompt_end() {
# Context: user@hostname (who am I and where am I) # Context: user@hostname (who am I and where am I)
prompt_context() { prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m" prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
fi fi
} }