diff --git a/LICENSE b/LICENSE index e5df23c..3cb1cab 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2020 Alexandros Kozak +Copyright (c) 2017-2021 Alexandros Kozak Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index d0fcac4..a4e4205 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
Here are the latest features and updates. +- v3.10.0 + + The prompt is now fully compatible with ZSH's `promptinit` function. - v3.9.0 - The characters used to signify path abbreviation with `AGKOZAK_PROMPT_DIRTRIM` (`...` by default) can now be overridden with `AGKOZAK_PROMPT_DIRTRIM_STRING`. - v3.8.1 (November 23, 2020) @@ -125,6 +127,15 @@ And add the following to your `.zshrc` file: source /path/to/agkozak-zsh-prompt.plugin.zsh +### For [`promptinit`](https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Prompt-Themes) users + +ZSH comes with a built-in way of handling prompts, the `promptinit` function. You can load the agkozak ZSH prompt by running + + fpath+=( /path/to/agkozak-zsh-prompt ) # The directory where the prompt's + # files are kept + autoload promptinit; promptinit + prompt agkozak-zsh-prompt + ### For [antigen](https://github.com/zsh-users/antigen) users Add the line @@ -163,6 +174,14 @@ The prompt now supports `zinit`'s `unload` feature; you may restore the shell to zinit unload agkozak/agkozak-zsh-prompt +### For [Znap](https://github.com/marlonrichert/zsh-snap) users + +Simply put + + znap prompt agkozak/agkozak-zsh-prompt + +in your `.zshrc` somewhere after you source `znap.zsh`. + ### For [zplug](https://github.com/zplug/zplug) users Add the line diff --git a/agkozak-zsh-prompt.plugin.zsh b/agkozak-zsh-prompt.plugin.zsh index 919dd31..5e9ba6c 100644 --- a/agkozak-zsh-prompt.plugin.zsh +++ b/agkozak-zsh-prompt.plugin.zsh @@ -11,7 +11,7 @@ # # MIT License # -# Copyright (c) 2017-2020 Alexandros Kozak +# Copyright (c) 2017-2021 Alexandros Kozak # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -79,8 +79,8 @@ autoload -Uz is-at-least add-zle-hook-widget -# AGKOZAK is an associative array for storing internal information that is discarded when the -# prompt is unloaded. +# AGKOZAK is an associative array for storing internal information that is +# discarded when the prompt is unloaded. # # AGKOZAK[ASYNC_METHOD] Which asynchronous method is currently in use # AGKOZAK[FIRST_PROMPT_PRINTED] When AGKOZAK_BLANK_LINES=1, this variable @@ -134,10 +134,12 @@ AGKOZAK[FUNCTIONS]='_agkozak_debug_print _agkozak_usr1_async_worker TRAPUSR1 _agkozak_strip_colors - _agkozak_preexec - _agkozak_precmd + prompt_agkozak_preexec + prompt_agkozak_precmd _agkozak_prompt_strings - agkozak-zsh-prompt' + agkozak-zsh-prompt + prompt_agkozak-zsh-prompt_preview + prompt_agkozak-zsh-prompt_help' : ${AGKOZAK_PROMPT_DEBUG:=0} @@ -216,8 +218,6 @@ fi # Characters to put around the virtual environment name (default: square brackets) (( $+AGKOZAK_VIRTUALENV_CHARS )) || AGKOZAK_VIRTUALENV_CHARS=( '[' ']' ) -setopt PROMPT_SUBST NO_PROMPT_BANG - ###################################################################### # GENERAL FUNCTIONS ###################################################################### @@ -716,7 +716,7 @@ _agkozak_async_init() { else _agkozak_debug_print 'TRAPUSR1 has been redefined. Switching to subst-async mode.' AGKOZAK[ASYNC_METHOD]='subst-async' - _agkozak_precmd + prompt_agkozak_precmd fi } @@ -800,7 +800,7 @@ _agkozak_strip_colors() { # Runs right before each command is about to be executed. # Used to calculate command execution time. ############################################################ -_agkozak_preexec() { +prompt_agkozak_preexec() { typeset -gi AGKOZAK_CMD_START_TIME=$EPOCHSECONDS } @@ -819,7 +819,7 @@ _agkozak_preexec() { # AGKOZAK_BLANK_LINES # AGKOZAK_PROMPT_DIRTRIM ############################################################ -_agkozak_precmd() { +prompt_agkozak_precmd() { emulate -L zsh (( AGKOZAK_PROMPT_DEBUG )) && [[ $ZSH_VERSION != 5.0.[0-2] ]] && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL @@ -979,9 +979,11 @@ _agkozak_prompt_strings() { # AGKOZAK_PROMPT_DEBUG # AGKOZAK_PROMPT_DIRTRIM ############################################################ -agkozak-zsh-prompt() { - emulate -L zsh - (( AGKOZAK_PROMPT_DEBUG )) && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL +prompt_agkozak-zsh-prompt_setup() { + # `emulate -L zsh' has been removed for promptinit + # compatibility + prompt_opts=( percent subst ) + setopt NO_PROMPT_{BANG,CR,PERCENT,SUBST} "PROMPT_${^prompt_opts[@]}" _agkozak_async_init @@ -1002,8 +1004,8 @@ agkozak-zsh-prompt() { : else autoload -Uz add-zsh-hook - add-zsh-hook preexec _agkozak_preexec - add-zsh-hook precmd _agkozak_precmd + add-zsh-hook preexec prompt_agkozak_preexec + add-zsh-hook precmd prompt_agkozak_precmd fi # Only display the HOSTNAME for an SSH connection or for a superuser @@ -1037,7 +1039,22 @@ agkozak-zsh-prompt() { _agkozak_debug_print "Using async method: ${AGKOZAK[ASYNC_METHOD]}" } -agkozak-zsh-prompt +prompt_agkozak-zsh-prompt_setup + +############################################################ +# Preview function for promptinit +############################################################ + +prompt_agkozak-zsh-prompt_preview() { + print "No preview available. Try \`prompt agkozak-zsh-prompt'." +} + +############################################################ +# Help function for promptinit +############################################################ +prompt_agkozak-zsh-prompt_help() { + print 'For information about how to configure the agkozak-zsh-prompt, visit https://github.com/agkozak/agkozak-zsh-prompt.' | fold -s +} ############################################################ # Unload function @@ -1056,8 +1073,8 @@ agkozak-zsh-prompt_plugin_unload() { psvar=( $AGKOZAK_OLD_PSVAR ) - add-zsh-hook -D preexec _agkozak_preexec - add-zsh-hook -D precmd _agkozak_precmd + 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 diff --git a/prompt_agkozak-zsh-prompt_setup b/prompt_agkozak-zsh-prompt_setup new file mode 100644 index 0000000..88e0bdf --- /dev/null +++ b/prompt_agkozak-zsh-prompt_setup @@ -0,0 +1,3 @@ +#autoload +# Shim for promptinit compatibility +source "${${(%):-%x}:A:h}/agkozak-zsh-prompt.plugin.zsh"