Use an associative array for prompt data
This commit is contained in:
parent
d1015de700
commit
2e5308ad40
@ -4,12 +4,10 @@ args=($@)
|
||||
() {
|
||||
if [[ ! -o interactive ]]; then return; fi
|
||||
|
||||
typeset -g kitty_prompt_state="first-run"
|
||||
typeset -g kitty_prompt_cursor="y"
|
||||
typeset -g kitty_prompt_title="y"
|
||||
typeset -g -A kitty_prompt=([state]='first-run' [cursor]='y' [title]='y')
|
||||
|
||||
(( ${args[(I)no-cursor]} )) && kitty_prompt_cursor="n"
|
||||
(( ${args[(I)no-title]} )) && kitty_prompt_title="n"
|
||||
(( ${args[(I)no-cursor]} )) && kitty_prompt[cursor]="n"
|
||||
(( ${args[(I)no-title]} )) && kitty_prompt[title]="n"
|
||||
|
||||
function debug() {
|
||||
# print a line to STDOUT of parent kitty process
|
||||
@ -19,14 +17,16 @@ args=($@)
|
||||
|
||||
function change-cursor-shape () {
|
||||
# change cursor shape depending on mode
|
||||
if [[ "$kitty_prompt_cursor" == "y" ]]; then
|
||||
if [[ "$KEYMAP" == vicmd ]]; then
|
||||
# the command mode for vi
|
||||
printf "\e[2 q" # blinking block cursor
|
||||
else
|
||||
# the insert mode for vi
|
||||
printf "\e[5 q" # blinking bar cursor
|
||||
fi
|
||||
if [[ "$kitty_prompt[cursor]" == "y" ]]; then
|
||||
case $KEYMAP in
|
||||
vicmd | visual)
|
||||
# the command mode for vi
|
||||
printf "\e[2 q" # blinking block cursor
|
||||
;;
|
||||
*)
|
||||
printf "\e[5 q" # blinking bar cursor
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
@ -49,15 +49,15 @@ args=($@)
|
||||
# tell kitty to mark the current cursor position using OSC 133
|
||||
osc "133;$1"
|
||||
}
|
||||
typeset -g kitty_prompt_start_mark="%{$(mark A)%}"
|
||||
kitty_prompt[start_mark]="%{$(mark A)%}"
|
||||
|
||||
function set_title() {
|
||||
if [[ "$kitty_prompt_title" == "y" ]]; then osc "2;$1"; fi
|
||||
if [[ "$kitty_prompt[title]" == "y" ]]; then osc "2;$1"; fi
|
||||
}
|
||||
|
||||
function kitty_precmd() {
|
||||
local cmd_status=$?
|
||||
if [[ "$kitty_prompt_state" == "first-run" ]]; then
|
||||
if [[ "$kitty_prompt[state]" == "first-run" ]]; then
|
||||
# compdef is only defined if compinit has been called
|
||||
if whence compdef > /dev/null; then
|
||||
compdef _kitty kitty
|
||||
@ -65,22 +65,22 @@ args=($@)
|
||||
fi
|
||||
# Set kitty window title to the cwd
|
||||
set_title "${PWD/$HOME/~}"
|
||||
if [[ "$kitty_prompt_state" == "preexec" ]]; then
|
||||
if [[ "$kitty_prompt[state]" == "preexec" ]]; then
|
||||
mark "D;$cmd_status"
|
||||
else
|
||||
if [[ "$kitty_prompt_state" != "first-run" ]]; then mark "D"; fi
|
||||
if [[ "$kitty_prompt[state]" != "first-run" ]]; then mark "D"; fi
|
||||
fi
|
||||
# we must use PS1 to set the prompt start mark as precmd functions are
|
||||
# not called when the prompt is redrawn after a window resize or when a background
|
||||
# job finishes
|
||||
if [[ "$PS1" != *"$kitty_prompt_start_mark"* ]]; then PS1="$kitty_prompt_start_mark$PS1" fi
|
||||
kitty_prompt_state="precmd"
|
||||
if [[ "$PS1" != *"$kitty_prompt[start_mark]"* ]]; then PS1="$kitty_prompt[start_mark]$PS1" fi
|
||||
kitty_prompt[state]="precmd"
|
||||
}
|
||||
|
||||
function kitty_zle_line_init() {
|
||||
mark "B"
|
||||
change-cursor-shape;
|
||||
kitty_prompt_state="line-init"
|
||||
kitty_prompt[state]="line-init"
|
||||
}
|
||||
function kitty_zle_line_init_with_orginal() { zle kitty-zle-line-init-original; kitty_zle_line_init }
|
||||
zle -A zle-line-init kitty-zle-line-init-original 2>/dev/null
|
||||
@ -92,7 +92,7 @@ args=($@)
|
||||
|
||||
function kitty_zle_line_finish() {
|
||||
change-cursor-shape;
|
||||
kitty_prompt_state="line-finish"
|
||||
kitty_prompt[state]="line-finish"
|
||||
}
|
||||
function kitty_zle_line_finish_with_orginal() { zle kitty-zle-line-finish-original; kitty_zle_line_finish }
|
||||
zle -A zle-line-finish kitty-zle-line-finish-original 2>/dev/null
|
||||
@ -106,9 +106,9 @@ args=($@)
|
||||
mark "C"
|
||||
# Set kitty window title to the currently executing command
|
||||
set_title "$1"
|
||||
kitty_prompt_state="preexec"
|
||||
kitty_prompt[state]="preexec"
|
||||
# remove the prompt mark sequence while the command is executing as it could read/modify the value of PS1
|
||||
PS1="${PS1//$kitty_prompt_start_mark/}"
|
||||
PS1="${PS1//$kitty_prompt[start_mark]/}"
|
||||
}
|
||||
|
||||
typeset -a -g precmd_functions
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user