From a0209264b52e2a2ed34a30d323d37a68a45a6ef3 Mon Sep 17 00:00:00 2001 From: Christian Baer Date: Mon, 10 Jun 2024 23:17:26 +0200 Subject: [PATCH] ZSH: Updated prompt --- .config/zsh/lib/30-prompt.zsh | 38 ++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/.config/zsh/lib/30-prompt.zsh b/.config/zsh/lib/30-prompt.zsh index 92bab40..41008c9 100644 --- a/.config/zsh/lib/30-prompt.zsh +++ b/.config/zsh/lib/30-prompt.zsh @@ -11,12 +11,44 @@ p_host='%F{blue}%m%f' ## Print path in yellow p_path='%F{yellow}%~%f' ## Print prompt sign in red if the previous command retunend and error, otherwise print it in white -p_pr='%(?.%F{white}.%F{red}) %B〉%b%f' +p_pr='%(?.%F{magenta}.%F{red})%B〉%b%f%' # Add green arrows (⇣⇡) if connection is via ssh if [[ "${SSH_CONNECTION}" ]]; then p_ssh=" %F{green}⇣⇡%f"; fi; -PS1="$p_user$p_at$p_host$p_ssh $p_path$p_pr" -unset p_at p_user p_host p_path p_pr \ No newline at end of file +# Transient prompt based on https://github.com/romkatv/powerlevel10k/issues/888#issuecomment-657969840 +zle-line-init() { + emulate -L zsh + + [[ $CONTEXT == start ]] || return 0 + + while true; do + zle .recursive-edit + local -i ret=$? + [[ $ret == 0 && $KEYS == $'\4' ]] || break + [[ -o ignore_eof ]] || exit 0 + done + + local saved_prompt=$PROMPT + local saved_rprompt=$RPROMPT + PROMPT='${nl}$p_pr ' + RPROMPT='' + zle .reset-prompt + PROMPT=$saved_prompt + RPROMPT=$saved_rprompt + + if (( ret )); then + zle .send-break + else + zle .accept-line + fi + return ret +} + +zle -N zle-line-init + +nl=$'\n' +PS1="${nl}$p_user$p_at$p_host$p_ssh $p_path${nl}$p_pr" +#unset p_at p_user p_host p_path p_pr \ No newline at end of file