Skip to content

Commit 0425524

Browse files
committed
Merge branch 'develop'
2 parents b6106d9 + 60f080b commit 0425524

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017-2020 Alexandros Kozak
3+
Copyright (c) 2017-2021 Alexandros Kozak
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ This prompt has been tested on numerous Linux and BSD distributions, as well as
5656
<details>
5757
<summary>Here are the latest features and updates.</summary>
5858

59+
- v3.10.0
60+
+ The prompt is now fully compatible with ZSH's `promptinit` function.
5961
- v3.9.0
6062
- The characters used to signify path abbreviation with `AGKOZAK_PROMPT_DIRTRIM` (`...` by default) can now be overridden with `AGKOZAK_PROMPT_DIRTRIM_STRING`.
6163
- v3.8.1 (November 23, 2020)
@@ -125,6 +127,15 @@ And add the following to your `.zshrc` file:
125127

126128
source /path/to/agkozak-zsh-prompt.plugin.zsh
127129

130+
### For [`promptinit`](https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Prompt-Themes) users
131+
132+
ZSH comes with a built-in way of handling prompts, the `promptinit` function. You can load the agkozak ZSH prompt by running
133+
134+
fpath+=( /path/to/agkozak-zsh-prompt ) # The directory where the prompt's
135+
# files are kept
136+
autoload promptinit; promptinit
137+
prompt agkozak-zsh-prompt
138+
128139
### For [antigen](https://github.com/zsh-users/antigen) users
129140

130141
Add the line
@@ -163,6 +174,14 @@ The prompt now supports `zinit`'s `unload` feature; you may restore the shell to
163174

164175
zinit unload agkozak/agkozak-zsh-prompt
165176

177+
### For [Znap](https://github.com/marlonrichert/zsh-snap) users
178+
179+
Simply put
180+
181+
znap prompt agkozak/agkozak-zsh-prompt
182+
183+
in your `.zshrc` somewhere after you source `znap.zsh`.
184+
166185
### For [zplug](https://github.com/zplug/zplug) users
167186

168187
Add the line

agkozak-zsh-prompt.plugin.zsh

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# MIT License
1313
#
14-
# Copyright (c) 2017-2020 Alexandros Kozak
14+
# Copyright (c) 2017-2021 Alexandros Kozak
1515
#
1616
# Permission is hereby granted, free of charge, to any person obtaining a copy
1717
# of this software and associated documentation files (the "Software"), to deal
@@ -79,8 +79,8 @@
7979

8080
autoload -Uz is-at-least add-zle-hook-widget
8181

82-
# AGKOZAK is an associative array for storing internal information that is discarded when the
83-
# prompt is unloaded.
82+
# AGKOZAK is an associative array for storing internal information that is
83+
# discarded when the prompt is unloaded.
8484
#
8585
# AGKOZAK[ASYNC_METHOD] Which asynchronous method is currently in use
8686
# AGKOZAK[FIRST_PROMPT_PRINTED] When AGKOZAK_BLANK_LINES=1, this variable
@@ -134,10 +134,12 @@ AGKOZAK[FUNCTIONS]='_agkozak_debug_print
134134
_agkozak_usr1_async_worker
135135
TRAPUSR1
136136
_agkozak_strip_colors
137-
_agkozak_preexec
138-
_agkozak_precmd
137+
prompt_agkozak_preexec
138+
prompt_agkozak_precmd
139139
_agkozak_prompt_strings
140-
agkozak-zsh-prompt'
140+
agkozak-zsh-prompt
141+
prompt_agkozak-zsh-prompt_preview
142+
prompt_agkozak-zsh-prompt_help'
141143

142144
: ${AGKOZAK_PROMPT_DEBUG:=0}
143145

@@ -216,8 +218,6 @@ fi
216218
# Characters to put around the virtual environment name (default: square brackets)
217219
(( $+AGKOZAK_VIRTUALENV_CHARS )) || AGKOZAK_VIRTUALENV_CHARS=( '[' ']' )
218220

219-
setopt PROMPT_SUBST NO_PROMPT_BANG
220-
221221
######################################################################
222222
# GENERAL FUNCTIONS
223223
######################################################################
@@ -716,7 +716,7 @@ _agkozak_async_init() {
716716
else
717717
_agkozak_debug_print 'TRAPUSR1 has been redefined. Switching to subst-async mode.'
718718
AGKOZAK[ASYNC_METHOD]='subst-async'
719-
_agkozak_precmd
719+
prompt_agkozak_precmd
720720
fi
721721
}
722722

@@ -800,7 +800,7 @@ _agkozak_strip_colors() {
800800
# Runs right before each command is about to be executed.
801801
# Used to calculate command execution time.
802802
############################################################
803-
_agkozak_preexec() {
803+
prompt_agkozak_preexec() {
804804
typeset -gi AGKOZAK_CMD_START_TIME=$EPOCHSECONDS
805805
}
806806

@@ -819,7 +819,7 @@ _agkozak_preexec() {
819819
# AGKOZAK_BLANK_LINES
820820
# AGKOZAK_PROMPT_DIRTRIM
821821
############################################################
822-
_agkozak_precmd() {
822+
prompt_agkozak_precmd() {
823823
emulate -L zsh
824824
(( AGKOZAK_PROMPT_DEBUG )) && [[ $ZSH_VERSION != 5.0.[0-2] ]] &&
825825
setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL
@@ -979,9 +979,11 @@ _agkozak_prompt_strings() {
979979
# AGKOZAK_PROMPT_DEBUG
980980
# AGKOZAK_PROMPT_DIRTRIM
981981
############################################################
982-
agkozak-zsh-prompt() {
983-
emulate -L zsh
984-
(( AGKOZAK_PROMPT_DEBUG )) && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL
982+
prompt_agkozak-zsh-prompt_setup() {
983+
# `emulate -L zsh' has been removed for promptinit
984+
# compatibility
985+
prompt_opts=( percent subst )
986+
setopt NO_PROMPT_{BANG,CR,PERCENT,SUBST} "PROMPT_${^prompt_opts[@]}"
985987

986988
_agkozak_async_init
987989

@@ -1002,8 +1004,8 @@ agkozak-zsh-prompt() {
10021004
:
10031005
else
10041006
autoload -Uz add-zsh-hook
1005-
add-zsh-hook preexec _agkozak_preexec
1006-
add-zsh-hook precmd _agkozak_precmd
1007+
add-zsh-hook preexec prompt_agkozak_preexec
1008+
add-zsh-hook precmd prompt_agkozak_precmd
10071009
fi
10081010

10091011
# Only display the HOSTNAME for an SSH connection or for a superuser
@@ -1037,7 +1039,22 @@ agkozak-zsh-prompt() {
10371039
_agkozak_debug_print "Using async method: ${AGKOZAK[ASYNC_METHOD]}"
10381040
}
10391041

1040-
agkozak-zsh-prompt
1042+
prompt_agkozak-zsh-prompt_setup
1043+
1044+
############################################################
1045+
# Preview function for promptinit
1046+
############################################################
1047+
1048+
prompt_agkozak-zsh-prompt_preview() {
1049+
print "No preview available. Try \`prompt agkozak-zsh-prompt'."
1050+
}
1051+
1052+
############################################################
1053+
# Help function for promptinit
1054+
############################################################
1055+
prompt_agkozak-zsh-prompt_help() {
1056+
print 'For information about how to configure the agkozak-zsh-prompt, visit https://github.com/agkozak/agkozak-zsh-prompt.' | fold -s
1057+
}
10411058

10421059
############################################################
10431060
# Unload function
@@ -1056,8 +1073,8 @@ agkozak-zsh-prompt_plugin_unload() {
10561073

10571074
psvar=( $AGKOZAK_OLD_PSVAR )
10581075

1059-
add-zsh-hook -D preexec _agkozak_preexec
1060-
add-zsh-hook -D precmd _agkozak_precmd
1076+
add-zsh-hook -D preexec prompt_agkozak_preexec
1077+
add-zsh-hook -D precmd prompt_agkozak_precmd
10611078

10621079
if is-at-least 5.3; then
10631080
add-zle-hook-widget -D zle-keymap-select _agkozak_zle-keymap-select

prompt_agkozak-zsh-prompt_setup

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#autoload
2+
# Shim for promptinit compatibility
3+
source "${${(%):-%x}:A:h}/agkozak-zsh-prompt.plugin.zsh"

0 commit comments

Comments
 (0)