Singify ssh/chroot prompt

This commit is contained in:
ItsDrike 2021-04-20 08:29:47 +02:00
parent 6c9585a4bf
commit 085c9d8629
No known key found for this signature in database
GPG key ID: B5F6B41F708C3ADD

View file

@ -12,6 +12,7 @@ LBLUE="%F{075}"
PURPLE="%F{105}"
RESET="%f"
# Signals git status of CWD repository (if any)
git_prompt() {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
echo -n " $ORANGE${ref#refs/heads/}"
@ -21,12 +22,23 @@ git_prompt() {
fi
}
# Adds @chroot or @ssh
foreign_prompt() {
if [ "$(awk '$5=="/" {print $1}' </proc/1/mountinfo)" != "$(awk '$5=="/" {print $1}' </proc/$$/mountinfo)" ]; then
echo -n "@${ORANGE}chroot"
fi
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
echo -n "@${ORANGE}ssh"
fi
}
setopt promptsubst # enable command substitution in prompt
# Primary Prompt
[ "$EUID" -eq 0 ] && PS1="$RED%n$RESET" || PS1="$GREEN%n$RESET" # user@machine
[ "$EUID" -eq 0 ] && PS1="$RED%n$RESET" || PS1="$GREEN%n$RESET" # user
PS1+="$(foreign_prompt)"
#PS1+=" $BLUE%~" # Working directory
PS1+=" $BLUE%(5~|%-1~/…/%3~|%4~)"
PS1+=" $BLUE%(5~|%-1~/…/%3~|%4~)" # Shortened working directory
PS1+="\$(git_prompt)"
PS1+=" $PURPLE%(!.#.»)$RESET " # Final symbol (# or »)
@ -36,7 +48,4 @@ PS2="$RED\ $RESET"
# Right side prompt (on error)
RPS1="%(?..$RED%? ↵$RESET)"
# SSH Prompt
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
PS1="$PURPLE(ssh) $RESET${PS1}"
fi