From f8d708bc79ccfbec349e4bcc50eadd78acd659d8 Mon Sep 17 00:00:00 2001 From: Alexandros Kozak Date: Wed, 30 Dec 2020 15:20:54 -0800 Subject: [PATCH 1/4] Formatting --- agkozak-zsh-prompt.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agkozak-zsh-prompt.plugin.zsh b/agkozak-zsh-prompt.plugin.zsh index 919dd31..d143292 100644 --- a/agkozak-zsh-prompt.plugin.zsh +++ b/agkozak-zsh-prompt.plugin.zsh @@ -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 From 9a7438a01399c5abc8d614073f0660dca9213cfc Mon Sep 17 00:00:00 2001 From: Alexandros Kozak Date: Fri, 1 Jan 2021 16:40:25 -0800 Subject: [PATCH 2/4] Updated license --- LICENSE | 2 +- agkozak-zsh-prompt.plugin.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/agkozak-zsh-prompt.plugin.zsh b/agkozak-zsh-prompt.plugin.zsh index d143292..4d20904 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 From 58406506674e2354f12ea06305bd0e34220804e3 Mon Sep 17 00:00:00 2001 From: Alexandros Kozak Date: Sat, 8 May 2021 11:14:05 -0700 Subject: [PATCH 3/4] promptinit compatibility --- agkozak-zsh-prompt.plugin.zsh | 53 +++++++++++++++++++++++---------- prompt_agkozak-zsh-prompt_setup | 3 ++ 2 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 prompt_agkozak-zsh-prompt_setup diff --git a/agkozak-zsh-prompt.plugin.zsh b/agkozak-zsh-prompt.plugin.zsh index 4d20904..65d1f90 100644 --- a/agkozak-zsh-prompt.plugin.zsh +++ b/agkozak-zsh-prompt.plugin.zsh @@ -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,14 @@ _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() { + # promptinit compatibility + # TODO: rewrite function carefully now that emulate -L zsh has been removed + prompt_opts=( percent subst ) + setopt NO_PROMPT_{BANG,CR,PERCENT,SUBST} "PROMPT_${^prompt_opts[@]}" + + # emulate -L zsh + # (( AGKOZAK_PROMPT_DEBUG )) && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL _agkozak_async_init @@ -1002,8 +1007,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 +1042,23 @@ 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() { + # TODO: Write a real preview function if possible + 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 +1077,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" From 60f080b9251bc0637a2c50851350969031d8b002 Mon Sep 17 00:00:00 2001 From: Alexandros Kozak Date: Sat, 14 Aug 2021 09:41:15 -0700 Subject: [PATCH 4/4] promptinit compatibility --- README.md | 19 +++++++++++++++++++ agkozak-zsh-prompt.plugin.zsh | 10 +++------- 2 files changed, 22 insertions(+), 7 deletions(-) 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 65d1f90..5e9ba6c 100644 --- a/agkozak-zsh-prompt.plugin.zsh +++ b/agkozak-zsh-prompt.plugin.zsh @@ -980,14 +980,11 @@ _agkozak_prompt_strings() { # AGKOZAK_PROMPT_DIRTRIM ############################################################ prompt_agkozak-zsh-prompt_setup() { - # promptinit compatibility - # TODO: rewrite function carefully now that emulate -L zsh has been removed + # `emulate -L zsh' has been removed for promptinit + # compatibility prompt_opts=( percent subst ) setopt NO_PROMPT_{BANG,CR,PERCENT,SUBST} "PROMPT_${^prompt_opts[@]}" - # emulate -L zsh - # (( AGKOZAK_PROMPT_DEBUG )) && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL - _agkozak_async_init case ${AGKOZAK[ASYNC_METHOD]} in @@ -1049,8 +1046,7 @@ prompt_agkozak-zsh-prompt_setup ############################################################ prompt_agkozak-zsh-prompt_preview() { - # TODO: Write a real preview function if possible - print "No preview available. Try \`prompt agkozak-zsh-prompt\'." + print "No preview available. Try \`prompt agkozak-zsh-prompt'." } ############################################################