Use PS1 to set the prompt start mark
Needed as precmd functions are not called when redrawing the prompt. As far as I can tell zsh stupidly has no hook that is called when the prompt is redrawn after a window resize or when a background job finishes.
This commit is contained in:
parent
a4925eeeb4
commit
85f6d3fed8
@ -41,22 +41,18 @@ args=($@)
|
|||||||
zle -N zle-keymap-select kitty_zle_keymap_select
|
zle -N zle-keymap-select kitty_zle_keymap_select
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function mark() {
|
function osc() {
|
||||||
# tell kitty to mark the current cursor position using OSC 133
|
printf "\e]%s\a" "$1"
|
||||||
printf "\e]133;%s\e\\" "$1"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_title_precmd () {
|
function mark() {
|
||||||
# Set kitty window title to the cwd
|
# tell kitty to mark the current cursor position using OSC 133
|
||||||
if [[ "$kitty_prompt_title" == "y" ]]; then
|
osc "133;$1"
|
||||||
printf "\e]2;%s\007" "${PWD/$HOME/~}"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
function set_title_preexec() {
|
typeset -g kitty_prompt_start_mark="%{$(mark A)%}"
|
||||||
# Set kitty window title to the currently executing command
|
|
||||||
if [[ "$kitty_prompt_title" == "y" ]]; then
|
function set_title() {
|
||||||
printf "\e]2;%s\a" "$1"
|
if [[ "$kitty_prompt_title" == "y" ]]; then osc "2;$1"; fi
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function kitty_precmd() {
|
function kitty_precmd() {
|
||||||
@ -67,14 +63,18 @@ args=($@)
|
|||||||
compdef _kitty kitty
|
compdef _kitty kitty
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
set_title_precmd
|
# 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"
|
mark "D;$cmd_status"
|
||||||
else
|
else
|
||||||
if [[ "$kitty_prompt_state" != "first-run" ]]; then mark "D"; fi
|
if [[ "$kitty_prompt_state" != "first-run" ]]; then mark "D"; fi
|
||||||
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"
|
kitty_prompt_state="precmd"
|
||||||
mark "A"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function kitty_zle_line_init() {
|
function kitty_zle_line_init() {
|
||||||
@ -104,8 +104,11 @@ args=($@)
|
|||||||
|
|
||||||
function kitty_preexec() {
|
function kitty_preexec() {
|
||||||
mark "C"
|
mark "C"
|
||||||
set_title_preexec "$1"
|
# 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/}"
|
||||||
}
|
}
|
||||||
|
|
||||||
typeset -a -g precmd_functions
|
typeset -a -g precmd_functions
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user