Reimplement ZSH transient prompt
This commit is contained in:
parent
0cddc2fd46
commit
5030c18734
1 changed files with 53 additions and 0 deletions
53
.zshrc
53
.zshrc
|
@ -32,4 +32,57 @@ bindkey '^x^e' edit-command-line
|
||||||
# Load any kind of system-local stuff
|
# Load any kind of system-local stuff
|
||||||
[[ ! -f ~/.zshrc.local ]] || source ~/.zshrc.local
|
[[ ! -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)"
|
eval "$(starship init zsh)"
|
||||||
|
|
||||||
|
# Pull back to our transient prompt
|
||||||
|
# We call starship within the prompt function when warranted
|
||||||
|
PS1='$(_prompt)'
|
||||||
|
|
Loading…
Add table
Reference in a new issue