mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
notify_on_cmd_finish: Show the actual command that was finished
Fixes #7420
This commit is contained in:
@@ -195,6 +195,22 @@ _ksi_main() {
|
||||
_ksi_prompt[ps0_suffix]+="\[\e[0 q\]" # blinking default cursor
|
||||
fi
|
||||
|
||||
_ksi_get_current_command() {
|
||||
builtin local last_cmd
|
||||
last_cmd=$(HISTTIMEFORMAT= builtin history 1)
|
||||
last_cmd="${last_cmd#*[[:digit:]]*[[:space:]]}" # remove leading history number
|
||||
last_cmd="${last_cmd#"${last_cmd%%[![:space:]]*}"}" # remove remaining leading whitespace
|
||||
if [[ "${_ksi_prompt[title]}" == "y" ]]; then
|
||||
builtin printf "\e]2;%s%s\a" "${_ksi_prompt[hostname_prefix]@P}" "${_ksi_prompt[last_cmd]//[[:cntrl:]]}" # remove any control characters
|
||||
fi
|
||||
if [[ "${_ksi_prompt[mark]}" == "y" ]]; then
|
||||
builtin printf "\e]133;C;cmdline="
|
||||
for (( i=0; i<${#last_cmd}; i++ )); do builtin printf '%x ' "'${last_cmd:$i:1}"; done
|
||||
builtin printf "\a"
|
||||
fi
|
||||
}
|
||||
if [[ "${_ksi_prompt[title]}" == "y" || "${_ksi_prompt[mark]}" ]]; then _ksi_prompt[ps0]+='$(_ksi_get_current_command)'; fi
|
||||
|
||||
if [[ "${_ksi_prompt[title]}" == "y" ]]; then
|
||||
if [[ -z "$KITTY_PID" ]]; then
|
||||
if [[ -n "$SSH_TTY" || -n "$SSH2_TTY$KITTY_WINDOW_ID" ]]; then
|
||||
@@ -212,22 +228,16 @@ _ksi_main() {
|
||||
# we use suffix here because some distros add title setting to their bashrc files by default
|
||||
_ksi_prompt[ps1_suffix]+="\[\e]2;${_ksi_prompt[hostname_prefix]}\w\a\]"
|
||||
if [[ "$HISTCONTROL" == *"ignoreboth"* ]] || [[ "$HISTCONTROL" == *"ignorespace"* ]]; then
|
||||
_ksi_debug_print "ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command in window title will not be robust"
|
||||
_ksi_debug_print "ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command will not be robust"
|
||||
fi
|
||||
_ksi_get_current_command() {
|
||||
builtin local last_cmd
|
||||
last_cmd=$(HISTTIMEFORMAT= builtin history 1)
|
||||
last_cmd="${last_cmd#*[[:digit:]]*[[:space:]]}" # remove leading history number
|
||||
last_cmd="${last_cmd#"${last_cmd%%[![:space:]]*}"}" # remove remaining leading whitespace
|
||||
builtin printf "\e]2;%s%s\a" "${_ksi_prompt[hostname_prefix]@P}" "${last_cmd//[[:cntrl:]]}" # remove any control characters
|
||||
}
|
||||
_ksi_prompt[ps0_suffix]+='$(_ksi_get_current_command)'
|
||||
fi
|
||||
|
||||
if [[ "${_ksi_prompt[mark]}" == "y" ]]; then
|
||||
_ksi_prompt[ps1]+="\[\e]133;A\a\]"
|
||||
# this can result in multiple D prompt marks or ones that dont
|
||||
# correspond to a cmd but kitty handles this gracefully, only
|
||||
# taking into account the first D after a C.
|
||||
_ksi_prompt[ps1]+="\[\e]133;D;\$?\a\e]133;A\a\]"
|
||||
_ksi_prompt[ps2]+="\[\e]133;A;k=s\a\]"
|
||||
_ksi_prompt[ps0]+="\[\e]133;C\a\]"
|
||||
fi
|
||||
|
||||
builtin alias edit-in-kitty="kitten edit-in-kitty"
|
||||
|
||||
@@ -88,7 +88,7 @@ function __ksi_schedule --on-event fish_prompt -d "Setup kitty integration after
|
||||
|
||||
function __ksi_mark_output_start --on-event fish_preexec
|
||||
set --global __ksi_prompt_state pre-exec
|
||||
echo -en "\e]133;C\a"
|
||||
printf '\e]133;C;cmdline_url=%s\a' (string escape --style=url -- "$argv")
|
||||
end
|
||||
|
||||
function __ksi_mark_output_end --on-event fish_postexec
|
||||
|
||||
@@ -215,7 +215,9 @@ _ksi_deferred_init() {
|
||||
# its preexec hook before us, we'll incorrectly mark its output as
|
||||
# belonging to the command (as if the user typed it into zle) rather
|
||||
# than command output.
|
||||
builtin print -nu $_ksi_fd '\e]133;C\a'
|
||||
builtin print -nu "$_ksi_fd" '\e]133;C;cmdline='
|
||||
for (( i=0; i<${#1}; i++ )); do builtin print -nu "$_ksi_fd" -f '%x ' "'${1:$i:1}"; done
|
||||
builtin print -nu "$_ksi_fd" '\a'
|
||||
(( _ksi_state = 1 ))
|
||||
}
|
||||
|
||||
@@ -401,9 +403,9 @@ _ksi_deferred_init() {
|
||||
[[ "$arg" != -* && "$arg" != *=* ]] && builtin break # command found
|
||||
done
|
||||
if [[ "$is_sudoedit" == "y" ]]; then
|
||||
builtin command sudo "$@";
|
||||
else
|
||||
builtin command sudo TERMINFO="$TERMINFO" "$@";
|
||||
builtin command sudo "$@";
|
||||
else
|
||||
builtin command sudo TERMINFO="$TERMINFO" "$@";
|
||||
fi
|
||||
}
|
||||
fi
|
||||
@@ -411,8 +413,8 @@ _ksi_deferred_init() {
|
||||
|
||||
# Map alt+left/right to move by word if not already mapped. This is expected behavior on macOS and I am tired
|
||||
# of answering questions about it.
|
||||
[[ $(builtin bindkey "^[[1;3C") == *" undefined-key" ]] && builtin bindkey "^[[1;3C" "forward-word"
|
||||
[[ $(builtin bindkey "^[[1;3D") == *" undefined-key" ]] && builtin bindkey "^[[1;3D" "backward-word"
|
||||
[[ $(builtin bindkey "^[[1;3C") == *" undefined-key" ]] && builtin bindkey "^[[1;3C" "forward-word"
|
||||
[[ $(builtin bindkey "^[[1;3D") == *" undefined-key" ]] && builtin bindkey "^[[1;3D" "backward-word"
|
||||
|
||||
# Unfunction _ksi_deferred_init to save memory. Don't unfunction
|
||||
# kitty-integration though because decent public functions aren't supposed to
|
||||
|
||||
Reference in New Issue
Block a user