diff --git a/.zshrc b/.zshrc index 3046b09..d610d6d 100644 --- a/.zshrc +++ b/.zshrc @@ -32,4 +32,57 @@ bindkey '^x^e' edit-command-line # Load any kind of system-local stuff [[ ! -f ~/.zshrc.local ]] || source ~/.zshrc.local +# Transient prompt +_prompt () { + local retval=$? + + # Echo compact prompt + if (( $_vbe_prompt_compact )); then + echo '\e[32m\e[0m ' + return + fi + + # Echo main prompt + starship prompt +} +setopt prompt_subst + +_zle-line-init() { + [[ $CONTEXT == start ]] || return 0 + + # Start regular line editor + (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1] + zle .recursive-edit + local -i ret=$? + (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2] + + # If we received EOT, we exit the shell + if [[ $ret == 0 && $KEYS == $'\4' ]]; then + _vbe_prompt_compact=1 + zle .reset-prompt + exit + fi + + # Line edition is over. Shorten the current prompt. + _vbe_prompt_compact=1 + zle .reset-prompt + unset _vbe_prompt_compact + + if (( ret )); then + # Ctrl-C + zle .send-break + else + # Enter + zle .accept-line + fi + return ret +} + +zle -N zle-line-init _zle-line-init + +# Init starship eval "$(starship init zsh)" + +# Pull back to our transient prompt +# We call starship within the prompt function when warranted +PS1='$(_prompt)'