Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed Aug 14, 2021
2 parents b6106d9 + 60f080b commit 0425524
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 20 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 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.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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
55 changes: 36 additions & 19 deletions agkozak-zsh-prompt.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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
######################################################################
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions prompt_agkozak-zsh-prompt_setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#autoload
# Shim for promptinit compatibility
source "${${(%):-%x}:A:h}/agkozak-zsh-prompt.plugin.zsh"

0 comments on commit 0425524

Please sign in to comment.