diff --git a/.gitmodules b/.gitmodules index fcc482621e..547effa3e7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,6 +28,8 @@ [submodule "modules/prompt/external/powerlevel9k"] path = modules/prompt/external/powerlevel9k url = https://github.com/bhilburn/powerlevel9k.git + shallow = true [submodule "modules/prompt/external/powerlevel10k"] path = modules/prompt/external/powerlevel10k url = https://github.com/romkatv/powerlevel10k.git + shallow = true diff --git a/README.md b/README.md index 552784bae7..45ef61ce40 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Updating Run `zprezto-update` to automatically check if there is an update to zprezto. If there are no file conflicts, zprezto and its submodules will be -automatically updated. If there are conflicts you will instructed to go into +automatically updated. If there are conflicts you will be instructed to go into the `$ZPREZTODIR` directory and resolve them yourself. To pull the latest changes and update submodules manually: diff --git a/modules/command-not-found/init.zsh b/modules/command-not-found/init.zsh index f3d7ea6287..35884ce6e0 100644 --- a/modules/command-not-found/init.zsh +++ b/modules/command-not-found/init.zsh @@ -21,11 +21,12 @@ elif (( $+commands[brew] )); then "$(brew --repository 2> /dev/null)"/Library/Taps/*/*/cmd/brew-command-not-found-init(|.rb)(.N) ) if (( $#cnf_command )); then - cache_file="${TMPDIR:-/tmp}/prezto-brew-command-not-found-cache.$UID.zsh" + cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/brew-command-not-found-cache.zsh" if [[ "${${(@o)cnf_command}[1]}" -nt "$cache_file" \ || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ || ! -s "$cache_file" ]]; then + mkdir -p "$cache_file:h" # brew command-not-found-init is slow; cache its output. brew command-not-found-init >! "$cache_file" 2> /dev/null fi diff --git a/modules/completion/init.zsh b/modules/completion/init.zsh index 07acf13bf3..4cf46fa95d 100644 --- a/modules/completion/init.zsh +++ b/modules/completion/init.zsh @@ -32,13 +32,16 @@ unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor. # cache time of 20 hours, so it should almost always regenerate the first time a # shell is opened each day. autoload -Uz compinit -_comp_files=(${ZDOTDIR:-$HOME}/.zcompdump(Nm-20)) -if (( $#_comp_files )); then - compinit -i -C +_comp_path="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/zcompdump" +# #q expands globs in conditional expressions +if [[ $_comp_path(#qNmh-20) ]]; then + # -C (skip function check) implies -i (skip security check). + compinit -C -d "$_comp_path" else - compinit -i + mkdir -p "$_comp_path:h" + compinit -i -d "$_comp_path" fi -unset _comp_files +unset _comp_path # # Styles @@ -46,7 +49,7 @@ unset _comp_files # Use caching to make completion for commands such as dpkg and apt usable. zstyle ':completion::complete:*' use-cache on -zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-$HOME}/.zcompcache" +zstyle ':completion::complete:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/prezto/zcompcache" # Case-insensitive (all), partial-word, and then substring completion. if zstyle -t ':prezto:module:completion:*' case-sensitive; then diff --git a/modules/editor/init.zsh b/modules/editor/init.zsh index 28a2fb24a0..5b411f58a9 100644 --- a/modules/editor/init.zsh +++ b/modules/editor/init.zsh @@ -318,6 +318,7 @@ bindkey -M vicmd "$key_info[Control]X$key_info[Control]E" edit-command-line # Undo/Redo bindkey -M vicmd "u" undo +bindkey -M viins "$key_info[Control]_" undo bindkey -M vicmd "$key_info[Control]R" redo if (( $+widgets[history-incremental-pattern-search-backward] )); then diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index 37babd8e3e..f948789ec8 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -19,7 +19,7 @@ fi # Initialization # -cache_file="${TMPDIR:-/tmp}/prezto-fasd-cache.$UID.zsh" +cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/fasd-cache.zsh" if [[ "${commands[fasd]}" -nt "$cache_file" \ || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ || ! -s "$cache_file" ]]; then @@ -31,6 +31,7 @@ if [[ "${commands[fasd]}" -nt "$cache_file" \ init_args+=(zsh-ccomp zsh-ccomp-install zsh-wcomp zsh-wcomp-install) fi + mkdir -p "$cache_file:h" # Cache init code. fasd --init "$init_args[@]" >! "$cache_file" 2> /dev/null fi diff --git a/modules/git/alias.zsh b/modules/git/alias.zsh index 6d99ba8100..630db39af0 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -100,7 +100,9 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then alias gfc='git clone' alias gfcr='git clone --recurse-submodules' alias gfm='git pull' + alias gfma='git pull --autostash' alias gfr='git pull --rebase' + alias gfra='git pull --rebase --autostash' # Flow (F) alias gFi='git flow init' @@ -191,7 +193,7 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then alias gls='git log --topo-order --stat --pretty=format:"${_git_log_medium_format}"' alias gld='git log --topo-order --stat --patch --full-diff --pretty=format:"${_git_log_medium_format}"' alias glo='git log --topo-order --pretty=format:"${_git_log_oneline_format}"' - alias glg='git log --topo-order --all --graph --pretty=format:"${_git_log_graph_format}"' + alias glg='git log --topo-order --all --graph --pretty=format:"${_git_log_oneline_format}"' alias glb='git log --topo-order --pretty=format:"${_git_log_brief_format}"' alias glc='git shortlog --summary --numbered' alias glS='git log --patch --pretty=format:"${_git_log_oneline_format}" -S' diff --git a/modules/git/functions/git-info b/modules/git/functions/git-info index fe8ca2acd9..20c284b08c 100644 --- a/modules/git/functions/git-info +++ b/modules/git/functions/git-info @@ -275,7 +275,7 @@ function git-info { # Format ahead. if [[ -n "$ahead_format" ]]; then - ahead="$ahead_and_behind[(w)1]" + ahead="$ahead_and_behind[(pws:\t:)1]" if (( ahead > 0 )); then zformat -f ahead_formatted "$ahead_format" "A:$ahead" fi @@ -283,7 +283,7 @@ function git-info { # Format behind. if [[ -n "$behind_format" ]]; then - behind="$ahead_and_behind[(w)2]" + behind="$ahead_and_behind[(pws:\t:)2]" if (( behind > 0 )); then zformat -f behind_formatted "$behind_format" "B:$behind" fi diff --git a/modules/gpg/init.zsh b/modules/gpg/init.zsh index 4498b7b066..a3b37ba3bc 100644 --- a/modules/gpg/init.zsh +++ b/modules/gpg/init.zsh @@ -12,7 +12,7 @@ fi # Set the default paths to gpg-agent files. _gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf" -_gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID" +_gpg_agent_env="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/gpg-agent.env" # Load environment variables from previous run source "$_gpg_agent_env" 2> /dev/null @@ -21,6 +21,7 @@ source "$_gpg_agent_env" 2> /dev/null if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" ]]; then # Start gpg-agent if not started. if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then + mkdir -p "$_gpg_agent_env:h" eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")" fi fi diff --git a/modules/haskell/init.zsh b/modules/haskell/init.zsh index c1c78ca2a0..cb76864122 100644 --- a/modules/haskell/init.zsh +++ b/modules/haskell/init.zsh @@ -10,8 +10,11 @@ if (( ! $+commands[ghc] )); then return 1 fi +# Load dependencies. +pmodload 'helper' + # Prepend Cabal per user directories to PATH. -if [[ "$OSTYPE" == darwin* && -d $HOME/Library/Haskell ]]; then +if is-darwin && [[ -d $HOME/Library/Haskell ]]; then path=($HOME/Library/Haskell/bin(/N) $path) else path=($HOME/.cabal/bin(/N) $path) diff --git a/modules/helper/init.zsh b/modules/helper/init.zsh index 328bed4f71..0553556a49 100644 --- a/modules/helper/init.zsh +++ b/modules/helper/init.zsh @@ -29,3 +29,28 @@ function coalesce { done return 1 } + +# is true on MacOS Darwin +function is-darwin { + [[ "$OSTYPE" == darwin* ]] +} + +# is true on Linux's +function is-linux { + [[ "$OSTYPE" == linux* ]] +} + +# is true on BSD's +function is-bsd { + [[ "$OSTYPE" == *bsd* ]] +} + +# is true on Cygwin (Windows) +function is-cygwin { + [[ "$OSTYPE" == cygwin* ]] +} + +# is true on termux (Android) +function is-termux { + [[ "$OSTYPE" == linux-android ]] +} diff --git a/modules/history-substring-search/init.zsh b/modules/history-substring-search/init.zsh index d3ee3a1131..0de78918dc 100644 --- a/modules/history-substring-search/init.zsh +++ b/modules/history-substring-search/init.zsh @@ -10,7 +10,9 @@ pmodload 'editor' # Source module files. -source "${0:h}/external/zsh-history-substring-search.zsh" || return 1 +if (( ! $+functions[history-substring-search-up] )); then + source "${0:h}/external/zsh-history-substring-search.zsh" || return 1 +fi # # Search diff --git a/modules/homebrew/init.zsh b/modules/homebrew/init.zsh index 9f7e0b4646..bfa667c0bc 100644 --- a/modules/homebrew/init.zsh +++ b/modules/homebrew/init.zsh @@ -5,8 +5,11 @@ # Sorin Ionescu # +# Load dependencies. +pmodload 'helper' + # Return if requirements are not found. -if [[ "$OSTYPE" != (darwin|linux)* ]]; then +if ! is-darwin && ! is-linux; then return 1 fi diff --git a/modules/macports/init.zsh b/modules/macports/init.zsh index d55744a875..7bf4ab2940 100644 --- a/modules/macports/init.zsh +++ b/modules/macports/init.zsh @@ -6,8 +6,11 @@ # Sorin Ionescu # +# Load dependencies. +pmodload 'helper' + # Return if requirements are not found. -if [[ "$OSTYPE" != darwin* ]]; then +if ! is-darwin; then return 1 fi diff --git a/modules/node/init.zsh b/modules/node/init.zsh index 1ea66f9c6c..6fb68f307d 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -39,12 +39,13 @@ typeset -A compl_commands=( for compl_command in "${(k)compl_commands[@]}"; do if (( $+commands[$compl_command] )); then - cache_file="${TMPDIR:-/tmp}/prezto-$compl_command-cache.$UID.zsh" + cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/$compl_command-cache.zsh" # Completion commands are slow; cache their output if old or missing. if [[ "$commands[$compl_command]" -nt "$cache_file" \ || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ || ! -s "$cache_file" ]]; then + mkdir -p "$cache_file:h" command ${=compl_commands[$compl_command]} >! "$cache_file" 2> /dev/null fi diff --git a/modules/osx/init.zsh b/modules/osx/init.zsh index f7871ca718..62f219437b 100644 --- a/modules/osx/init.zsh +++ b/modules/osx/init.zsh @@ -5,8 +5,11 @@ # Sorin Ionescu # +# Load dependencies. +pmodload 'helper' + # Return if requirements are not found. -if [[ "$OSTYPE" != darwin* ]]; then +if ! is-darwin; then return 1 fi diff --git a/modules/pacman/functions/pacman-list-disowned b/modules/pacman/functions/pacman-list-disowned index 9c8f56a0e9..c5e84fcf67 100644 --- a/modules/pacman/functions/pacman-list-disowned +++ b/modules/pacman/functions/pacman-list-disowned @@ -8,11 +8,11 @@ # function pacman-list-disowned { -local tmp="${TMPDIR:-/tmp}/pacman-disowned-$UID-$$" +local tmp="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/pacman-disowned-$$" local db="$tmp/db" local fs="$tmp/fs" -mkdir "$tmp" +mkdir -p "$tmp" trap 'rm -rf "$tmp"' EXIT pacman --quiet --query --list | sort --unique > "$db" diff --git a/modules/perl/init.zsh b/modules/perl/init.zsh index b7a794797a..1b5e665761 100644 --- a/modules/perl/init.zsh +++ b/modules/perl/init.zsh @@ -10,6 +10,9 @@ if (( ! $+commands[perl] )); then return 1 fi +# Load dependencies. +pmodload 'helper' + # # Load Perlbrew or plenv # @@ -37,13 +40,14 @@ fi # Local Module Installation # -if [[ "$OSTYPE" == darwin* ]]; then +if is-darwin; then # Perl is slow; cache its output. - cache_file="${TMPDIR:-/tmp}/prezto-perl-cache.$UID.zsh" + cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/perl-cache.zsh" perl_path="$HOME/Library/Perl/5.12" if [[ -f "$perl_path/lib/perl5/local/lib.pm" ]]; then if [[ "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" || ! -s "$cache_file" ]]; then + mkdir -p "$cache_file:h" perl -I$perl_path/lib/perl5 -Mlocal::lib=$perl_path >! "$cache_file" fi diff --git a/modules/prompt/functions/prompt_sorin_setup b/modules/prompt/functions/prompt_sorin_setup index 41ac7d0175..a7d341ee8d 100644 --- a/modules/prompt/functions/prompt_sorin_setup +++ b/modules/prompt/functions/prompt_sorin_setup @@ -54,6 +54,13 @@ function prompt_sorin_async_callback { zle && zle reset-prompt fi ;; + "[async]") + # Code is 1 for corrupted worker output and 2 for dead worker. + if [[ $2 -eq 2 ]]; then + # Our worker died unexpectedly. + typeset -g prompt_prezto_async_init=0 + fi + ;; esac } diff --git a/modules/python/init.zsh b/modules/python/init.zsh index e5967f7aa8..b878f04978 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -7,6 +7,9 @@ # Patrick Bos # +# Load dependencies +pmodload 'helper' + # Load manually installed pyenv into the path if [[ -s "${PYENV_ROOT:=$HOME/.pyenv}/bin/pyenv" ]]; then path=("${PYENV_ROOT}/bin" $path) @@ -22,7 +25,7 @@ elif (( $+commands[pyenv] )); then else if [[ -n "$PYTHONUSERBASE" ]]; then path=($PYTHONUSERBASE/bin $path) - elif [[ "$OSTYPE" == darwin* ]]; then + elif is-darwin; then path=($HOME/Library/Python/*/bin(N) $path) else # This is subject to change. @@ -68,7 +71,7 @@ function _python-workon-cwd { if [[ "$ENV_NAME" != "" ]]; then # Activate the environment only if it is not already active if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then - if [[ -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then + if [[ -n "$WORKON_HOME" && -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME" elif [[ -e "$ENV_NAME/bin/activate" ]]; then source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME" @@ -144,17 +147,25 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \ fi # Load PIP completion. -if (( $#commands[(i)pip(|[23])] )); then - cache_file="${TMPDIR:-/tmp}/prezto-pip-cache.$UID.zsh" - - # Detect and use one available from among 'pip', 'pip2', 'pip3' variants +# Detect and use one available from among 'pip', 'pip2', 'pip3' variants +if [[ -n "$PYENV_ROOT" ]]; then + for pip in pip{,2,3}; do + pip_command="$(pyenv which "$pip" 2>/dev/null)" + [[ -n "$pip_command" ]] && break + done + unset pip +else pip_command="$commands[(i)pip(|[23])]" +fi +if [[ -n "$pip_command" ]]; then + cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/pip-cache.zsh" if [[ "$pip_command" -nt "$cache_file" \ || "${ZDOTDIR:-$HOME}/.zpreztorc" -nt "$cache_file" \ || ! -s "$cache_file" ]]; then + mkdir -p "$cache_file:h" # pip is slow; cache its output. And also support 'pip2', 'pip3' variants - $pip_command completion --zsh \ + "$pip_command" completion --zsh \ | sed -e "s/\(compctl -K [-_[:alnum:]]* pip\).*/\1{,2,3}{,.{0..9}}/" \ >! "$cache_file" \ 2> /dev/null @@ -162,8 +173,9 @@ if (( $#commands[(i)pip(|[23])] )); then source "$cache_file" - unset cache_file pip_command + unset cache_file fi +unset pip_command # Load conda into the shell session, if requested zstyle -T ':prezto:module:python' conda-init diff --git a/modules/rsync/init.zsh b/modules/rsync/init.zsh index b3010ede32..79432c1251 100644 --- a/modules/rsync/init.zsh +++ b/modules/rsync/init.zsh @@ -10,6 +10,9 @@ if (( ! $+commands[rsync] )); then return 1 fi +# Load dependencies. +pmodload 'helper' + # # Aliases # @@ -23,7 +26,7 @@ fi # macOS and HFS+ Enhancements # https://bombich.com/kb/ccc5/credits -if [[ "$OSTYPE" == darwin* ]] && grep -q 'file-flags' <(rsync --help 2>&1); then +if is-darwin && grep -q 'file-flags' <(rsync --help 2>&1); then _rsync_cmd="${_rsync_cmd} --crtimes --fileflags --protect-decmpfs --force-change" fi diff --git a/modules/ssh/init.zsh b/modules/ssh/init.zsh index 08edce5772..b9567d4635 100644 --- a/modules/ssh/init.zsh +++ b/modules/ssh/init.zsh @@ -14,10 +14,10 @@ fi _ssh_dir="$HOME/.ssh" # Set the path to the environment file if not set by another module. -_ssh_agent_env="${_ssh_agent_env:-${TMPDIR:-/tmp}/ssh-agent.env.$UID}" +_ssh_agent_env="${_ssh_agent_env:-${XDG_CACHE_HOME:-$HOME/.cache}/prezto/ssh-agent.env}" # Set the path to the persistent authentication socket. -_ssh_agent_sock="${TMPDIR:-/tmp}/ssh-agent.sock.$UID" +_ssh_agent_sock="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/ssh-agent.sock" # Start ssh-agent if not started. if [[ ! -S "$SSH_AUTH_SOCK" ]]; then @@ -26,12 +26,14 @@ if [[ ! -S "$SSH_AUTH_SOCK" ]]; then # Start ssh-agent if not started. if ! ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${SSH_AGENT_PID:--1} ssh-agent"; then + mkdir -p "$_ssh_agent_env:h" eval "$(ssh-agent | sed '/^echo /d' | tee "$_ssh_agent_env")" fi fi # Create a persistent SSH authentication socket. if [[ -S "$SSH_AUTH_SOCK" && "$SSH_AUTH_SOCK" != "$_ssh_agent_sock" ]]; then + mkdir -p "$_ssh_agent_sock:h" ln -sf "$SSH_AUTH_SOCK" "$_ssh_agent_sock" export SSH_AUTH_SOCK="$_ssh_agent_sock" fi diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index a2e5c2bdfe..7bb753249e 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -134,12 +134,16 @@ if zstyle -t ':prezto:module:utility:grep' color; then fi # macOS Everywhere -if [[ "$OSTYPE" == darwin* ]]; then +if is-darwin; then alias o='open' -elif [[ "$OSTYPE" == cygwin* ]]; then +elif is-cygwin; then alias o='cygstart' alias pbcopy='tee > /dev/clipboard' alias pbpaste='cat /dev/clipboard' +elif is-termux; then + alias o='termux-open' + alias pbcopy='termux-clipboard-set' + alias pbpaste='termux-clipboard-get' else alias o='xdg-open' @@ -166,7 +170,7 @@ fi alias df='df -kh' alias du='du -kh' -if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then +if is-darwin || is-bsd; then alias topc='top -o cpu' alias topm='top -o vsize' else diff --git a/runcoms/zlogin b/runcoms/zlogin index 9ea97929c2..ac4d3422a2 100644 --- a/runcoms/zlogin +++ b/runcoms/zlogin @@ -8,7 +8,7 @@ # Execute code that does not affect the current session in the background. { # Compile the completion dump to increase startup speed. - zcompdump="${ZDOTDIR:-$HOME}/.zcompdump" + zcompdump="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/zcompdump" if [[ -s "$zcompdump" && (! -s "${zcompdump}.zwc" || "$zcompdump" -nt "${zcompdump}.zwc") ]]; then zcompile "$zcompdump" fi