Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Sep 10, 2021
2 parents 0425524 + 73bcbd9 commit 072e7a5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
<details>
<summary>Here are the latest features and updates.</summary>

- v3.10.1
+ The prompt now supports `promptinit`'s `prompt_cleanup` function.
- v3.10.0
+ The prompt is now fully compatible with ZSH's `promptinit` function.
- v3.9.0
Expand Down
58 changes: 50 additions & 8 deletions agkozak-zsh-prompt.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,34 @@ AGKOZAK[FUNCTIONS]='_agkozak_debug_print
prompt_agkozak_preexec
prompt_agkozak_precmd
_agkozak_prompt_strings
agkozak-zsh-prompt
prompt_agkozak-zsh-prompt_preview
prompt_agkozak-zsh-prompt_help'

prompt_agkozak-zsh-prompt_help
_agkozak_prompt_cleanup'

# Some global declarations
typeset -g AGKOZAK_PROMPT_DEBUG \
AGKOZAK_COLORS_EXIT_STATUS \
AGKOZAK_COLORS_USER_HOST \
AGKOZAK_COLORS_PATH \
AGKOZAK_COLORS_BRANCH_STATUS \
AGKOZAK_COLORS_PROMPT_CHAR \
AGKOZAK_COLORS_CMD_EXEC_TIME \
AGKOZAK_COLORS_VIRTUALENV \
AGKOZAK_LEFT_PROMPT_ONLY \
AGKOZAK_MULTILINE \
AGKOZAK_NAMED_DIRS \
AGKOZAK_PROMPT_DIRTRIM \
AGKOZAK_PROMPT_DIRTRIM_STRING \
AGKOZAK_SHOW_STASH \
AGKOZAK_USER_HOST_DISPLAY \
AGKOZAK_CMD_EXEC_TIME \
AGKOZAK_BLANK_LINES \
AGKOZAK_SHOW_VIRTUALENV

typeset -ga AGKOZAK_CMD_EXEC_TIME_CHARS \
AGKOZAK_VIRTUALENV_CHARS

# Set AGKOZAK_PROMPT_DEBUG=1 for debugging mode
: ${AGKOZAK_PROMPT_DEBUG:=0}

############################################################
Expand All @@ -162,12 +186,9 @@ _agkozak_debug_print() {

if (( AGKOZAK_PROMPT_DEBUG )); then
if is-at-least 5.4.0; then
for x in ${=AGKOZAK[FUNCTIONS]}; do
# Enable WARN_CREATE_GLOBAL for each function of the prompt
functions -W $x
done
# Enable WARN_CREATE_GLOBAL for each function of the prompt
functions -W ${=AGKOZAK[FUNCTIONS][@]}
fi
unset x
fi

# Putting these default options here makes sure that the variables are in the
Expand Down Expand Up @@ -982,6 +1003,7 @@ _agkozak_prompt_strings() {
prompt_agkozak-zsh-prompt_setup() {
# `emulate -L zsh' has been removed for promptinit
# compatibility
typeset -g prompt_opts
prompt_opts=( percent subst )
setopt NO_PROMPT_{BANG,CR,PERCENT,SUBST} "PROMPT_${^prompt_opts[@]}"

Expand Down Expand Up @@ -1036,6 +1058,10 @@ prompt_agkozak-zsh-prompt_setup() {
(( $+VSCODE_PID )) && ZLE_RPROMPT_INDENT=6
fi

# For promptinit
(( ${+functions[prompt_cleanup]} )) &&
prompt_cleanup _agkozak_prompt_cleanup

_agkozak_debug_print "Using async method: ${AGKOZAK[ASYNC_METHOD]}"
}

Expand Down Expand Up @@ -1092,4 +1118,20 @@ agkozak-zsh-prompt_plugin_unload() {
unfunction $0
}

############################################################
# promptinit cleanup function
############################################################
_agkozak_prompt_cleanup() {
setopt LOCAL_OPTIONS NO_KSH_ARRAYS NO_SH_WORD_SPLIT

add-zsh-hook -D preexec prompt_agkozak_preexec
add-zsh-hook -D precmd prompt_agkozak_precmd

if is-at-least 5.3; then
add-zle-hook-widget -D zle-keymap-select _agkozak_zle-keymap-select
else
zle -D _agkozak_zle-keymap_select
fi
}

# vim: ts=2:et:sts=2:sw=2:

0 comments on commit 072e7a5

Please sign in to comment.