diff --git a/.gitignore b/.gitignore index 7ed5411b7a..8d63b6d767 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.zwc.old modules/*/cache.zsh .ztoken +contrib diff --git a/README.md b/README.md index 751d426ce7..5b5c087e95 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,19 @@ accompanying README files to learn of what is available. ![sorin theme][2] +### External Modules + + 1. By default modules will be loaded from */modules* and */contrib*. + 2. Additional module directories can be added to the + `:prezto:load:pmodule-dirs` setting in *~/.zpreztorc*. + + Note that module names need to be unique or they will cause an error when + loading. + + ```console + zstyle ':prezto:load' pmodule-dirs $HOME/.zprezto-contrib + ``` + Customization ------------- diff --git a/init.zsh b/init.zsh index 18525ca87d..99254bdb58 100644 --- a/init.zsh +++ b/init.zsh @@ -72,44 +72,68 @@ function zprezto-update { # Loads Prezto modules. function pmodload { local -a pmodules + local -a pmodule_dirs + local -a locations local pmodule + local pmodule_location local pfunction_glob='^([_.]*|prompt_*_setup|README*|*~)(-.N:t)' - # $argv is overridden in the anonymous function. - pmodules=("$argv[@]") - - # Add functions to $fpath. - fpath=(${pmodules:+$ZPREZTODIR/modules/${^pmodules}/functions(/FN)} $fpath) - - function { - local pfunction + # Load in any additional directories and warn if they don't exist + zstyle -a ':prezto:load' pmodule-dirs 'user_pmodule_dirs' + for user_dir in "$user_pmodule_dirs[@]"; do + if [[ ! -d "$user_dir" ]]; then + echo "$0: Missing user module dir: $user_dir" + fi + done - # Extended globbing is needed for listing autoloadable function directories. - setopt LOCAL_OPTIONS EXTENDED_GLOB + pmodule_dirs=("$ZPREZTODIR/modules" "$ZPREZTODIR/contrib" "$user_pmodule_dirs[@]") - # Load Prezto functions. - for pfunction in $ZPREZTODIR/modules/${^pmodules}/functions/$~pfunction_glob; do - autoload -Uz "$pfunction" - done - } + # $argv is overridden in the anonymous function. + pmodules=("$argv[@]") # Load Prezto modules. for pmodule in "$pmodules[@]"; do if zstyle -t ":prezto:module:$pmodule" loaded 'yes' 'no'; then continue - elif [[ ! -d "$ZPREZTODIR/modules/$pmodule" ]]; then - print "$0: no such module: $pmodule" >&2 - continue else - if [[ -s "$ZPREZTODIR/modules/$pmodule/init.zsh" ]]; then - source "$ZPREZTODIR/modules/$pmodule/init.zsh" + locations=(${pmodule_dirs:+${^pmodule_dirs}/$pmodule(-/FN)}) + if (( ${#locations} > 1 )); then + print "$0: conflicting module locations: $locations" + continue + elif (( ${#locations} < 1 )); then + print "$0: no such module: $pmodule" + continue + fi + + # Grab the full path to this module + pmodule_location=${locations[1]} + + # Add functions to $fpath. + fpath=(${pmodule_location}/functions(/FN) $fpath) + + function { + local pfunction + + # Extended globbing is needed for listing autoloadable function directories. + setopt LOCAL_OPTIONS EXTENDED_GLOB + + # Load Prezto functions. + for pfunction in ${pmodule_location}/functions/$~pfunction_glob; do + autoload -Uz "$pfunction" + done + } + + if [[ -s "${pmodule_location}/init.zsh" ]]; then + source "${pmodule_location}/init.zsh" + elif [[ -s "${pmodule_location}/${pmodule}.plugin.zsh" ]]; then + source "${pmodule_location}/${pmodule}.plugin.zsh" fi if (( $? == 0 )); then zstyle ":prezto:module:$pmodule" loaded 'yes' else # Remove the $fpath entry. - fpath[(r)${ZPREZTODIR}/modules/${pmodule}/functions]=() + fpath[(r)${pmodule_location}/functions]=() function { local pfunction @@ -119,7 +143,7 @@ function pmodload { setopt LOCAL_OPTIONS EXTENDED_GLOB # Unload Prezto functions. - for pfunction in $ZPREZTODIR/modules/$pmodule/functions/$~pfunction_glob; do + for pfunction in ${pmodule_location}/functions/$~pfunction_glob; do unfunction "$pfunction" done } diff --git a/modules/README.md b/modules/README.md index 1c2cdc54d8..3c7392cf16 100644 --- a/modules/README.md +++ b/modules/README.md @@ -122,7 +122,7 @@ Initializes OCaml package management. OSX --- -Defines Mac OS X aliases and functions. +Defines macOS aliases and functions. Pacman ------ @@ -132,7 +132,7 @@ Provides aliases and functions for the Pacman package manager and frontends. Perl ---- -Enables local Perl module installation on Mac OS X and defines alises. +Enables local Perl module installation on macOS and defines alises. Prompt ------ diff --git a/modules/archive/README.md b/modules/archive/README.md index c2ab938a1b..600ff15d0e 100644 --- a/modules/archive/README.md +++ b/modules/archive/README.md @@ -35,6 +35,12 @@ Additionally, if `pigz` and/or `pbzip2` are installed, `archive` will use them o their traditional counterparts, `gzip` and `bzip2` respectively, to take full advantage of all available CPU cores for compression. +Alternatives +------------ + +Specifically on macOS, [The Unarchiver][1] provides a similar command line tool +which doesn't depend on a number of other programs being installed. + Authors ------- @@ -43,4 +49,4 @@ Authors - [Sorin Ionescu](https://github.com/sorin-ionescu) - [Matt Hamilton](https://github.com/Eriner) -[1]: https://github.com/sorin-ionescu/prezto/issues +[1]: https://theunarchiver.com/command-line diff --git a/modules/autosuggestions/README.md b/modules/autosuggestions/README.md index ad0f7eced9..c3e90a4916 100644 --- a/modules/autosuggestions/README.md +++ b/modules/autosuggestions/README.md @@ -46,6 +46,14 @@ To set the query found color, add the following line to *zpreztorc*: zstyle ':prezto:module:autosuggestions:color' found '' ``` +Troubleshooting +--------------- + +### Autosuggestions from previous sessions don't show up + +For autosuggestions from previous shell sessions to work, please make sure you +also have the `history` module enabled. + Authors ------- diff --git a/modules/command-not-found/init.zsh b/modules/command-not-found/init.zsh index 0e778031f1..2c59a4b31d 100644 --- a/modules/command-not-found/init.zsh +++ b/modules/command-not-found/init.zsh @@ -12,9 +12,9 @@ if [[ -s '/etc/zsh_command_not_found' ]]; then # Load command-not-found on Arch Linux-based distributions. elif [[ -s '/usr/share/doc/pkgfile/command-not-found.zsh' ]]; then source '/usr/share/doc/pkgfile/command-not-found.zsh' -# Load command-not-found on Mac OS X when homebrew tap is configured. -elif (( $+commands[brew] )) && brew command command-not-found-init > /dev/null 2>&1; then - eval "$(brew command-not-found-init)" +# Load command-not-found on macOS when homebrew tap is configured. +elif [[ -s '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh' ]]; then + source '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-command-not-found/handler.sh' # Return if requirements are not found. else return 1 diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh index 47191dfe4f..8abc1e2407 100644 --- a/modules/directory/init.zsh +++ b/modules/directory/init.zsh @@ -16,7 +16,6 @@ setopt PUSHD_IGNORE_DUPS # Do not store duplicates in the stack. setopt PUSHD_SILENT # Do not print the directory stack after pushd or popd. setopt PUSHD_TO_HOME # Push to home directory when no argument is given. setopt CDABLE_VARS # Change directory to a path stored in a variable. -setopt AUTO_NAME_DIRS # Auto add variable-stored paths to ~ list. setopt MULTIOS # Write to multiple descriptors. setopt EXTENDED_GLOB # Use extended globbing syntax. unsetopt CLOBBER # Do not overwrite existing files with > and >>. diff --git a/modules/editor/init.zsh b/modules/editor/init.zsh index 415d653088..085947ef61 100644 --- a/modules/editor/init.zsh +++ b/modules/editor/init.zsh @@ -14,8 +14,7 @@ fi # Options # -# Beep on error in line editor. -setopt BEEP +setopt BEEP # Beep on error in line editor. # # Variables @@ -211,6 +210,14 @@ zle -N expand-dot-to-parent-directory-path function expand-or-complete-with-indicator { local indicator zstyle -s ':prezto:module:editor:info:completing' format 'indicator' + + # This is included to work around a bug in zsh which shows up when interacting + # with multi-line prompts. + if [[ -z "$indicator" ]]; then + zle expand-or-complete + return + fi + print -Pn "$indicator" zle expand-or-complete zle redisplay @@ -234,6 +241,27 @@ function glob-alias { } zle -N glob-alias +# Toggle the comment character at the start of the line. This is meant to work +# around a buggy implementation of pound-insert in zsh. +# +# This is currently only used for the emacs keys because vi-pound-insert has +# been reported to work properly. +function pound-toggle { + if [[ "$BUFFER" = '#'* ]]; then + # Because of an oddity in how zsh handles the cursor when the buffer size + # changes, we need to make this check before we modify the buffer and let + # zsh handle moving the cursor back if it's past the end of the line. + if [[ $CURSOR != $#BUFFER ]]; then + (( CURSOR -= 1 )) + fi + BUFFER="${BUFFER:1}" + else + BUFFER="#$BUFFER" + (( CURSOR += 1 )) + fi +} +zle -N pound-toggle + # Reset to default key bindings. bindkey -d @@ -269,6 +297,12 @@ if (( $+widgets[history-incremental-pattern-search-backward] )); then history-incremental-pattern-search-forward fi +# Toggle comment at the start of the line. Note that we use pound-toggle which +# is similar to pount insert, but meant to work around some issues that were +# being seen in iTerm. +bindkey -M emacs "$key_info[Escape];" pound-toggle + + # # Vi Key Bindings # @@ -288,6 +322,9 @@ else bindkey -M vicmd "/" history-incremental-search-forward fi +# Toggle comment at the start of the line. +bindkey -M vicmd "#" vi-pound-insert + # # Emacs and Vi Key Bindings # @@ -322,18 +359,24 @@ for keymap in $unbound_keys; do bindkey -M viins "${keymap}" _prezto-zle-noop bindkey -M vicmd "${keymap}" _prezto-zle-noop done -# Ctrl + Left and Ctrl + Right bindings to forward/backward word + +# Keybinds for all keymaps +for keymap in 'emacs' 'viins' 'vicmd'; do + bindkey -M "$keymap" "$key_info[Home]" beginning-of-line + bindkey -M "$keymap" "$key_info[End]" end-of-line +done + +# Keybinds for all vi keymaps for keymap in viins vicmd; do + # Ctrl + Left and Ctrl + Right bindings to forward/backward word for key in "${(s: :)key_info[ControlLeft]}" bindkey -M "$keymap" "$key" vi-backward-word for key in "${(s: :)key_info[ControlRight]}" bindkey -M "$keymap" "$key" vi-forward-word done +# Keybinds for emacs and vi insert mode for keymap in 'emacs' 'viins'; do - bindkey -M "$keymap" "$key_info[Home]" beginning-of-line - bindkey -M "$keymap" "$key_info[End]" end-of-line - bindkey -M "$keymap" "$key_info[Insert]" overwrite-mode bindkey -M "$keymap" "$key_info[Delete]" delete-char bindkey -M "$keymap" "$key_info[Backspace]" backward-delete-char diff --git a/modules/environment/init.zsh b/modules/environment/init.zsh index 76655a6c7e..4f3bbfe35a 100644 --- a/modules/environment/init.zsh +++ b/modules/environment/init.zsh @@ -9,18 +9,34 @@ # Smart URLs # -autoload -Uz url-quote-magic -zle -N self-insert url-quote-magic +# This logic comes from an old version of zim. Essentially, bracketed-paste was +# added as a requirement of url-quote-magic in 5.1, but in 5.1.1 bracketed +# paste had a regression. Additionally, 5.2 added bracketed-paste-url-magic +# which is generally better than url-quote-magic so we load that when possible. +autoload -Uz is-at-least +if [[ ${ZSH_VERSION} != 5.1.1 ]]; then + if is-at-least 5.2; then + autoload -Uz bracketed-paste-url-magic + zle -N bracketed-paste bracketed-paste-url-magic + else + if is-at-least 5.1; then + autoload -Uz bracketed-paste-magic + zle -N bracketed-paste bracketed-paste-magic + fi + fi + autoload -Uz url-quote-magic + zle -N self-insert url-quote-magic +fi # # General # -setopt BRACE_CCL # Allow brace character class list expansion. -setopt COMBINING_CHARS # Combine zero-length punctuation characters (accents) - # with the base character. -setopt RC_QUOTES # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'. -unsetopt MAIL_WARNING # Don't print a warning message if a mail file has been accessed. +setopt COMBINING_CHARS # Combine zero-length punctuation characters (accents) + # with the base character. +setopt INTERACTIVE_COMMENTS # Enable comments in interactive shell. +setopt RC_QUOTES # Allow 'Henry''s Garage' instead of 'Henry'\''s Garage'. +unsetopt MAIL_WARNING # Don't print a warning message if a mail file has been accessed. # # Jobs diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index 44d6297517..37babd8e3e 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -19,8 +19,10 @@ fi # Initialization # -cache_file="${0:h}/cache.zsh" -if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then +cache_file="${TMPDIR:-/tmp}/prezto-fasd-cache.$UID.zsh" +if [[ "${commands[fasd]}" -nt "$cache_file" \ + || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ + || ! -s "$cache_file" ]]; then # Set the base init arguments. init_args=(zsh-hook) diff --git a/modules/git/README.md b/modules/git/README.md index bd67f712cc..1d4b7ba562 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -82,6 +82,8 @@ zstyle ':prezto:module:git:alias' skip 'yes' - `gcR` removes the *HEAD* commit. - `gcs` displays various types of objects. - `gcl` lists lost commits. + - `gcy` displays commits yet to be applied to upstream in the short format. + - `gcY` displays commits yet to be applied to upstream. ### Conflict @@ -288,6 +290,11 @@ zstyle ':prezto:module:git:alias' skip 'yes' - `gSu` fetches and merges the latest changes for all submodule. - `gSx` removes a submodule. +### Tag + + - `gt` lists tags or creates tag. + - `gtl` lists tags matching pattern. + ### Working directory - `gws` displays working-tree status in the short format. @@ -307,9 +314,10 @@ zstyle ':prezto:module:git:alias' skip 'yes' The following aliases may shadow system commands: - - `gpt` shadows the [GUID partition table maintenance utility][4]. - - `gs` shadows the [Ghostscript][5]. - `gb` shadows the [GB][9]. + - `gm` shadows the [Graphics Magick image processor][11]. + - `gpt` shadows the [GUID partition table maintenance utility][4]. + - `gs` shadows the [Ghostscript interpreter and previewer][5]. If you frequently use the above commands, you may wish to remove said aliases from this module or to disable them at the bottom of the zshrc with `unalias`. @@ -434,9 +442,10 @@ Authors [2]: https://github.com/defunkt/hub [3]: https://www.github.com [4]: http://www.manpagez.com/man/8/gpt/ -[5]: http://linux.die.net/man/1/gs +[5]: http://www.manpagez.com/man/1/gs/ [6]: https://github.com/sorin-ionescu/prezto/issues [7]: https://github.com/sorin-ionescu/prezto/issues/219 [8]: http://www.kernel.org/pub/software/scm/git/docs/git-log.html [9]: https://getgb.io/ [10]: https://github.com/blog/985-git-io-github-url-shortener +[11]: http://www.manpagez.com/man/1/gm/ diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh index 698ae692e4..2d8db5c97a 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -69,6 +69,8 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then alias gcR='git reset "HEAD^"' alias gcs='git show' alias gcl='git-commit-lost' + alias gcy='git cherry -v --abbrev' + alias gcY='git cherry -v' # Conflict (C) alias gCl='git --no-pager diff --name-only --diff-filter=U' @@ -250,6 +252,10 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then alias gSu='git submodule foreach git pull origin master' alias gSx='git-submodule-remove' + # Tag (t) + alias gt='git tag' + alias gtl='git tag -l' + # Working Copy (w) alias gws='git status --ignore-submodules=${_git_status_ignore_submodules} --short' alias gwS='git status --ignore-submodules=${_git_status_ignore_submodules}' diff --git a/modules/git/functions/_git-hub-browse b/modules/git/functions/_git-hub-browse index 9e6d6f0d5c..075314bb90 100644 --- a/modules/git/functions/_git-hub-browse +++ b/modules/git/functions/_git-hub-browse @@ -8,7 +8,7 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then return 1 fi @@ -21,7 +21,7 @@ _arguments -C -s -S \ case "$state" in (remote) - remotes=($(git config --get-regexp 'remote.*.url' | cut -d. -f2)) + remotes=($(command git config --get-regexp 'remote.*.url' | cut -d. -f2)) _describe -t branch 'remotes' remotes && ret=0 ;; @@ -29,7 +29,7 @@ case "$state" in remote="$words[(($CURRENT - 1))]" branches_or_tags=($( - git ls-remote --heads --tags "$remote" 2> /dev/null | cut -f2 + command git ls-remote --heads --tags "$remote" 2> /dev/null | cut -f2 )) branches=(HEAD ${${(M)branches_or_tags[@]##refs/heads/?##}##refs/heads/}) @@ -39,7 +39,7 @@ case "$state" in _describe -t tag 'tags' tags && ret=0 ;; (file) - files=(${(0)"$(_call_program files git ls-files -z --exclude-standard 2> /dev/null)"}) + files=(${(0)"$(_call_program files command git ls-files -z --exclude-standard 2> /dev/null)"}) _wanted file expl 'file' _multi_parts - / files && ret=0 ;; esac diff --git a/modules/git/functions/_git-hub-shorten-url b/modules/git/functions/_git-hub-shorten-url index 1d811caee7..7e65ded318 100644 --- a/modules/git/functions/_git-hub-shorten-url +++ b/modules/git/functions/_git-hub-shorten-url @@ -8,4 +8,9 @@ # Sorin Ionescu # -_arguments '::GitHub URL:_urls' && return 0 +local service="$service" + +zstyle ":completion:*:${service}:*:prefixes" ignored-patterns '^http(|s)://' +zstyle ":completion:*:${service}:*:hosts" ignored-patterns '^*github.com' + +_arguments '1::GitHub URL:_urls' '2::code:' && return 0 diff --git a/modules/git/functions/_git-info b/modules/git/functions/_git-info index 1e21bfeb1a..ef6d97026b 100644 --- a/modules/git/functions/_git-info +++ b/modules/git/functions/_git-info @@ -8,7 +8,7 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then return 1 fi diff --git a/modules/git/functions/_git-submodule-move b/modules/git/functions/_git-submodule-move index 44eddb5402..5f2122c4d1 100644 --- a/modules/git/functions/_git-submodule-move +++ b/modules/git/functions/_git-submodule-move @@ -8,7 +8,7 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then return 1 fi @@ -25,7 +25,7 @@ case "$state" in while IFS=$'\n' read submodule; do submodules+=("$submodule") done < <( - git config --file "$(git-root)/.gitmodules" --list \ + command git config --file "$(git-root)/.gitmodules" --list \ | grep '.path=' \ | cut -d= -f2- ) diff --git a/modules/git/functions/_git-submodule-remove b/modules/git/functions/_git-submodule-remove index 87bd7cb006..819dfd8e36 100644 --- a/modules/git/functions/_git-submodule-remove +++ b/modules/git/functions/_git-submodule-remove @@ -8,7 +8,7 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then return 1 fi @@ -18,7 +18,7 @@ local submodule while IFS=$'\n' read submodule; do submodules+=("$submodule") done < <( - git config --file "$(git-root)/.gitmodules" --list \ + command git config --file "$(git-root)/.gitmodules" --list \ | grep '.path=' \ | cut -d= -f2- ) diff --git a/modules/git/functions/git-branch-current b/modules/git/functions/git-branch-current index cadb6f63df..3cf2e191d1 100644 --- a/modules/git/functions/git-branch-current +++ b/modules/git/functions/git-branch-current @@ -7,12 +7,12 @@ # function git-branch-current { -if ! git rev-parse 2> /dev/null; then +if ! command git rev-parse 2> /dev/null; then print "$0: not a repository: $PWD" >&2 return 1 fi -local ref="$(git symbolic-ref HEAD 2> /dev/null)" +local ref="$(command git symbolic-ref HEAD 2> /dev/null)" if [[ -n "$ref" ]]; then print "${ref#refs/heads/}" diff --git a/modules/git/functions/git-commit-lost b/modules/git/functions/git-commit-lost index 62789ac916..1f086d3b95 100644 --- a/modules/git/functions/git-commit-lost +++ b/modules/git/functions/git-commit-lost @@ -7,15 +7,15 @@ # function git-commit-lost { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 fi -git fsck 2> /dev/null \ +command git fsck 2> /dev/null \ | grep "^dangling commit" \ | awk '{print $3}' \ - | git log \ + | command git log \ --date-order \ --no-walk \ --stdin \ diff --git a/modules/git/functions/git-dir b/modules/git/functions/git-dir index fdb515c5d4..aacaaa8866 100644 --- a/modules/git/functions/git-dir +++ b/modules/git/functions/git-dir @@ -7,7 +7,7 @@ # function git-dir { -local git_dir="${$(git rev-parse --git-dir):A}" +local git_dir="${$(command git rev-parse --git-dir):A}" if [[ -n "$git_dir" ]]; then print "$git_dir" diff --git a/modules/git/functions/git-hub-browse b/modules/git/functions/git-hub-browse index a365a5a9ae..cb3fc60de8 100644 --- a/modules/git/functions/git-hub-browse +++ b/modules/git/functions/git-hub-browse @@ -7,7 +7,7 @@ # function git-hub-browse { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 fi @@ -15,7 +15,7 @@ fi local remotes remote references reference file url remote="${1:-origin}" -remotes=($(git config --get-regexp 'remote.*.url' | cut -d. -f2)) +remotes=($(command git config --get-regexp 'remote.*.url' | cut -d. -f2)) if (( $remotes[(i)$remote] == $#remotes + 1 )); then print "$0: remote not found: $remote" >&2 @@ -23,14 +23,14 @@ if (( $remotes[(i)$remote] == $#remotes + 1 )); then fi url=$( - git config --get "remote.${remote}.url" \ + command git config --get "remote.${remote}.url" \ | sed -En "s/(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p" ) reference="${${2:-$(git-branch-current)}:-HEAD}" references=( HEAD - ${$(git ls-remote --heads --tags "$remote" | awk '{print $2}')##refs/(heads|tags)/} + ${$(command git ls-remote --heads --tags "$remote" | awk '{print $2}')##refs/(heads|tags)/} ) if (( $references[(i)$reference] == $#references + 1 )); then @@ -39,7 +39,7 @@ if (( $references[(i)$reference] == $#references + 1 )); then fi if [[ "$reference" == 'HEAD' ]]; then - reference="$(git rev-parse HEAD 2> /dev/null)" + reference="$(command git rev-parse HEAD 2> /dev/null)" fi file="$3" diff --git a/modules/git/functions/git-hub-shorten-url b/modules/git/functions/git-hub-shorten-url index f36662f4ec..470c093f1c 100644 --- a/modules/git/functions/git-hub-shorten-url +++ b/modules/git/functions/git-hub-shorten-url @@ -7,20 +7,22 @@ # function git-hub-shorten-url { -local url="$1" +local url="$1" code="$2" if [[ "$url" == '-' ]]; then read url <&0 fi if [[ -z "$url" || ! "$url" =~ ^https?:\/\/.*github.com\/ ]]; then - print "usage: $0 [ url | - ] ; must be a github.com URL" >&2 + print "usage: $0 [ url | - ] [code] ; url must be a github.com URL" >&2 + return 1 fi if (( $+commands[curl] )); then - curl -s -i 'https://git.io' -F "url=$url" | sed -n 's/^Location: //p' + curl -s -i 'https://git.io' -F "url=$url" ${(s: :)code:+ -F "code=$code"} | sed -n 's/^Location: //p' else print "$0: command not found: curl" >&2 + return 1 fi # } diff --git a/modules/git/functions/git-info b/modules/git/functions/git-info index d27365c243..a173c20f14 100644 --- a/modules/git/functions/git-info +++ b/modules/git/functions/git-info @@ -178,15 +178,15 @@ function git-info { typeset -gA git_info # Return if not inside a Git repository work tree. - if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then + if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then return 1 fi if (( $# > 0 )); then if [[ "$1" == [Oo][Nn] ]]; then - git config --bool prompt.showinfo true + command git config --bool prompt.showinfo true elif [[ "$1" == [Oo][Ff][Ff] ]]; then - git config --bool prompt.showinfo false + command git config --bool prompt.showinfo false else print "usage: $0 [ on | off ]" >&2 fi @@ -194,7 +194,7 @@ function git-info { fi # Return if git-info is disabled. - if ! is-true "${$(git config --bool prompt.showinfo):-true}"; then + if ! is-true "${$(command git config --bool prompt.showinfo):-true}"; then return 1 fi @@ -204,7 +204,7 @@ function git-info { # Format commit. zstyle -s ':prezto:module:git:info:commit' format 'commit_format' if [[ -n "$commit_format" ]]; then - commit="$(git rev-parse HEAD 2> /dev/null)" + commit="$(command git rev-parse HEAD 2> /dev/null)" if [[ -n "$commit" ]]; then zformat -f commit_formatted "$commit_format" "c:$commit" fi @@ -213,7 +213,7 @@ function git-info { # Format stashed. zstyle -s ':prezto:module:git:info:stashed' format 'stashed_format' if [[ -n "$stashed_format" && -f "$(git-dir)/refs/stash" ]]; then - stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')" + stashed="$(command git stash list 2> /dev/null | wc -l | awk '{print $1}')" if [[ -n "$stashed" ]]; then zformat -f stashed_formatted "$stashed_format" "S:$stashed" fi @@ -229,7 +229,7 @@ function git-info { fi # Get the branch. - branch="${$(git symbolic-ref HEAD 2> /dev/null)#refs/heads/}" + branch="${$(command git symbolic-ref HEAD 2> /dev/null)#refs/heads/}" # Format branch. zstyle -s ':prezto:module:git:info:branch' format 'branch_format' @@ -240,7 +240,7 @@ function git-info { # Format position. zstyle -s ':prezto:module:git:info:position' format 'position_format' if [[ -z "$branch" && -n "$position_format" ]]; then - position="$(git describe --contains --all HEAD 2> /dev/null)" + position="$(command git describe --contains --all HEAD 2> /dev/null)" if [[ -n "$position" ]]; then zformat -f position_formatted "$position_format" "p:$position" fi @@ -250,7 +250,7 @@ function git-info { zstyle -s ':prezto:module:git:info:remote' format 'remote_format' if [[ -n "$branch" && -n "$remote_format" ]]; then # Gets the remote name. - remote_cmd='git rev-parse --symbolic-full-name --verify HEAD@{upstream}' + remote_cmd='command git rev-parse --symbolic-full-name --verify HEAD@{upstream}' remote="${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}" if [[ -n "$remote" ]]; then zformat -f remote_formatted "$remote_format" "R:$remote" @@ -261,7 +261,7 @@ function git-info { zstyle -s ':prezto:module:git:info:behind' format 'behind_format' if [[ -n "$branch" && ( -n "$ahead_format" || -n "$behind_format" ) ]]; then # Gets the commit difference counts between local and remote. - ahead_and_behind_cmd='git rev-list --count --left-right HEAD...@{upstream}' + ahead_and_behind_cmd='command git rev-list --count --left-right HEAD...@{upstream}' # Get ahead and behind counts. ahead_and_behind="$(${(z)ahead_and_behind_cmd} 2> /dev/null)" @@ -290,7 +290,7 @@ function git-info { if [[ -n "$indexed_format" ]]; then (( indexed+=$( - git diff-index \ + command git diff-index \ --no-ext-diff \ --name-only \ --cached \ @@ -310,7 +310,7 @@ function git-info { if [[ -n "$unindexed_format" ]]; then (( unindexed+=$( - git diff-files \ + command git diff-files \ --no-ext-diff \ --name-only \ --ignore-submodules=${ignore_submodules:-none} \ @@ -328,7 +328,7 @@ function git-info { if [[ -n "$untracked_format" ]]; then (( untracked+=$( - git ls-files \ + command git ls-files \ --other \ --exclude-standard \ 2> /dev/null \ @@ -343,7 +343,7 @@ function git-info { (( dirty = indexed + unindexed + untracked )) else # Use porcelain status for easy parsing. - status_cmd="git status --porcelain --ignore-submodules=${ignore_submodules:-none}" + status_cmd="command git status --porcelain --ignore-submodules=${ignore_submodules:-none}" # Get current status. while IFS=$'\n' read line; do diff --git a/modules/git/functions/git-root b/modules/git/functions/git-root index f749457205..643f346b36 100644 --- a/modules/git/functions/git-root +++ b/modules/git/functions/git-root @@ -7,7 +7,7 @@ # function git-root { -local root="$(git rev-parse --show-toplevel 2> /dev/null)" +local root="$(command git rev-parse --show-toplevel 2> /dev/null)" if [[ -n "$root" ]]; then print "$root" diff --git a/modules/git/functions/git-stash-clear-interactive b/modules/git/functions/git-stash-clear-interactive index 71468aa0e0..cc665a1829 100644 --- a/modules/git/functions/git-stash-clear-interactive +++ b/modules/git/functions/git-stash-clear-interactive @@ -7,7 +7,7 @@ # function git-stash-clear-interactive { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 fi @@ -15,10 +15,10 @@ fi local stashed if [[ -f "$(git-dir)/refs/stash" ]]; then - stashed="$(git stash list 2> /dev/null | wc -l | awk '{print $1}')" + stashed="$(command git stash list 2> /dev/null | wc -l | awk '{print $1}')" if (( $stashed > 0 )); then if read -q "?Clear $stashed stashed state(s) [y/N]? "; then - git stash clear + command git stash clear fi fi fi diff --git a/modules/git/functions/git-stash-dropped b/modules/git/functions/git-stash-dropped index 2a0b7a94e7..d9e759e872 100644 --- a/modules/git/functions/git-stash-dropped +++ b/modules/git/functions/git-stash-dropped @@ -7,15 +7,15 @@ # function git-stash-dropped { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 fi -git fsck --unreachable 2> /dev/null \ +command git fsck --unreachable 2> /dev/null \ | grep 'commit' \ | awk '{print $3}' \ - | git log \ + | command git log \ --pretty=format:${_git_log_oneline_format} \ --extended-regexp \ --grep="${1:-(WIP )?[Oo]n [^:]+:}" \ diff --git a/modules/git/functions/git-stash-recover b/modules/git/functions/git-stash-recover index 5cc949a730..6cb5416e6c 100644 --- a/modules/git/functions/git-stash-recover +++ b/modules/git/functions/git-stash-recover @@ -7,7 +7,7 @@ # function git-stash-recover { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 fi @@ -15,8 +15,8 @@ fi local commit for commit in "$@"; do - git update-ref \ - -m "$(git log -1 --pretty="format:%s" "$commit")" refs/stash "$commit" + command git update-ref \ + -m "$(command git log -1 --pretty="format:%s" "$commit")" refs/stash "$commit" done # } diff --git a/modules/git/functions/git-submodule-move b/modules/git/functions/git-submodule-move index ec6048e68e..746f46e512 100644 --- a/modules/git/functions/git-submodule-move +++ b/modules/git/functions/git-submodule-move @@ -7,7 +7,7 @@ # function git-submodule-move { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 elif [[ "$PWD" != "$(git-root)" ]]; then @@ -19,7 +19,7 @@ local src="$1" local dst="$2" local url -url="$(git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")" +url="$(command git config --file "$(git-root)/.gitmodules" --get "submodule.${src}.url")" if [[ -z "$url" ]]; then print "$0: submodule not found: $src" >&2 @@ -29,7 +29,7 @@ fi mkdir -p "${dst:h}" git-submodule-remove "$src" -git submodule add "$url" "$dst" +command git submodule add "$url" "$dst" return 0 diff --git a/modules/git/functions/git-submodule-remove b/modules/git/functions/git-submodule-remove index 2490e78c87..c8c11aa8c3 100644 --- a/modules/git/functions/git-submodule-remove +++ b/modules/git/functions/git-submodule-remove @@ -7,22 +7,22 @@ # function git-submodule-remove { -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +if ! is-true "$(command git rev-parse --is-inside-work-tree 2> /dev/null)"; then print "$0: not a repository work tree: $PWD" >&2 return 1 elif [[ "$PWD" != "$(git-root)" ]]; then print "$0: must be run from the root of the work tree" >&2 return 1 -elif ! git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then +elif ! command git config --file .gitmodules --get "submodule.${1}.path" &> /dev/null; then print "$0: submodule not found: $1" >&2 return 1 fi -git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &>/dev/null -git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &>/dev/null -git add .gitmodules +command git config --file "$(git-dir)/config" --remove-section "submodule.${1}" &> /dev/null +command git config --file "$(git-root)/.gitmodules" --remove-section "submodule.${1}" &> /dev/null +command git add .gitmodules -git rm --cached -rf "${1}" +command git rm --cached -rf "${1}" rm -rf "${1}" rm -rf "$(git-dir)/modules/${1}" diff --git a/modules/gnu-utility/init.zsh b/modules/gnu-utility/init.zsh index 5df4fe3368..cbf9a4baa8 100644 --- a/modules/gnu-utility/init.zsh +++ b/modules/gnu-utility/init.zsh @@ -48,7 +48,7 @@ _gnu_utility_cmds=( # Wrap GNU utilities in functions. for _gnu_utility_cmd in "${_gnu_utility_cmds[@]}"; do _gnu_utility_pcmd="${_gnu_utility_p}${_gnu_utility_cmd}" - if (( ${+commands[${_gnu_utility_pcmd}]} )); then + if (( ${+commands[${_gnu_utility_pcmd}]} && ! ${+builtins[${_gnu_utility_cmd}]} )); then eval " function ${_gnu_utility_cmd} { '${commands[${_gnu_utility_pcmd}]}' \"\$@\" diff --git a/modules/gpg/init.zsh b/modules/gpg/init.zsh index 3d80a46cdc..7976fd7da4 100644 --- a/modules/gpg/init.zsh +++ b/modules/gpg/init.zsh @@ -14,11 +14,11 @@ fi _gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf" _gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID" +# Load environment variables from previous run +source "$_gpg_agent_env" 2> /dev/null + # Start gpg-agent if not started. if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" ]]; then - # Export environment variables. - source "$_gpg_agent_env" 2> /dev/null - # Start gpg-agent if not started. if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")" diff --git a/modules/node/init.zsh b/modules/node/init.zsh index 127dea7242..0a516f0dfb 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -30,9 +30,11 @@ fi # Load NPM completion. if (( $+commands[npm] )); then - cache_file="${0:h}/cache.zsh" + cache_file="${TMPDIR:-/tmp}/prezto-node-cache.$UID.zsh" - if [[ "$commands[npm]" -nt "$cache_file" || ! -s "$cache_file" ]]; then + if [[ "$commands[npm]" -nt "$cache_file" \ + || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ + || ! -s "$cache_file" ]]; then # npm is slow; cache its output. npm completion >! "$cache_file" 2> /dev/null fi diff --git a/modules/osx/README.md b/modules/osx/README.md index 870b486408..1f93a2c332 100644 --- a/modules/osx/README.md +++ b/modules/osx/README.md @@ -1,7 +1,7 @@ OSX === -Defines [Mac OS X][1] aliases and functions. +Defines [macOS][1] aliases and functions. Settings -------- @@ -34,8 +34,8 @@ Functions - `tab` creates a new tab (works in both _Terminal_ and [_iTerm_][3]). - `ql` previews files in Quick Look. - `osx-rm-dir-metadata` deletes .DS\_Store, \_\_MACOSX cruft. - - `osx-ls-download-history` displays the Mac OS X download history. - - `osx-rm-download-history` deletes the Mac OS X download history. + - `osx-ls-download-history` displays the macOS download history. + - `osx-rm-download-history` deletes the macOS download history. Authors ------- diff --git a/modules/osx/functions/osx-ls-download-history b/modules/osx/functions/osx-ls-download-history index ba6a40c7ea..8b6eaab260 100644 --- a/modules/osx/functions/osx-ls-download-history +++ b/modules/osx/functions/osx-ls-download-history @@ -1,5 +1,5 @@ # -# Displays the Mac OS X download history. +# Displays the macOS download history. # # Authors: # Sorin Ionescu diff --git a/modules/osx/functions/osx-rm-download-history b/modules/osx/functions/osx-rm-download-history index c6a368cafb..068ba3db93 100644 --- a/modules/osx/functions/osx-rm-download-history +++ b/modules/osx/functions/osx-rm-download-history @@ -1,5 +1,5 @@ # -# Deletes the Mac OS X download history. +# Deletes the macOS download history. # # Authors: # Sorin Ionescu diff --git a/modules/osx/init.zsh b/modules/osx/init.zsh index edf6ed3d5f..f7871ca718 100644 --- a/modules/osx/init.zsh +++ b/modules/osx/init.zsh @@ -1,5 +1,5 @@ # -# Defines Mac OS X aliases and functions. +# Defines macOS aliases and functions. # # Authors: # Sorin Ionescu diff --git a/modules/pacman/README.md b/modules/pacman/README.md index 68ed92049e..a619a74777 100644 --- a/modules/pacman/README.md +++ b/modules/pacman/README.md @@ -7,20 +7,21 @@ frontends. Settings -------- -To enable a Pacman frontend, for example, [Yaourt][2], add the following line to -*zpreztorc*: +It is possible to use a Pacman frontend with the pacman aliases provided by this +package as long as that frontend supports the same command line options (The +[AUR Helpers][2] page has a good comparison which lists if the command line +options are pacman compatible). -```sh -zstyle ':prezto:module:pacman' frontend 'yaourt' -``` - -If you have enabled color globally in *zpreztorc*, you may disable it for certain -commands. +Please note that installing packages with an AUR Helper is not officially +supported by Archlinux. It is currently recommended to manually build AUR +packages using the [provided instructions][3]. The [aurutils][4] project has a +set of small utilities to make this easier. -To disable `yaourt` highlighting, add the following line to *zpreztorc*: +To enable a Pacman frontend, add the following line to *zpreztorc*, substituting +`pacman_frontend` with the name of the frontent: ```sh -zstyle ':prezto:module:pacman:yaourt' color 'no' +zstyle ':prezto:module:pacman' frontend 'pacman_frontend' ``` Aliases @@ -46,24 +47,23 @@ Aliases ### Frontends -#### Yaourt - - - `pacc` manages *.pac\** files. - Functions --------- + - `aurget` clone an aur package - `pacman-list-explicit` lists explicitly installed pacman packages. - `pacman-list-disowned` lists pacman disowned files. Authors ------- -*The authors of this module should be contacted via the [issue tracker][3].* +*The authors of this module should be contacted via the [issue tracker][5].* - [Benjamin Boudreau](https://github.com/dreur) - [Sorin Ionescu](https://github.com/sorin-ionescu) [1]: http://www.archlinux.org/pacman/ -[2]: http://archlinux.fr/yaourt-en -[3]: https://github.com/sorin-ionescu/prezto/issues +[2]: https://wiki.archlinux.org/index.php/AUR_helpers#Comparison_table +[3]: https://wiki.archlinux.org/index.php/Arch_User_Repository#Installing_packages +[4]: https://github.com/AladW/aurutils +[5]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/pacman/init.zsh b/modules/pacman/init.zsh index a5cacf2c44..88c977f6b3 100644 --- a/modules/pacman/init.zsh +++ b/modules/pacman/init.zsh @@ -23,10 +23,6 @@ zstyle -s ':prezto:module:pacman' frontend '_pacman_frontend' if (( $+commands[$_pacman_frontend] )); then alias pacman="$_pacman_frontend" - - if [[ -s "${0:h}/${_pacman_frontend}.zsh" ]]; then - source "${0:h}/${_pacman_frontend}.zsh" - fi else _pacman_frontend='pacman' _pacman_sudo='sudo ' @@ -81,4 +77,12 @@ fi # upgrades outdated packages. alias pacU="${_pacman_sudo}${_pacman_frontend} --sync --refresh --sysupgrade" +function aurget { + local target_dir="$1" + if [[ -n "$2" ]]; then + target_dir="$2" + fi + git clone "https://aur.archlinux.org/$1" "$target_dir" +} + unset _pacman_{frontend,sudo} diff --git a/modules/pacman/yaourt.zsh b/modules/pacman/yaourt.zsh deleted file mode 100644 index 819fad16be..0000000000 --- a/modules/pacman/yaourt.zsh +++ /dev/null @@ -1,18 +0,0 @@ -# -# Defines Yaourt aliases. -# -# Authors: -# Sorin Ionescu -# - -# -# Aliases -# - -# Disable color. -if ! zstyle -t ':prezto:module:pacman:yaourt' color; then - alias pacman='yaourt --nocolor' -fi - -# Manages .pac* files. -alias pacc='yaourt -C' diff --git a/modules/perl/README.md b/modules/perl/README.md index 092c922478..67f2a17798 100644 --- a/modules/perl/README.md +++ b/modules/perl/README.md @@ -1,14 +1,14 @@ Perl ==== -Enables local [Perl][1] module installation on Mac OS X and defines aliases. +Enables local [Perl][1] module installation on macOS and defines aliases. Local Module Installation ------------------------- Perl versions older than 5.14 do not support the local installation of Perl modules natively. This module allows for local installation of Perl modules on -Mac OS X in *~/Library/Perl/5.12* by altering the environment. +macOS in *~/Library/Perl/5.12* by altering the environment. ### Usage diff --git a/modules/perl/init.zsh b/modules/perl/init.zsh index 1624fbf9e0..b7a794797a 100644 --- a/modules/perl/init.zsh +++ b/modules/perl/init.zsh @@ -1,5 +1,5 @@ # -# Enables local Perl module installation on Mac OS X and defines aliases. +# Enables local Perl module installation on macOS and defines aliases. # # Authors: # Sorin Ionescu @@ -39,11 +39,11 @@ fi if [[ "$OSTYPE" == darwin* ]]; then # Perl is slow; cache its output. - cache_file="${0:h}/cache.zsh" + cache_file="${TMPDIR:-/tmp}/prezto-perl-cache.$UID.zsh" perl_path="$HOME/Library/Perl/5.12" if [[ -f "$perl_path/lib/perl5/local/lib.pm" ]]; then - if [[ ! -s "$cache_file" ]]; then + if [[ "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" || ! -s "$cache_file" ]]; then perl -I$perl_path/lib/perl5 -Mlocal::lib=$perl_path >! "$cache_file" fi diff --git a/modules/prompt/external/async b/modules/prompt/external/async index d95adb7cb5..b001fa529a 160000 --- a/modules/prompt/external/async +++ b/modules/prompt/external/async @@ -1 +1 @@ -Subproject commit d95adb7cb58ec9d45bf024951770d975e089ef1d +Subproject commit b001fa529a874fbe8bd22a9d4526153138645289 diff --git a/modules/prompt/functions/prompt_smiley_setup b/modules/prompt/functions/prompt_smiley_setup index 3066a2dc2b..3d41b3af46 100644 --- a/modules/prompt/functions/prompt_smiley_setup +++ b/modules/prompt/functions/prompt_smiley_setup @@ -36,7 +36,7 @@ function prompt_smiley_precmd { function prompt_smiley_setup { unsetopt XTRACE KSH_ARRAYS - prompt_opts=(percent subst) + prompt_opts=(cr percent sp subst) # Add hook for calling git-info before each command. add-zsh-hook precmd prompt_smiley_precmd diff --git a/modules/prompt/functions/prompt_sorin_setup b/modules/prompt/functions/prompt_sorin_setup index de00abab9d..30e71a9285 100644 --- a/modules/prompt/functions/prompt_sorin_setup +++ b/modules/prompt/functions/prompt_sorin_setup @@ -32,26 +32,29 @@ # Load dependencies. pmodload 'helper' -function prompt_sorin_git_info { - # We can safely split on ':' because it isn't allowed in ref names. - IFS=':' read _git_target _git_post_target <<<"$3" - - # The target actually contains 3 space separated possibilities, so we need to - # make sure we grab the first one. - _git_target=$(coalesce ${(@)${(z)_git_target}}) - - if [[ -z "$_git_target" ]]; then - # No git target detected, flush the git fragment and redisplay the prompt. - if [[ -n "$_prompt_sorin_git" ]]; then - _prompt_sorin_git='' - zle && zle reset-prompt - fi - - else - # Git target detected, update the git fragment and redisplay the prompt. - _prompt_sorin_git="${_git_target}${_git_post_target}" - zle && zle reset-prompt - fi +function prompt_sorin_async_callback { + case $1 in + prompt_sorin_async_git) + # We can safely split on ':' because it isn't allowed in ref names. + IFS=':' read _git_target _git_post_target <<<"$3" + + # The target actually contains 3 space separated possibilities, so we need to + # make sure we grab the first one. + _git_target=$(coalesce ${(@)${(z)_git_target}}) + + if [[ -z "$_git_target" ]]; then + # No git target detected, flush the git fragment and redisplay the prompt. + if [[ -n "$_prompt_sorin_git" ]]; then + _prompt_sorin_git='' + zle && zle reset-prompt + fi + else + # Git target detected, update the git fragment and redisplay the prompt. + _prompt_sorin_git="${_git_target}${_git_post_target}" + zle && zle reset-prompt + fi + ;; + esac } function prompt_sorin_async_git { @@ -62,6 +65,22 @@ function prompt_sorin_async_git { fi } +function prompt_sorin_async_tasks { + # Initialize async worker. This needs to be done here and not in + # prompt_sorin_setup so the git formatting can be overridden by other prompts. + if (( !${prompt_prezto_async_init:-0} )); then + async_start_worker prompt_sorin -n + async_register_callback prompt_sorin prompt_sorin_async_callback + typeset -g prompt_prezto_async_init=1 + fi + + # Kill the old process of slow commands if it is still running. + async_flush_jobs prompt_sorin + + # Compute slow commands in the background. + async_job prompt_sorin prompt_sorin_async_git "$PWD" +} + function prompt_sorin_precmd { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS @@ -69,9 +88,6 @@ function prompt_sorin_precmd { # Format PWD. _prompt_sorin_pwd=$(prompt-pwd) - # Kill the old process of slow commands if it is still running. - async_flush_jobs async_sorin_git - # Handle updating git data. We also clear the git prompt data if we're in a # different git root now. if (( $+functions[git-dir] )); then @@ -82,14 +98,12 @@ function prompt_sorin_precmd { fi fi - # Run python info (this should be fast and not require any async) if (( $+functions[python-info] )); then python-info fi - # Compute slow commands in the background. - async_job async_sorin_git prompt_sorin_async_git "$PWD" + prompt_sorin_async_tasks } function prompt_sorin_setup { @@ -140,8 +154,6 @@ function prompt_sorin_setup { zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} ' # Get the async worker set up - async_start_worker async_sorin_git -n - async_register_callback async_sorin_git prompt_sorin_git_info _sorin_cur_git_root='' _prompt_sorin_git='' diff --git a/modules/python/README.md b/modules/python/README.md index 27d18e62d6..e7b72c480b 100644 --- a/modules/python/README.md +++ b/modules/python/README.md @@ -3,6 +3,23 @@ Python Enables local Python and local Python package installation. +Settings +-------- + +This module supports virtual environments from conda and virtualenvwrapper. By default, only virtualenvwrapper is enabled. To disable virtualenvwrapper, add the following to *zpreztorc*. + +```sh +zstyle ':prezto:module:python' skip-virtualenvwrapper-init 'on' +``` + +Conda support is enabled by adding the following to *zpreztorc*. + +```sh +zstyle ':prezto:module:python' conda-init 'on' +``` + +Caution: using conda and virtualenvwrapper at the same time may cause conflicts. + Local Python Installation ------------------------- @@ -93,7 +110,7 @@ zstyle ':prezto:module:python:virtualenv' auto-switch 'yes' (`$VIRTUALENVWRAPPER_VIRTUALENV` is explicitly set or `virtualenv` is in `$PATH`). This can be disabled with: -``` +```sh zstyle ':prezto:module:python:virtualenv' initialize 'no' ``` @@ -122,6 +139,10 @@ following style in the `prompt_name_setup` function. Then add `$python_info[virtualenv]` to `$PROMPT` or `$RPROMPT` and call `python-info` in the `prompt_name_preexec` hook function. +Similarly, you can use `:prezto:module:python:info:version:format` with `%v` for +the version and add `$python_info[version]` to your prompt for the current +python version/ + Authors ------- diff --git a/modules/python/functions/python-info b/modules/python/functions/python-info index a616814c8a..144a5b6a29 100644 --- a/modules/python/functions/python-info +++ b/modules/python/functions/python-info @@ -4,22 +4,50 @@ # # Authors: # Sorin Ionescu +# Patrick Bos # # function python-info { local virtualenv_format local virtualenv_formatted +local version_format +local version_formatted +local version # Clean up previous $python_info. unset python_info typeset -gA python_info +# Grab the styling we might have to do +zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format' +zstyle -s ':prezto:module:python:info:version' format 'version_format' + # Format virtualenv. -if [[ -n "$VIRTUAL_ENV" ]]; then - zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format' - zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}" - python_info[virtualenv]="$virtualenv_formatted" +if [[ -n "$virtualenv_format" ]]; then + if [[ -n "$VIRTUAL_ENV" ]]; then + zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}" + python_info[virtualenv]="$virtualenv_formatted" + fi + + # Do the same for Conda virtual environments + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + zformat -f virtualenv_formatted "$virtualenv_format" "v:${CONDA_DEFAULT_ENV:t}" + python_info[virtualenv]="$virtualenv_formatted" + fi +fi + +if [[ -n "$version_format" ]]; then + if (( $+commands[pyenv] )); then + version="${"$(pyenv version)"%% *}" + elif (( $+commands[python] )); then + version="${$(python3 --version)#Python }" + fi + + if [[ -n "$version" && "$version" != "system" ]]; then + zformat -f version_formatted "$version_format" "v:$version" + python_info[version]="$version_formatted" + fi fi # } diff --git a/modules/python/init.zsh b/modules/python/init.zsh index 6f8ae7f128..45e9b8dd6b 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -4,6 +4,7 @@ # Authors: # Sorin Ionescu # Sebastian Wiesner +# Patrick Bos # # Load manually installed pyenv into the shell session. @@ -18,7 +19,7 @@ elif (( $+commands[pyenv] )); then eval "$(pyenv init -)" # Prepend PEP 370 per user site packages directory, which defaults to -# ~/Library/Python on Mac OS X and ~/.local elsewhere, to PATH. The +# ~/Library/Python on macOS and ~/.local elsewhere, to PATH. The # path can be overridden using PYTHONUSERBASE. else if [[ -n "$PYTHONUSERBASE" ]]; then @@ -81,6 +82,7 @@ function _python-workon-cwd { # Load auto workon cwd hook if zstyle -t ':prezto:module:python:virtualenv' auto-switch 'yes'; then # Auto workon when changing directory + autoload -Uz add-zsh-hook add-zsh-hook chpwd _python-workon-cwd fi @@ -92,7 +94,7 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \ export WORKON_HOME="${WORKON_HOME:-$HOME/.virtualenvs}" # Disable the virtualenv prompt. - VIRTUAL_ENV_DISABLE_PROMPT=1 + export VIRTUAL_ENV_DISABLE_PROMPT=1 # Create a sorted array of available virtualenv related 'pyenv' commands to # look for plugins of interest. Scanning shell '$path' isn't enough as they @@ -113,6 +115,19 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \ else # Fallback to 'virtualenvwrapper' without 'pyenv' wrapper if available # in '$path' or in an alternative location on a Debian based system. + # + # If homebrew is installed and the python location wasn't overridden via + # environment variable we fall back to python3 then python2 in that order. + # This is needed to fix an issue with virtualenvwrapper as homebrew no + # longer shadows the system python. + if [[ -z "$VIRTUALENVWRAPPER_PYTHON" ]] && (( $+commands[brew] )); then + if (( $+commands[python3] )); then + export VIRTUALENVWRAPPER_PYTHON=$commands[python3] + elif (( $+commands[python2] )); then + export VIRTUALENVWRAPPER_PYTHON=$commands[python2] + fi + fi + virtenv_sources=( ${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]} /usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN) @@ -129,12 +144,14 @@ fi # Load PIP completion. if (( $#commands[(i)pip(|[23])] )); then - cache_file="${0:h}/cache.zsh" + cache_file="${TMPDIR:-/tmp}/prezto-python-cache.$UID.zsh" # Detect and use one available from among 'pip', 'pip2', 'pip3' variants pip_command="$commands[(i)pip(|[23])]" - if [[ "$pip_command" -nt "$cache_file" || ! -s "$cache_file" ]]; then + if [[ "$pip_command" -nt "$cache_file" \ + || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ + || ! -s "$cache_file" ]]; then # pip is slow; cache its output. And also support 'pip2', 'pip3' variants $pip_command completion --zsh \ | sed -e "s|compctl -K [-_[:alnum:]]* pip|& pip2 pip3|" >! "$cache_file" 2> /dev/null @@ -144,6 +161,19 @@ if (( $#commands[(i)pip(|[23])] )); then unset cache_file pip_command fi +# Load conda into the shell session, if requested +zstyle -T ':prezto:module:python' conda-init +if (( $? && $+commands[conda] )); then + if (( $(conda ..changeps1) )); then + echo "To make sure Conda doesn't change your prompt (should do that in the prompt module) run:\n conda config --set changeps1 false" + # TODO: + # We could just run this ourselves. In an exit hook + # (add zsh-hook zshexit [(anonymous) function]) we could then set it back + # to the way it was before we changed it. However, I'm not sure if this is + # exception safe, so left it like this for now. + fi +fi + # # Aliases # diff --git a/modules/rsync/README.md b/modules/rsync/README.md index b418780b87..77d78ea54c 100644 --- a/modules/rsync/README.md +++ b/modules/rsync/README.md @@ -3,7 +3,7 @@ Rsync Defines [rsync][1] aliases. -Mac OS X users are encouraged to use [Bombich's rsync][2], which has HFS+ +macOS users are encouraged to use [Bombich's rsync][2], which has HFS+ enhancements. Aliases diff --git a/modules/rsync/init.zsh b/modules/rsync/init.zsh index 3afebdb4dd..a802222fac 100644 --- a/modules/rsync/init.zsh +++ b/modules/rsync/init.zsh @@ -20,7 +20,7 @@ if grep -q 'xattrs' <(rsync --help 2>&1); then _rsync_cmd="${_rsync_cmd} --acls --xattrs" fi -# Mac OS X and HFS+ Enhancements +# macOS and HFS+ Enhancements # http://help.bombich.com/kb/overview/credits#opensource if [[ "$OSTYPE" == darwin* ]] && grep -q 'file-flags' <(rsync --help 2>&1); then _rsync_cmd="${_rsync_cmd} --crtimes --fileflags --protect-decmpfs --force-change" diff --git a/modules/ruby/functions/ruby-info b/modules/ruby/functions/ruby-info index d53435b42e..cba0188f98 100644 --- a/modules/ruby/functions/ruby-info +++ b/modules/ruby/functions/ruby-info @@ -16,19 +16,23 @@ local version_formatted unset ruby_info typeset -gA ruby_info -if (( $+commands[rvm-prompt] )); then - version="$(rvm-prompt)" -elif (( $+commands[rbenv] )); then - version="$(rbenv version-name)" -elif (( $+commands[ruby] )); then - version="${${$(ruby --version)[(w)1,(w)2]}/ /-}" -fi +# Grab formatting for anything we might have to do +zstyle -s ':prezto:module:ruby:info:version' format 'version_format' + +if [[ -n "$version_format" ]]; then + if (( $+commands[rvm-prompt] )); then + version="$(rvm-prompt)" + elif (( $+commands[rbenv] )); then + version="$(rbenv version-name)" + elif (( $+commands[ruby] )); then + version="${${$(ruby --version)[(w)1,(w)2]}/ /-}" + fi -# Format version. -if [[ -n "$version" ]]; then - zstyle -s ':prezto:module:ruby:info:version' format 'version_format' - zformat -f version_formatted "$version_format" "v:$version" - ruby_info[version]="$version_formatted" + # Format version. + if [[ -n "$version" && "$version" != "system" ]]; then + zformat -f version_formatted "$version_format" "v:$version" + ruby_info[version]="$version_formatted" + fi fi # } diff --git a/modules/ruby/init.zsh b/modules/ruby/init.zsh index 3f666c3e0b..4ede36675f 100644 --- a/modules/ruby/init.zsh +++ b/modules/ruby/init.zsh @@ -25,9 +25,14 @@ elif (( $+commands[rbenv] )); then # Load package manager installed chruby into the shell session. elif (( $+commands[chruby-exec] )); then - source "${commands[chruby-exec]:h:h}/share/chruby/chruby.sh" + if (( ! $+functions[chruby] )); then + source "${commands[chruby-exec]:h:h}/share/chruby/chruby.sh" + fi + if zstyle -t ':prezto:module:ruby:chruby' auto-switch; then - source "${commands[chruby-exec]:h:h}/share/chruby/auto.sh" + if (( ! $+functions[chruby_auto] )); then + source "${commands[chruby-exec]:h:h}/share/chruby/auto.sh" + fi # If a default Ruby is set, switch to it. chruby_auto diff --git a/modules/tmux/README.md b/modules/tmux/README.md index 3d742ba684..0738d7cfad 100644 --- a/modules/tmux/README.md +++ b/modules/tmux/README.md @@ -62,7 +62,7 @@ Aliases Caveats ------- -On Mac OS X, launching tmux can cause the error **launch_msg(...): Socket is not +On macOS, launching tmux can cause the error **launch_msg(...): Socket is not connected** to be displayed, which can be fixed by installing [reattach-to-user-namespace][3], available in [Homebrew][4], and adding the following to *tmux.conf*: @@ -71,7 +71,7 @@ following to *tmux.conf*: set-option -g default-command "reattach-to-user-namespace -l $SHELL -l" ``` -Furthermore, tmux is known to cause **kernel panics** on Mac OS X. A discussion +Furthermore, tmux is known to cause **kernel panics** on macOS. A discussion about this and Prezto has already been [opened][2]. Authors diff --git a/modules/tmux/init.zsh b/modules/tmux/init.zsh index a361a6a60b..fb56d07603 100644 --- a/modules/tmux/init.zsh +++ b/modules/tmux/init.zsh @@ -23,7 +23,7 @@ if ([[ "$TERM_PROGRAM" = 'iTerm.app' ]] && \ _tmux_iterm_integration='-CC' fi -if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" ]] && ( \ +if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && -z "$VSCODE_PID" ]] && ( \ ( [[ -n "$SSH_TTY" ]] && zstyle -t ':prezto:module:tmux:auto-start' remote ) || ( [[ -z "$SSH_TTY" ]] && zstyle -t ':prezto:module:tmux:auto-start' local ) \ ); then diff --git a/modules/utility/README.md b/modules/utility/README.md index a2b93be330..84e81f5c28 100644 --- a/modules/utility/README.md +++ b/modules/utility/README.md @@ -153,7 +153,7 @@ Functions ### Developer - - `diff` highlights diff output (requires `colordiff` or `Git`). + - `diff` highlights diff output (requires `colordiff`). - `make` highlights make output (requires `colormake`). - `wdiff` highlights wdiff output (requires `wdiff `or `Git`). diff --git a/modules/utility/functions/diff b/modules/utility/functions/diff index 51806e81b7..d614b28bda 100644 --- a/modules/utility/functions/diff +++ b/modules/utility/functions/diff @@ -6,12 +6,9 @@ # function diff { - if zstyle -t ':prezto:module:utility:diff' color; then - if (( $+commands[colordiff] )); then + if zstyle -t ':prezto:module:utility:diff' color \ + && (( $+commands[colordiff] )); then command colordiff "$@" - else - command diff "$@" - fi else command diff "$@" fi diff --git a/modules/utility/functions/wdiff b/modules/utility/functions/wdiff index c93ead1c6d..ebfad0b82f 100644 --- a/modules/utility/functions/wdiff +++ b/modules/utility/functions/wdiff @@ -17,7 +17,7 @@ function wdiff { "$@" \ | sed 's/^\(@@\( [+-][[:digit:]]*,[[:digit:]]*\)\{2\} @@\)$/;5;6m\10m/g' elif (( $+commands[git] )); then - git --no-pager diff --color=auto --no-ext-diff --no-index --color-words "$@" + command git --no-pager diff --color=auto --no-ext-diff --no-index --color-words "$@" else command wdiff "$@" fi diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index 75e72b26a3..942090d777 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -41,8 +41,8 @@ alias ftp='noglob ftp' alias history='noglob history' alias locate='noglob locate' alias rake='noglob rake' -alias rsync='noglob noremoteglob rsync' -alias scp='noglob noremoteglob scp' +alias rsync='noglob rsync' +alias scp='noglob scp' alias sftp='noglob sftp' # Define general aliases. @@ -76,10 +76,13 @@ if is-callable 'dircolors'; then alias ls='ls --group-directories-first' if zstyle -t ':prezto:module:utility:ls' color; then - if [[ -s "$HOME/.dir_colors" ]]; then - eval "$(dircolors --sh "$HOME/.dir_colors")" - else - eval "$(dircolors --sh)" + # Call dircolors to define colors if they're missing + if [[ -z "$LS_COLORS" ]]; then + if [[ -s "$HOME/.dir_colors" ]]; then + eval "$(dircolors --sh "$HOME/.dir_colors")" + else + eval "$(dircolors --sh)" + fi fi alias ls="${aliases[ls]:-ls} --color=auto" @@ -89,11 +92,15 @@ if is-callable 'dircolors'; then else # BSD Core Utilities if zstyle -t ':prezto:module:utility:ls' color; then - # Define colors for BSD ls. - export LSCOLORS='exfxcxdxbxGxDxabagacad' + # Define colors for BSD ls if they're not already defined + if [[ -z "$LSCOLORS" ]]; then + export LSCOLORS='exfxcxdxbxGxDxabagacad' + fi - # Define colors for the completion system. - export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:' + # Define colors for the completion system if they're not already defined + if [[ -z "$LS_COLORS" ]]; then + export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:' + fi alias ls="${aliases[ls]:-ls} -G" else @@ -121,7 +128,7 @@ if zstyle -t ':prezto:module:utility:grep' color; then alias grep="${aliases[grep]:-grep} --color=auto" fi -# Mac OS X Everywhere +# macOS Everywhere if [[ "$OSTYPE" == darwin* ]]; then alias o='open' elif [[ "$OSTYPE" == cygwin* ]]; then @@ -151,12 +158,7 @@ elif (( $+commands[wget] )); then fi # Resource Usage -if (( $+commands[pydf] )); then - alias df=pydf -else - alias df='df -kh' -fi - +alias df='df -kh' alias du='du -kh' if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then @@ -223,6 +225,10 @@ function psu { # Example: # - Local: '*.txt', './foo:2017*.txt', '/var/*:log.txt' # - Remote: user@localhost:foo/ +# +# NOTE: This function is buggy and is not used anywhere until we can make sure +# it's fixed. See https://github.com/sorin-ionescu/prezto/issues/1443 and +# https://github.com/sorin-ionescu/prezto/issues/1521 for more information. function noremoteglob { local -a argo local cmd="$1" diff --git a/runcoms/zlogin b/runcoms/zlogin index 30549f33f6..16fae45e0f 100644 --- a/runcoms/zlogin +++ b/runcoms/zlogin @@ -14,10 +14,13 @@ fi } &! -# Print a random, hopefully interesting, adage. -if (( $+commands[fortune] )); then - if [[ -t 0 || -t 1 ]]; then +# Execute code only if STDERR is bound to a TTY. +[[ -o INTERACTIVE && -t 2 ]] && { + + # Print a random, hopefully interesting, adage. + if (( $+commands[fortune] )); then fortune -s print fi -fi + +} >&2 diff --git a/runcoms/zlogout b/runcoms/zlogout index 7c27e88581..56b6b5515e 100644 --- a/runcoms/zlogout +++ b/runcoms/zlogout @@ -5,9 +5,14 @@ # Sorin Ionescu # +# Execute code only if STDERR is bound to a TTY. +[[ -o INTERACTIVE && -t 2 ]] && { + # Print the message. cat <<-EOF Thank you. Come again! -- Dr. Apu Nahasapeemapetilon EOF + +} >&2 diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index 1d7bef2c9a..42eacfca6b 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -15,6 +15,9 @@ # Color output (auto set to 'no' on dumb terminals). zstyle ':prezto:*:*' color 'yes' +# Add additional directories to load prezto modules from +# zstyle ':prezto:load' pmodule-dirs $HOME/.zprezto-contrib + # Set the Zsh modules to load (man zshmodules). # zstyle ':prezto:load' zmodule 'attr' 'stat' @@ -111,7 +114,7 @@ zstyle ':prezto:module:history-substring-search' color 'yes' # zstyle ':prezto:module:history-substring-search' globbing-flags '' # -# OS X +# macOS # # Set the keyword used by `mand` to open man pages in Dash.app