diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..42dd37a6e8 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[{.gitattributes,.gitignore,.gitmodules}] +indent_style = tab diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 444379c1a9..e39ca09868 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,16 +1,15 @@ -Please check if a similar issue already exists or has been closed before before opening your issue. + ### Description - -[Description of the bug or feature] + ### Expected behavior -[What you expected to happen] + ### Actual behavior -[What actually happened] + ### Steps to Reproduce diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2b2f70bfb9..b8548b6ce6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,5 @@ -Please be sure to check out our [contributing guidelines](https://github.com/sorin-ionescu/prezto/blob/master/CONTRIBUTING.md) before submitting your pull request. +Please be sure to check out our [contributing guidelines](https://github.com/sorin-ionescu/prezto/blob/master/CONTRIBUTING.md) +before submitting your pull request. Fixes # diff --git a/.gitignore b/.gitignore index e05465feb9..05e53b63e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.zwc *.zwc.old modules/*/cache.zsh +contrib diff --git a/.gitmodules b/.gitmodules index 6494149210..547effa3e7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "modules/autosuggestions/external"] path = modules/autosuggestions/external - url = https://github.com/zsh-users/zsh-autosuggestions + url = https://github.com/zsh-users/zsh-autosuggestions.git [submodule "modules/history-substring-search/external"] path = modules/history-substring-search/external url = https://github.com/zsh-users/zsh-history-substring-search.git @@ -19,3 +19,17 @@ [submodule "modules/prompt/functions/pure"] path = modules/prompt/external/pure url = https://github.com/sindresorhus/pure.git +[submodule "modules/fasd/external"] + path = modules/fasd/external + url = https://github.com/clvv/fasd.git +[submodule "modules/prompt/external/async"] + path = modules/prompt/external/async + url = https://github.com/mafredri/zsh-async.git +[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/CONTRIBUTING.md b/CONTRIBUTING.md index 5079e6419e..f4dc0d6160 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,15 +25,36 @@ improve its performance, do not hesitate to fork and send pull requests. #### Code Style - - Indent using 2 spaces. No tabs. - - Put `; do` and `; then` on the same line as the `while`, `for` or `if`. +This project follows the [Google Shell Style Guide][5] when possible. However, +there are a number of additional things to keep in mind. + - Local variables should be used whenever possible. - - Use `snake_case` for variable and function naming. - - Local variables should be lower cased. - - Global variables should be upper cased. - - Use `$(command)` instead of backticks. - - Avoid `eval` if possible. - Prefer `zstyle` over environment variables for configuration. + - Prefer (( ... )) over [[ ... ]] for arithmetic expression. + - Use the function keyword to define functions. + - The 80 character hard limit can be waived for readability. + +#### Using an Alternative zprezto Directory + +To work on zprezto without messing with your current configuration: + +```sh +mkdir devel-zprezto +cd devel-zprezto +git clone --recursive https://github.com/sorin-ionescu/prezto.git .zprezto +ZDOTDIR=$(pwd) +echo "Your development ZDOTDIR is $ZDOTDIR" +setopt EXTENDED_GLOB +for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do + ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" +done +``` + +Then to start zsh in this development environment you will run: + +```sh +ZDOTDIR=/path/to/devel-zprezto zsh +``` #### Modules @@ -44,10 +65,11 @@ improve its performance, do not hesitate to fork and send pull requests. #### Themes - A screenshots section must be present in the file header. - - The pull request description must have [embedded screenshots][5]. + - The pull request description must have [embedded screenshots][6]. [1]: https://github.com/sorin-ionescu/prezto/contributors [2]: http://gun.io/blog/how-to-github-fork-branch-and-pull-request [3]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html [4]: https://help.github.com/articles/using-pull-requests -[5]: http://daringfireball.net/projects/markdown/syntax#img +[5]: https://google.github.io/styleguide/shell.xml +[6]: http://daringfireball.net/projects/markdown/syntax#img diff --git a/README.md b/README.md index fee70a492b..552784bae7 100644 --- a/README.md +++ b/README.md @@ -9,35 +9,42 @@ Installation ------------ Prezto will work with any recent release of Zsh, but the minimum required -version is 4.3.17. +version is 4.3.11. 1. Launch Zsh: - `zsh` + ```console + zsh + ``` 2. Clone the repository: - `git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"` + ```console + git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto" + ``` 3. Create a new Zsh configuration by copying the Zsh configuration files provided: - ``` - setopt EXTENDED_GLOB - for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do - ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" - done - ``` - - Note: If you already have any of the given config files, ln will error. In - simple cases you can add `source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"` to - the bottom of your `.zshrc` to load prezto but keep your config intact. For - more complicated setups, it is recommended that you back up your original + ```sh + setopt EXTENDED_GLOB + for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do + ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}" + done + ``` + + Note: If you already have any of the given configuration files, `ln` will + cause error. In simple cases you can load prezto by adding the line + `source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"` to the bottom of your + `.zshrc` and keep the rest of your Zsh configuration intact. For more + complicated setups, it is recommended that you back up your original configs and replace them with the provided prezto runcoms. 4. Set Zsh as your default shell: - `chsh -s /bin/zsh` + ```console + chsh -s /bin/zsh + ``` 5. Open a new Zsh terminal window or tab. @@ -50,9 +57,18 @@ window or tab. Updating -------- -Pull the latest changes and update submodules. +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 +the `$ZPREZTODIR` directory and resolve them yourself. - git pull && git submodule update --init --recursive +To pull the latest changes and update submodules manually: + +```console +cd $ZPREZTODIR +git pull +git submodule update --init --recursive +``` Usage ----- @@ -74,6 +90,23 @@ accompanying README files to learn of what is available. window or tab. ![sorin theme][2] + Note that the 'git' module may be required for special symbols to appear, + such as those on the right of the above image. Add `'git'` to the `pmodule` + list (under `zstyle ':prezto:load' pmodule \` in your *~/.zpreztorc*) to + enable this module. + +### 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. + + ```sh + zstyle ':prezto:load' pmodule-dirs $HOME/.zprezto-contrib + ``` Customization ------------- @@ -98,6 +131,6 @@ This project is licensed under the MIT License. [3]: http://git-scm.com [4]: https://github.com [5]: http://gitimmersion.com -[6]: http://gitref.org +[6]: https://git.github.io/git-reference/ [7]: http://www.bash2zsh.com/zsh_refcard/refcard.pdf [8]: http://grml.org/zsh/zsh-lovers.html diff --git a/init.zsh b/init.zsh index 665e6c40da..ebae912bc9 100644 --- a/init.zsh +++ b/init.zsh @@ -10,13 +10,61 @@ # # Check for the minimum supported version. -min_zsh_version='4.3.17' +min_zsh_version='4.3.11' if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then - print "prezto: old shell detected, minimum required: $min_zsh_version" >&2 + printf "prezto: old shell detected, minimum required: %s\n" "$min_zsh_version" >&2 return 1 fi unset min_zsh_version +# zprezto convenience updater +# The function is surrounded by ( ) instead of { } so it starts in a subshell +# and won't affect the environment of the calling shell +function zprezto-update { + ( + function cannot-fast-forward { + local STATUS="$1" + [[ -n "${STATUS}" ]] && printf "%s\n" "${STATUS}" + printf "Unable to fast-forward the changes. You can fix this by " + printf "running\ncd '%s' and then\n'git pull' " "${ZPREZTODIR}" + printf "to manually pull and possibly merge in changes\n" + } + cd -q -- "${ZPREZTODIR}" || return 7 + local orig_branch="$(git symbolic-ref HEAD 2> /dev/null | cut -d '/' -f 3)" + if [[ "$orig_branch" == "master" ]]; then + git fetch || return "$?" + local UPSTREAM=$(git rev-parse '@{u}') + local LOCAL=$(git rev-parse HEAD) + local REMOTE=$(git rev-parse "$UPSTREAM") + local BASE=$(git merge-base HEAD "$UPSTREAM") + if [[ $LOCAL == $REMOTE ]]; then + printf "There are no updates.\n" + return 0 + elif [[ $LOCAL == $BASE ]]; then + printf "There is an update available. Trying to pull.\n\n" + if git pull --ff-only; then + printf "Syncing submodules\n" + git submodule update --init --recursive + return $? + else + cannot-fast-forward + return 1 + fi + elif [[ $REMOTE == $BASE ]]; then + cannot-fast-forward "Commits in master that aren't in upstream." + return 1 + else + cannot-fast-forward "Upstream and local have diverged." + return 1 + fi + else + printf "zprezto install at '%s' is not on the master branch " "${ZPREZTODIR}" + printf "(you're on '%s')\nUnable to automatically update.\n" "${orig_branch}" + return 1 + fi + return 1 + ) +} # # Module Loader # @@ -24,44 +72,70 @@ unset min_zsh_version # 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 + if ! zstyle -t ':prezto:load' pmodule-allow-overrides 'yes'; then + print "$0: conflicting module locations: $locations" + continue + fi + 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 @@ -71,7 +145,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 db851f3695..1ff4e61225 100644 --- a/modules/README.md +++ b/modules/README.md @@ -3,7 +3,9 @@ Modules Load modules in *zpreztorc*. The order matters. - zstyle ':prezto:load' pmodule 'environment' 'terminal' +```sh +zstyle ':prezto:load' pmodule 'environment' 'terminal' +``` Archive ------- @@ -18,7 +20,7 @@ Integrates zsh-autosuggestions into Prezto. Command-Not-Found ----------------- -Loads the command-not-found tool on Debian-based distributions. +Loads the command-not-found tool on macOS or Debian-based distributions. Completion ---------- @@ -120,7 +122,7 @@ Initializes OCaml package management. OSX --- -Defines Mac OS X aliases and functions. +Defines macOS aliases and functions. Pacman ------ @@ -130,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 a1d49011a3..c9806ea591 100644 --- a/modules/archive/README.md +++ b/modules/archive/README.md @@ -1,11 +1,12 @@ Archive ======= -Provides functions to list and extract archives. +Provides functions to create, list, and extract archives. Functions --------- + - `archive` creates an archive based on the provided archive name. - `lsarchive` lists the contents of one or more archives. - `unarchive` extracts the contents of one or more archives. @@ -15,8 +16,8 @@ Supported Formats The following archive formats are supported when the required utilities are installed: - - *.tar.gz*, *.tgz* require `tar`. - - *.tar.bz2*, *.tbz* require `tar`. + - *.tar.gz*, *.tgz* require `tar` (optionally `pigz`). + - *.tar.bz2*, *.tbz* require `tar` (optionally `pbzip2`). - *.tar.xz*, *.txz* require `tar` with *xz* support. - *.tar.zma*, *.tlz* require `tar` with *lzma* support. - *.tar* requires `tar`. @@ -25,16 +26,27 @@ installed: - *.xz* requires `unxz`. - *.lzma* requires `unlzma`. - *.Z* requires `uncompress`. - - *.zip* requires `unzip`. - - *.rar* requires `unrar` or `rar`. + - *.zip*, *.jar* requires `unzip`. + - *.rar* requires `rar` (needed for `archive` support), `unrar` or `lsar` and `unar`. - *.7z* requires `7za`. - *.deb* requires `ar`, `tar`. +Additionally, if `pigz` and/or `pbzip2` are installed, `archive` will use them +over 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 ------- *The authors of this module should be contacted via the [issue tracker][1].* - [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/archive/functions/_lsarchive b/modules/archive/functions/_lsarchive index 00f83e0584..f2cee88125 100644 --- a/modules/archive/functions/_lsarchive +++ b/modules/archive/functions/_lsarchive @@ -10,4 +10,4 @@ _arguments \ '(-v --verbose)'{-v,--remove}'[verbose archive listing]' \ - "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|rar|7z)(-.)'" && return 0 + "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|jar|rar|7z)(-.)'" && return 0 diff --git a/modules/archive/functions/_unarchive b/modules/archive/functions/_unarchive index aceb27b639..90e32f1a38 100644 --- a/modules/archive/functions/_unarchive +++ b/modules/archive/functions/_unarchive @@ -10,4 +10,4 @@ _arguments \ '(-r --remove)'{-r,--remove}'[remove archive]' \ - "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|rar|7z|deb)(-.)'" && return 0 + "*::archive file:_files -g '(#i)*.(tar|tgz|tbz|tbz2|txz|tlz|gz|bz2|xz|lzma|Z|zip|jar|rar|7z|deb)(-.)'" && return 0 diff --git a/modules/archive/functions/archive b/modules/archive/functions/archive new file mode 100644 index 0000000000..10bbad3985 --- /dev/null +++ b/modules/archive/functions/archive @@ -0,0 +1,73 @@ +#!/usr/bin/env zsh +# +# Creates archive file +# +# Authors: +# Matt Hamilton +# + +# function archive { + +local archive_name path_to_archive _gzip_bin _bzip2_bin _xz_bin + +if (( $# < 2 )); then + cat >&2 < # +# function lsarchive { + local verbose if (( $# == 0 )); then @@ -40,10 +42,12 @@ while (( $# > 0 )); do && tar --lzma -t${verbose:+v}f "$1" \ || lzcat "$1" | tar x${verbose:+v}f - ;; (*.tar) tar t${verbose:+v}f "$1" ;; - (*.zip) unzip -l${verbose:+v} "$1" ;; - (*.rar) unrar &> /dev/null \ - && unrar ${${verbose:+v}:-l} "$1" \ - || rar ${${verbose:+v}:-l} "$1" ;; + (*.zip|*.jar) unzip -l${verbose:+v} "$1" ;; + (*.rar) ( (( $+commands[unrar] )) \ + && unrar ${${verbose:+v}:-l} "$1" ) \ + || ( (( $+commands[rar] )) \ + && rar ${${verbose:+v}:-l} "$1" ) \ + || lsar ${verbose:+-l} "$1" ;; (*.7z) 7za l "$1" ;; (*) print "$0: cannot list: $1" >&2 @@ -53,3 +57,5 @@ while (( $# > 0 )); do shift done + +# } diff --git a/modules/archive/functions/unarchive b/modules/archive/functions/unarchive index 72dfbd1f75..9e38a80cf8 100644 --- a/modules/archive/functions/unarchive +++ b/modules/archive/functions/unarchive @@ -5,11 +5,14 @@ # Sorin Ionescu # +# function unarchive { + local remove_archive local success local file_name local file_path local extract_dir +local _gzip_bin _bzip2_bin _xz_bin if (( $# == 0 )); then cat >&2 < 0 )); do if [[ ! -s "$1" ]]; then print "$0: file not valid: $1" >&2 @@ -40,24 +66,24 @@ while (( $# > 0 )); do file_path="${1:A}" extract_dir="${file_name:r}" case "$1:l" in - (*.tar.gz|*.tgz) tar xvzf "$1" ;; - (*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$1" ;; - (*.tar.xz|*.txz) tar --xz --help &> /dev/null \ - && tar --xz -xvf "$1" \ - || xzcat "$1" | tar xvf - ;; + (*.tar.gz|*.tgz) tar -xvf "$1" --use-compress-program="${_gzip_bin}" ;; + (*.tar.bz2|*.tbz|*.tbz2) tar -xvf "$1" --use-compress-program="${_bzip2_bin}" ;; + (*.tar.xz|*.txz) tar -xvf "$1" --use-compress-program="${_xz_bin}" ;; (*.tar.zma|*.tlz) tar --lzma --help &> /dev/null \ && tar --lzma -xvf "$1" \ - || lzcat "$1" | tar xvf - ;; - (*.tar) tar xvf "$1" ;; + || lzcat "$1" | tar -xvf - ;; + (*.tar) tar -xvf "$1" ;; (*.gz) gunzip "$1" ;; (*.bz2) bunzip2 "$1" ;; (*.xz) unxz "$1" ;; (*.lzma) unlzma "$1" ;; (*.Z) uncompress "$1" ;; - (*.zip) unzip "$1" -d $extract_dir ;; - (*.rar) unrar &> /dev/null \ - && unrar x -ad "$1" \ - || rar x -ad "$1" ;; + (*.zip|*.jar) unzip "$1" -d $extract_dir ;; + (*.rar) ( (( $+commands[unrar] )) \ + && unrar x -ad "$1" ) \ + || ( (( $+commands[rar] )) \ + && rar x -ad "$1" ) \ + || unar -d "$1" ;; (*.7z) 7za x "$1" ;; (*.deb) mkdir -p "$extract_dir/control" @@ -78,3 +104,5 @@ while (( $# > 0 )); do (( $success == 0 )) && (( $remove_archive == 0 )) && rm "$1" shift done + +# } diff --git a/modules/autosuggestions/README.md b/modules/autosuggestions/README.md index 7024379817..48f9852887 100644 --- a/modules/autosuggestions/README.md +++ b/modules/autosuggestions/README.md @@ -1,8 +1,3 @@ -Autosuggestions ---------------- - -Integrates zsh-autosuggestions into Prezto. - Autosuggestions =============== @@ -11,11 +6,12 @@ Integrates [zsh-autosuggestions][1] into Prezto, which implements the of a previously entered command and Zsh suggests commands as you type based on history and completions. -If this module is used in conjuncture with the *syntax-highlighting* module, it -must be loaded **after** it. +If this module is used in conjunction with the *syntax-highlighting* module, +this module must be loaded **after** the *syntax-highlighting* module. -If this module is used in conjuncture with the *history-substring-search* -module, it must be loaded **after** it. +If this module is used in conjunction with the *history-substring-search* +module, this module must be loaded **after** the *history-substring-search* +module. Contributors ------------ @@ -35,11 +31,23 @@ positive results. To enable highlighting for this module only, add the following line to *zpreztorc*: - zstyle ':prezto:module:autosuggestions' color 'yes' +```sh +zstyle ':prezto:module:autosuggestions' color 'yes' +``` To set the query found color, add the following line to *zpreztorc*: - zstyle ':prezto:module:autosuggestions:color' found '' +```sh +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/README.md b/modules/command-not-found/README.md index e969b71af2..ee5a94d6d5 100644 --- a/modules/command-not-found/README.md +++ b/modules/command-not-found/README.md @@ -1,15 +1,24 @@ Command-Not-Found ================= -Displays installation information for not found commands by loading the -[command-not-found][1] tool on Debian-based and Arch Linux-based distributions. +When you try to use a command that is not available locally, searches +the package manager for a package offering that command and suggests +the proper install command. + +Debian and Arch Linux based distributions use the [`command-not-found`][1] tool. + +macOS uses Homebrew's [`command-not-found` clone][2]. Note that you also need to +[follow the instructions][3] to tap the `command-not-found` homebrew repository. + Authors ------- -*The authors of this module should be contacted via the [issue tracker][2].* +*The authors of this module should be contacted via the [issue tracker][4].* - [Joseph Booker](https://github.com/sargas) [1]: https://code.launchpad.net/command-not-found -[2]: https://github.com/sorin-ionescu/prezto/issues +[2]: https://github.com/Homebrew/homebrew-command-not-found +[3]: https://github.com/Homebrew/homebrew-command-not-found#install +[4]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/command-not-found/init.zsh b/modules/command-not-found/init.zsh index 2d9236a00b..35884ce6e0 100644 --- a/modules/command-not-found/init.zsh +++ b/modules/command-not-found/init.zsh @@ -3,6 +3,7 @@ # # Authors: # Joseph Jon Booker +# Indrajit Raychaudhuri # # Load command-not-found on Debian-based distributions. @@ -11,6 +12,31 @@ 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 macOS when Homebrew tap is configured. +# To avoid performance penalty, we do not use Homebrew's ruby based command +# lookup mechanism (viz., `brew command command-not-found-init`) and instead +# `find` it ourselves from `TAP_DIRECTORY` defined internally in Homebrew. +elif (( $+commands[brew] )); then + cnf_command=( + "$(brew --repository 2> /dev/null)"/Library/Taps/*/*/cmd/brew-command-not-found-init(|.rb)(.N) + ) + if (( $#cnf_command )); then + 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 + + source "$cache_file" + + unset cache_file + fi + + unset cnf_command # Return if requirements are not found. else return 1 diff --git a/modules/completion/README.md b/modules/completion/README.md index aaa86fdd2b..dc2b9b837a 100644 --- a/modules/completion/README.md +++ b/modules/completion/README.md @@ -6,6 +6,36 @@ the [zsh-completions][1] project. This module must be loaded **after** the *utility* module. +Options +------- + + - `COMPLETE_IN_WORD` complete from both ends of a word. + - `ALWAYS_TO_END` move cursor to the end of a completed word. + - `PATH_DIRS` perform path search even on command names with slashes. + - `AUTO_MENU` show completion menu on a successive tab press. + - `AUTO_LIST` automatically list choices on ambiguous completion. + - `AUTO_PARAM_SLASH` if completed parameter is a directory, add a trailing slash. + - `EXTENDED_GLOB` needed for file modification glob modifiers with compinit. + - `MENU_COMPLETE` do not autoselect the first completion entry. + - `FLOW_CONTROL` disable start/stop characters in shell editor. + +Settings +-------- + +### Ignore */etc/hosts* Entries + +To ignore certain entries from static */etc/hosts* for host completion, add the +following lines in *zpreztorc* with the IP addresses of the hosts as they +appear in */etc/hosts*. Both IP address and the corresponding hostname will be +ignored during host completion. However, some of the entries ignored from +*/etc/hosts* still might appear during completion because of their presence in +*ssh* configuration or history). + +```sh +zstyle ':prezto:module:completion:*:hosts' etc-host-ignores \ + '0.0.0.0' '127.0.0.1' +``` + Contributors ------------ diff --git a/modules/completion/init.zsh b/modules/completion/init.zsh index 620a9b38e0..4cf46fa95d 100644 --- a/modules/completion/init.zsh +++ b/modules/completion/init.zsh @@ -14,9 +14,6 @@ fi # Add zsh-completions to $fpath. fpath=("${0:h}/external/src" $fpath) -# Load and initialize the completion system ignoring insecure directories. -autoload -Uz compinit && compinit -i - # # Options # @@ -27,16 +24,32 @@ setopt PATH_DIRS # Perform path search even on command names with slas setopt AUTO_MENU # Show completion menu on a successive tab press. setopt AUTO_LIST # Automatically list choices on ambiguous completion. setopt AUTO_PARAM_SLASH # If completed parameter is a directory, add a trailing slash. +setopt EXTENDED_GLOB # Needed for file modification glob modifiers with compinit unsetopt MENU_COMPLETE # Do not autoselect the first completion entry. unsetopt FLOW_CONTROL # Disable start/stop characters in shell editor. +# Load and initialize the completion system ignoring insecure directories with a +# cache time of 20 hours, so it should almost always regenerate the first time a +# shell is opened each day. +autoload -Uz compinit +_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 + mkdir -p "$_comp_path:h" + compinit -i -d "$_comp_path" +fi +unset _comp_path + # # Styles # # 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 @@ -89,14 +102,17 @@ zstyle ':completion:*:history-words' remove-all-dups yes zstyle ':completion:*:history-words' list false zstyle ':completion:*:history-words' menu yes -# Environmental Variables +# Environment Variables zstyle ':completion::*:(-command-|export):*' fake-parameters ${${${_comps[(I)-value-*]#*,}%%,*}:#-*-} -# Populate hostname completion. +# Populate hostname completion. But allow ignoring custom entries from static +# */etc/hosts* which might be uninteresting. +zstyle -a ':prezto:module:completion:*:hosts' etc-host-ignores '_etc_host_ignores' + zstyle -e ':completion:*:hosts' hosts 'reply=( - ${=${=${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) 2>/dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } - ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2>/dev/null))"}%%\#*} - ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2>/dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}} + ${=${=${=${${(f)"$(cat {/etc/ssh/ssh_,~/.ssh/}known_hosts(|2)(N) 2> /dev/null)"}%%[#| ]*}//\]:[0-9]*/ }//,/ }//\[/ } + ${=${(f)"$(cat /etc/hosts(|)(N) <<(ypcat hosts 2> /dev/null))"}%%(\#${_etc_host_ignores:+|${(j:|:)~_etc_host_ignores}})*} + ${=${${${${(@M)${(f)"$(cat ~/.ssh/config 2> /dev/null)"}:#Host *}#Host }:#*\**}:#*\?*}} )' # Don't complete uninteresting users... @@ -140,9 +156,8 @@ if [[ -s "$HOME/.mutt/aliases" ]]; then fi # SSH/SCP/RSYNC -zstyle ':completion:*:(scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' +zstyle ':completion:*:(ssh|scp|rsync):*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' zstyle ':completion:*:(scp|rsync):*' group-order users files all-files hosts-domain hosts-host hosts-ipaddr -zstyle ':completion:*:ssh:*' tag-order 'hosts:-host:host hosts:-domain:domain hosts:-ipaddr:ip\ address *' zstyle ':completion:*:ssh:*' group-order users hosts-domain hosts-host users hosts-ipaddr zstyle ':completion:*:(ssh|scp|rsync):*:hosts-host' ignored-patterns '*(.|:)*' loopback ip6-loopback localhost ip6-localhost broadcasthost zstyle ':completion:*:(ssh|scp|rsync):*:hosts-domain' ignored-patterns '<->.<->.<->.<->' '^[-[:alnum:]]##(.[-[:alnum:]]##)##' '*@*' diff --git a/modules/directory/README.md b/modules/directory/README.md index 47c1bc201b..ce806eea12 100644 --- a/modules/directory/README.md +++ b/modules/directory/README.md @@ -12,7 +12,6 @@ Options - `PUSHD_SILENT` does not print the directory stack after `pushd` or `popd`. - `PUSHD_TO_HOME` pushes to the home directory when no argument is given. - `CDABLE_VARS` changes directory to a path stored in a variable. - - `AUTO_NAME_DIRS` auto adds variable-stored paths to `~` list. - `MULTIOS` writes to multiple descriptors. - `EXTENDED_GLOB` uses extended globbing syntax. - `CLOBBER` does not overwrite existing files with `>` and `>>`. Use `>!` and 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/dpkg/functions/deb-clone b/modules/dpkg/functions/deb-clone index a284c96fc0..a767bd323e 100644 --- a/modules/dpkg/functions/deb-clone +++ b/modules/dpkg/functions/deb-clone @@ -6,6 +6,8 @@ # Sorin Ionescu # +# function deb-clone { + local clone_script="${0}.sh" local package_list=$( perl \ @@ -23,3 +25,5 @@ rm "$clone_script" print '#!/bin/sh\n' > "$clone_script" print "aptitude install ${package_list}\n" >> "$clone_script" chmod +x "$clone_script" + +# } diff --git a/modules/dpkg/functions/deb-history b/modules/dpkg/functions/deb-history index 3737679031..a1369dea24 100644 --- a/modules/dpkg/functions/deb-history +++ b/modules/dpkg/functions/deb-history @@ -7,6 +7,8 @@ # Sorin Ionescu # +# function deb-history { + case "$1" in (install) zgrep --no-filename 'install ' $(ls -rt /var/log/dpkg*) @@ -34,3 +36,5 @@ Commands: EOF ;; esac + +# } diff --git a/modules/dpkg/functions/deb-kbuild b/modules/dpkg/functions/deb-kbuild index bdf7801e5b..a84a9b6de5 100644 --- a/modules/dpkg/functions/deb-kbuild +++ b/modules/dpkg/functions/deb-kbuild @@ -6,9 +6,13 @@ # Sorin Ionescu # +# function deb-kbuild { + make-kpkg clean MAKEFLAGS='' time fakeroot make-kpkg \ --append-to-version '-custom' \ --revision "$(date +"%Y%m%d")" \ kernel_image \ kernel_headers + +# } diff --git a/modules/editor/README.md b/modules/editor/README.md index 44bc829c80..7035635b2c 100644 --- a/modules/editor/README.md +++ b/modules/editor/README.md @@ -1,7 +1,17 @@ Editor ====== -Sets key bindings. +Sets editor specific key bindings options and variables. + +Options +------- + + - `BEEP` beep on error in line editor. + +Variables +--------- + + - `WORDCHARS` treat a given set of characters as part of a word. Settings -------- @@ -11,21 +21,27 @@ Settings To enable key bindings, add the following to *zpreztorc*, and replace 'bindings' with 'emacs' or 'vi'. - zstyle ':prezto:module:editor' key-bindings 'bindings' +```sh +zstyle ':prezto:module:editor' key-bindings 'bindings' +``` ### Dot Expansion To enable the auto conversion of .... to ../.., add the following to *zpreztorc*. - zstyle ':prezto:module:editor' dot-expansion 'yes' +```sh +zstyle ':prezto:module:editor' dot-expansion 'yes' +``` ### PS Context To enable the prompt context to be set, add the following to your *zpreztorc*. - zstyle ':prezto:module:editor' ps-context 'yes' +```sh +zstyle ':prezto:module:editor' ps-context 'yes' +``` Theming ------- @@ -33,31 +49,56 @@ Theming To indicate when the editor is in the primary keymap (emacs or viins), add the following to your `theme_prompt_setup` function. - zstyle ':prezto:module:editor:info:keymap:primary' format '>>>' +```sh +zstyle ':prezto:module:editor:info:keymap:primary' format '>>>' +``` To indicate when the editor is in the primary keymap (emacs or viins) insert mode, add the following to your `theme_prompt_setup` function. - zstyle ':prezto:module:editor:info:keymap:primary:insert' format 'I' +```sh +zstyle ':prezto:module:editor:info:keymap:primary:insert' format 'I' +``` To indicate when the editor is in the primary keymap (emacs or viins) overwrite mode, add the following to your `theme_prompt_setup` function. - zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format 'O' +```sh +zstyle ':prezto:module:editor:info:keymap:primary:overwrite' format 'O' +``` To indicate when the editor is in the alternate keymap (vicmd), add the following to your `theme_prompt_setup` function. - zstyle ':prezto:module:editor:info:keymap:alternate' format '<<<' +```sh +zstyle ':prezto:module:editor:info:keymap:alternate' format '<<<' +``` To indicate when the editor is completing, add the following to your `theme_prompt_setup` function. - zstyle ':prezto:module:editor:info:completing' format '...' +```sh +zstyle ':prezto:module:editor:info:completing' format '...' +``` Then add `$editor_info[context]`, where context is *keymap*, *insert*, or *overwrite*, to `$PROMPT` or `$RPROMPT`. +Convenience Functions +--------------------- + +### bindkey-all + +Provides a function `bindkey-all` which can be useful for checking how all of the +keys are bound. Normal `bindkey` command will only list the keys bound for one +keymap, which is not as useful if you want to grep through the output. The +keymap's names go to stderr so when you grep through bindkey-all's output you +will still see the headings and can tell which keymap each binding goes to. + +It will also pass through arguments so you can use bindkey-all to set bindings +for all keymaps at once. If provided arguments it will *not* print out the +names of each of the keymaps, and just run the command for each keymap. + Authors ------- @@ -65,4 +106,4 @@ Authors - [Sorin Ionescu](https://github.com/sorin-ionescu) -[1]: https://github.com/sorin-ionescu/oh-my-zsh/issues +[1]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/editor/init.zsh b/modules/editor/init.zsh index f1260021d7..28a2fb24a0 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 @@ -28,9 +27,11 @@ WORDCHARS='*?_-.[]~&;!#$%^(){}<>' zmodload zsh/terminfo typeset -gA key_info key_info=( - 'Control' '\C-' - 'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd' - 'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc' + 'Control' '\C-' + 'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd' + 'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc' + 'ControlPageUp' '\e[5;5~' + 'ControlPageDown' '\e[6;5~' 'Escape' '\e' 'Meta' '\M-' 'Backspace' "^?" @@ -78,32 +79,44 @@ zle -N edit-command-line # # Functions # - +# Runs bindkey but for all of the keymaps. Running it with no arguments will +# print out the mappings for all of the keymaps. +function bindkey-all { + local keymap='' + for keymap in $(bindkey -l); do + [[ "$#" -eq 0 ]] && printf "#### %s\n" "${keymap}" 1>&2 + bindkey -M "${keymap}" "$@" + done +} # Exposes information about the Zsh Line Editor via the $editor_info associative # array. function editor-info { - # Clean up previous $editor_info. - unset editor_info - typeset -gA editor_info - - if [[ "$KEYMAP" == 'vicmd' ]]; then - zstyle -s ':prezto:module:editor:info:keymap:alternate' format 'REPLY' - editor_info[keymap]="$REPLY" - else - zstyle -s ':prezto:module:editor:info:keymap:primary' format 'REPLY' - editor_info[keymap]="$REPLY" - - if [[ "$ZLE_STATE" == *overwrite* ]]; then - zstyle -s ':prezto:module:editor:info:keymap:primary:overwrite' format 'REPLY' - editor_info[overwrite]="$REPLY" + # Ensure that we're going to set the editor-info for prompts that + # are prezto managed and/or compatible. + if zstyle -t ':prezto:module:prompt' managed; then + # Clean up previous $editor_info. + unset editor_info + typeset -gA editor_info + + if [[ "$KEYMAP" == 'vicmd' ]]; then + zstyle -s ':prezto:module:editor:info:keymap:alternate' format 'REPLY' + editor_info[keymap]="$REPLY" else - zstyle -s ':prezto:module:editor:info:keymap:primary:insert' format 'REPLY' - editor_info[overwrite]="$REPLY" + zstyle -s ':prezto:module:editor:info:keymap:primary' format 'REPLY' + editor_info[keymap]="$REPLY" + + if [[ "$ZLE_STATE" == *overwrite* ]]; then + zstyle -s ':prezto:module:editor:info:keymap:primary:overwrite' format 'REPLY' + editor_info[overwrite]="$REPLY" + else + zstyle -s ':prezto:module:editor:info:keymap:primary:insert' format 'REPLY' + editor_info[overwrite]="$REPLY" + fi fi - fi - unset REPLY - zle zle-reset-prompt + unset REPLY + zle zle-reset-prompt + fi } zle -N editor-info @@ -201,6 +214,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 @@ -216,6 +237,35 @@ function prepend-sudo { } zle -N prepend-sudo +# Expand aliases +function glob-alias { + zle _expand_alias + zle expand-word + zle magic-space +} +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 @@ -223,9 +273,11 @@ bindkey -d # Emacs Key Bindings # -for key in "$key_info[Escape]"{B,b} "${(s: :)key_info[ControlLeft]}" +for key in "$key_info[Escape]"{B,b} "${(s: :)key_info[ControlLeft]}" \ + "${key_info[Escape]}${key_info[Left]}" bindkey -M emacs "$key" emacs-backward-word -for key in "$key_info[Escape]"{F,f} "${(s: :)key_info[ControlRight]}" +for key in "$key_info[Escape]"{F,f} "${(s: :)key_info[ControlRight]}" \ + "${key_info[Escape]}${key_info[Right]}" bindkey -M emacs "$key" emacs-forward-word # Kill to the beginning of the line. @@ -251,12 +303,18 @@ 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 # -# Edit command in an external editor. -bindkey -M vicmd "v" edit-command-line +# Edit command in an external editor emacs style (v is used for visual mode) +bindkey -M vicmd "$key_info[Control]X$key_info[Control]E" edit-command-line # Undo/Redo bindkey -M vicmd "u" undo @@ -270,14 +328,61 @@ 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 # -for keymap in 'emacs' 'viins'; do +# Unbound keys in vicmd and viins mode will cause really odd things to happen +# such as the casing of all the characters you have typed changing or other +# undefined things. In emacs mode they just insert a tilde, but bind these keys +# in the main keymap to a noop op so if there is no keybind in the users mode +# it will fall back and do nothing. +function _prezto-zle-noop { ; } +zle -N _prezto-zle-noop +local -a unbound_keys +unbound_keys=( + "${key_info[F1]}" + "${key_info[F2]}" + "${key_info[F3]}" + "${key_info[F4]}" + "${key_info[F5]}" + "${key_info[F6]}" + "${key_info[F7]}" + "${key_info[F8]}" + "${key_info[F9]}" + "${key_info[F10]}" + "${key_info[F11]}" + "${key_info[F12]}" + "${key_info[PageUp]}" + "${key_info[PageDown]}" + "${key_info[ControlPageUp]}" + "${key_info[ControlPageDown]}" +) +for keymap in $unbound_keys; do + bindkey -M viins "${keymap}" _prezto-zle-noop + bindkey -M vicmd "${keymap}" _prezto-zle-noop +done + +# 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[Insert]" overwrite-mode bindkey -M "$keymap" "$key_info[Delete]" delete-char bindkey -M "$keymap" "$key_info[Backspace]" backward-delete-char @@ -320,8 +425,14 @@ for keymap in 'emacs' 'viins'; do # Insert 'sudo ' at the beginning of the line. bindkey -M "$keymap" "$key_info[Control]X$key_info[Control]S" prepend-sudo + + # control-space expands all aliases, including global + bindkey -M "$keymap" "$key_info[Control] " glob-alias done +# Delete key deletes character in vimcmd cmd mode instead of weird default functionality +bindkey -M vicmd "$key_info[Delete]" delete-char + # Do not expand .... to ../.. during incremental search. if zstyle -t ':prezto:module:editor' dot-expansion; then bindkey -M isearch . self-insert 2> /dev/null diff --git a/modules/environment/README.md b/modules/environment/README.md index b86cbc54af..15ee95922c 100644 --- a/modules/environment/README.md +++ b/modules/environment/README.md @@ -5,21 +5,52 @@ Sets general shell options and defines environment variables. This module must be loaded first. -Environment Variables ---------------------- - Contributors ------------ This module **MUST NOT** rely on any command not built in Zsh. -Non-interactive environment variables should be defined in *zshenv*. +Non-interactive environment variables should be defined in [`zshenv`][1]. + +Options +------- + +### General + + - `COMBINING_CHARS` combine zero-length punctuation characters (accents) with + the base character. + - `INTERACTIVE_COMMENTS` enable comments in interactive shell. + - `RC_QUOTES` allow 'Henry''s Garage' instead of 'Henry'\''s Garage'. + - `MAIL_WARNING` don't print a warning message if a mail file has been accessed. + +### Jobs + + - `LONG_LIST_JOBS` list jobs in the long format by default. + - `AUTO_RESUME` attempt to resume existing job before creating a new process. + - `NOTIFY` report status of background jobs immediately. + - `BG_NICE` don't run all background jobs at a lower priority. + - `HUP` don't kill jobs on shell exit. + - `CHECK_JOBS` don't report on jobs when shell exit. + +Variables +--------- + +### Termcap + + - `LESS_TERMCAP_mb` begins blinking. + - `LESS_TERMCAP_md` begins bold. + - `LESS_TERMCAP_me` ends mode. + - `LESS_TERMCAP_se` ends standout-mode. + - `LESS_TERMCAP_so` begins standout-mode. + - `LESS_TERMCAP_ue` ends underline. + - `LESS_TERMCAP_us` begins underline. Authors ------- -*The authors of this module should be contacted via the [issue tracker][1].* +*The authors of this module should be contacted via the [issue tracker][2].* - [Sorin Ionescu](https://github.com/sorin-ionescu) -[1]: https://github.com/sorin-ionescu/prezto/issues +[1]: https://github.com/sorin-ionescu/prezto/blob/master/runcoms/zshenv +[2]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/environment/init.zsh b/modules/environment/init.zsh index 76655a6c7e..836a6cd443 100644 --- a/modules/environment/init.zsh +++ b/modules/environment/init.zsh @@ -9,18 +9,37 @@ # 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 && ${TERM} != "dumb" ]]; 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. + +# Allow mapping Ctrl+S and Ctrl+Q shortcuts +[[ -r ${TTY:-} && -w ${TTY:-} && $+commands[stty] == 1 ]] && stty -ixon <$TTY >$TTY # # Jobs diff --git a/modules/fasd/README.md b/modules/fasd/README.md index 8d3cca147e..cb3fc20b01 100644 --- a/modules/fasd/README.md +++ b/modules/fasd/README.md @@ -15,8 +15,8 @@ been disabled. Installation ------------ -Since fasd is not an external module it needs to be installed. -`brew install fasd` +`fasd` is bundled with prezto as a git submodule. Alternatively, you can manually install `fasd`. +If a manual install is found, it will be used instead of the bundled version. Aliases ------- diff --git a/modules/fasd/external b/modules/fasd/external new file mode 160000 index 0000000000..48220241e7 --- /dev/null +++ b/modules/fasd/external @@ -0,0 +1 @@ +Subproject commit 48220241e764fdf46b075cd7fe723468aaadde58 diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh index fc2142510c..f948789ec8 100644 --- a/modules/fasd/init.zsh +++ b/modules/fasd/init.zsh @@ -9,17 +9,20 @@ # Load dependencies. pmodload 'editor' -# Return if requirements are not found. +# If the command doesn't exist externally, we need to fall back to the bundled +# submodule. if (( ! $+commands[fasd] )); then - return 1 + source "${0:h}/external/fasd" || return 1 fi # # Initialization # -cache_file="${0:h}/cache.zsh" -if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then +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 # Set the base init arguments. init_args=(zsh-hook) @@ -28,6 +31,7 @@ if [[ "${commands[fasd]}" -nt "$cache_file" || ! -s "$cache_file" ]]; then 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/README.md b/modules/git/README.md index 81693f2378..e4425fab22 100644 --- a/modules/git/README.md +++ b/modules/git/README.md @@ -15,14 +15,18 @@ The format of the [git-log][8] output is configurable via the following style, where context is *brief*, *oneline*, and *medium*, which will be passed to the `--pretty=format:` switch. - zstyle ':prezto:module:git:log:context' format '' +```sh +zstyle ':prezto:module:git:log:context' format '' +``` ### Status Retrieving the status of a repository with submodules can take a long time. Submodules may be ignored when they are *dirty*, *untracked*, *all*, or *none*. - zstyle ':prezto:module:git:status:ignore' submodules 'all' +```sh +zstyle ':prezto:module:git:status:ignore' submodules 'all' +``` This setting affects all aliases and functions that call `git-status`. @@ -31,7 +35,9 @@ Aliases Aliases are enabled by default. You can disable them with: - zstyle ':prezto:module:git:alias' skip 'yes' +```sh +zstyle ':prezto:module:git:alias' skip 'yes' +``` ### Git @@ -41,15 +47,17 @@ Aliases are enabled by default. You can disable them with: - `gb` lists, creates, renames, and deletes branches. - `gbc` creates a new branch. - - `gbl` lists branches and their commits. - - `gbL` lists local and remote branches and their commits. + - `gbl` lists branches and their commits. (also `gbv`) + - `gbL` lists all local and remote branches and their commits. + - `gbr` renames a branch. (also `gbm`) + - `gbR` renames a branch even if the new branch name already exists. (also + `gbM`) - `gbs` lists branches and their commits with ancestry graphs. - `gbS` lists local and remote branches and their commits with ancestry graphs. - - `gbx` deletes a branch. - - `gbX` deletes a branch irrespective of its merged status. - - `gbm` renames a branch. - - `gbM` renames a branch even if the new branch name already exists. + - `gbV` lists branches with more verbose information about their commits. + - `gbx` deletes a branch. (also `gbd`) + - `gbX` deletes a branch irrespective of its merged status. (also `gbD`) ### Commit @@ -57,18 +65,26 @@ Aliases are enabled by default. You can disable them with: - `gc` records changes to the repository. - `gca` stages all modified and deleted files. - `gcm` records changes to the repository with the given message. + - `gcS` records changes to the repository. (Signed) + - `gcSa` stages all modified and deleted files. (Signed) + - `gcSm` records changes to the repository with the given message. (Signed) + - `gcam` stages all modified and deleted files, and records changes to the repository with the given message. - `gco` checks out a branch or paths to work tree. - `gcO` checks out hunks from the index or the tree interactively. - - `gcf` amends the tip of the current branch using the same log message as - *HEAD*. + - `gcf` amends the tip of the current branch using the same log message as *HEAD*. + - `gcSf` amends the tip of the current branch using the same log message as *HEAD*. (Signed) - `gcF` amends the tip of the current branch. + - `gcSF` amends the tip of the current branch. (Signed) - `gcp` applies changes introduced by existing commits. - `gcP` applies changes introduced by existing commits without committing. - `gcr` reverts existing commits by reverting patches and recording new commits. - `gcR` removes the *HEAD* commit. - `gcs` displays various types of objects. + - `gcsS` displays commits with GPG signature. - `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 @@ -93,7 +109,9 @@ Aliases are enabled by default. You can disable them with: ### Fetch - `gf` downloads objects and references from another repository. + - `gfa` downloads objects and references from all remote repositories. - `gfc` clones a repository into a new directory. + - `gfcr` clones a repository into a new directory including all submodules. - `gfm` fetches from and merges with another repository or local branch. - `gfr` fetches from and rebases on another repository or local branch. @@ -187,6 +205,8 @@ Aliases are enabled by default. You can disable them with: - `giu` adds file contents to the index (updates only known files). - `gid` displays changes between the index and a named commit (diff). - `giD` displays changes between the index and a named commit (word diff). + - `gii` temporarily ignore differences in a given file. + - `giI` unignore differences in a given file. - `gir` resets the current HEAD to the specified state. - `giR` resets the current index interactively. - `gix` removes files/directories from the index (recursively). @@ -201,6 +221,7 @@ Aliases are enabled by default. You can disable them with: - `glg` displays the graph log. - `glb` displays the brief commit log. - `glc` displays the commit count for each contributor in descending order. + - `glS` displays the log and checks the validity of signed commits. ### Merge @@ -214,7 +235,8 @@ Aliases are enabled by default. You can disable them with: ### Push - `gp` updates remote refs along with associated objects. - - `gpf` forcefully updates remote refs along with associated objects. + - `gpf` forcefully updates remote refs along with associated objects using the safer `--force-with-lease` option. + - `gpF` forcefully updates remote refs along with associated objects using the riskier `--force` option. - `gpa` updates remote branches along with associated objects. - `gpA` updates remote branches and tags along with associated objects. - `gpt` updates remote tags along with associated objects. @@ -271,6 +293,13 @@ Aliases are enabled by default. You can disable them with: - `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. + - `gts` creates a signed tag. + - `gtv` validate a signed tag. + ### Working directory - `gws` displays working-tree status in the short format. @@ -290,9 +319,10 @@ Aliases are enabled by default. You can disable them with: 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`. @@ -307,7 +337,7 @@ Functions - `git-commit-lost` lists lost commits. - `git-dir` displays the path to the Git directory. - `git-hub-browse` opens the [GitHub][3] repository in the default browser. - - `git-hub-shorten-url` shortens GitHub URLs. + - `git-hub-shorten-url` shortens [GitHub URLs][10]. - `git-info` exposes repository information via the `$git_info` associative array. - `git-root` displays the path to the working tree root. @@ -324,7 +354,9 @@ To display information about the current repository in a prompt, define the following styles in the `prompt_name_setup` function, where the syntax for setting a style is as follows. - zstyle ':prezto:module:git:info:context:subcontext' format 'string' +```sh +zstyle ':prezto:module:git:info:context:subcontext' format 'string' +``` ### Main Contexts @@ -351,7 +383,9 @@ setting a style is as follows. The following contexts must be enabled with the following zstyle: - zstyle ':prezto:module:git:info' verbose 'yes' +```sh +zstyle ':prezto:module:git:info' verbose 'yes' +``` ### Verbose Contexts @@ -378,18 +412,24 @@ The following contexts must be enabled with the following zstyle: | rebase | value | Rebasing | rebase-interactive | value | Rebasing interactively | rebase-merge | value | Rebasing merge +| revert | value | Reverting +| revert-sequence | value | Reverting sequence First, format the repository state attributes. For example, to format the branch and remote names, define the following styles. - zstyle ':prezto:module:git:info:branch' format 'branch:%b' - zstyle ':prezto:module:git:info:remote' format 'remote:%R' +```sh +zstyle ':prezto:module:git:info:branch' format 'branch:%b' +zstyle ':prezto:module:git:info:remote' format 'remote:%R' +``` Second, format how the above attributes are displayed in prompts. - zstyle ':prezto:module:git:info:keys' format \ - 'prompt' ' git(%b)' \ - 'rprompt' '[%R]' +```sh +zstyle ':prezto:module:git:info:keys' format \ + 'prompt' ' git(%b)' \ + 'rprompt' '[%R]' +``` Last, add `$git_info[prompt]` to `$PROMPT` and `$git_info[rprompt]` to `$RPROMPT` respectively and call `git-info` in the `prompt_name_preexec` hook @@ -407,8 +447,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 06e47b1665..95b2a0d475 100644 --- a/modules/git/alias.zsh +++ b/modules/git/alias.zsh @@ -32,33 +32,49 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then # Branch (b) alias gb='git branch' + alias gba='git branch --all --verbose' alias gbc='git checkout -b' - alias gbl='git branch -v' - alias gbL='git branch -av' - alias gbx='git branch -d' - alias gbX='git branch -D' - alias gbm='git branch -m' - alias gbM='git branch -M' + alias gbd='git branch --delete' + alias gbD='git branch --delete --force' + alias gbl='git branch --verbose' + alias gbL='git branch --all --verbose' + alias gbm='git branch --move' + alias gbM='git branch --move --force' + alias gbr='git branch --move' + alias gbR='git branch --move --force' alias gbs='git show-branch' - alias gbS='git show-branch -a' + alias gbS='git show-branch --all' + alias gbv='git branch --verbose' + alias gbV='git branch --verbose --verbose' + alias gbx='git branch --delete' + alias gbX='git branch --delete --force' # Commit (c) alias gc='git commit --verbose' alias gca='git commit --verbose --all' alias gcm='git commit --message' + alias gcS='git commit -S --verbose' + alias gcSa='git commit -S --verbose --all' + alias gcSm='git commit -S --message' + alias gcam='git commit --all --message' alias gco='git checkout' alias gcO='git checkout --patch' alias gcf='git commit --amend --reuse-message HEAD' + alias gcSf='git commit -S --amend --reuse-message HEAD' alias gcF='git commit --verbose --amend' + alias gcSF='git commit -S --verbose --amend' alias gcp='git cherry-pick --ff' alias gcP='git cherry-pick --no-commit' alias gcr='git revert' alias gcR='git reset "HEAD^"' alias gcs='git show' + alias gcsS='git show --pretty=short --show-signature' alias gcl='git-commit-lost' + alias gcy='git cherry -v --abbrev' + alias gcY='git cherry -v' # Conflict (C) - alias gCl='git status | sed -n "s/^.*both [a-z]*ed: *//p"' + alias gCl='git --no-pager diff --name-only --diff-filter=U' alias gCa='git add $(gCl)' alias gCe='git mergetool $(gCl)' alias gCo='git checkout --ours --' @@ -77,9 +93,13 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then # Fetch (f) alias gf='git fetch' + alias gfa='git fetch --all' 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' @@ -158,6 +178,8 @@ if ! zstyle -t ':prezto:module:git:alias' skip 'yes'; then alias giu='git add --update' alias gid='git diff --no-ext-diff --cached' alias giD='git diff --no-ext-diff --cached --word-diff' + alias gii='git update-index --assume-unchanged' + alias giI='git update-index --no-assume-unchanged' alias gir='git reset' alias giR='git reset --patch' alias gix='git rm -r --cached' @@ -168,9 +190,10 @@ 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_oneline_format}"' + alias glg='git log --topo-order --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 --show-signature' # Merge (m) alias gm='git merge' @@ -233,6 +256,12 @@ 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' + alias gts='git tag -s' + alias gtv='git verify-tag' + # 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 54d223f275..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 dcc7bb3880..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 '1:url:' && 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 944ffe25cd..3cf2e191d1 100644 --- a/modules/git/functions/git-branch-current +++ b/modules/git/functions/git-branch-current @@ -5,12 +5,14 @@ # Sorin Ionescu # -if ! git rev-parse 2> /dev/null; then +# function git-branch-current { + +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/}" @@ -18,3 +20,5 @@ if [[ -n "$ref" ]]; then else return 1 fi + +# } diff --git a/modules/git/functions/git-commit-lost b/modules/git/functions/git-commit-lost index 75ab571655..1f086d3b95 100644 --- a/modules/git/functions/git-commit-lost +++ b/modules/git/functions/git-commit-lost @@ -5,16 +5,20 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-commit-lost { + +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 \ --pretty=format:${_git_log_oneline_format} + +# } diff --git a/modules/git/functions/git-dir b/modules/git/functions/git-dir index 7e16ca8140..aacaaa8866 100644 --- a/modules/git/functions/git-dir +++ b/modules/git/functions/git-dir @@ -5,7 +5,9 @@ # Sorin Ionescu # -local git_dir="${$(git rev-parse --git-dir):A}" +# function git-dir { + +local git_dir="${$(command git rev-parse --git-dir):A}" if [[ -n "$git_dir" ]]; then print "$git_dir" @@ -14,3 +16,5 @@ else print "$0: not a repository: $PWD" >&2 return 1 fi + +# } diff --git a/modules/git/functions/git-hub-browse b/modules/git/functions/git-hub-browse index 549a544ab7..cb3fc60de8 100644 --- a/modules/git/functions/git-hub-browse +++ b/modules/git/functions/git-hub-browse @@ -5,7 +5,9 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-hub-browse { + +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 @@ -13,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 @@ -21,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 @@ -37,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" @@ -56,3 +58,5 @@ else print "$0: not a Git repository or remote not set" >&2 return 1 fi + +# } diff --git a/modules/git/functions/git-hub-shorten-url b/modules/git/functions/git-hub-shorten-url index d37b04eb85..470c093f1c 100644 --- a/modules/git/functions/git-hub-shorten-url +++ b/modules/git/functions/git-hub-shorten-url @@ -5,18 +5,24 @@ # Sorin Ionescu # -local url="$1" +# function git-hub-shorten-url { + +local url="$1" code="$2" if [[ "$url" == '-' ]]; then read url <&0 fi -if [[ -z "$url" ]]; then - print "usage: $0 [ url | - ]" >&2 +if [[ -z "$url" || ! "$url" =~ ^https?:\/\/.*github.com\/ ]]; then + print "usage: $0 [ url | - ] [code] ; url must be a github.com URL" >&2 + return 1 fi if (( $+commands[curl] )); then - curl -s -i 'http://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 8aaa4c32d6..20c284b08c 100644 --- a/modules/git/functions/git-info +++ b/modules/git/functions/git-info @@ -5,7 +5,7 @@ # Sorin Ionescu # -# Gets the Git special action (am, bisect, cherry, merge, rebase). +# Gets the Git special action (am, bisect, cherry, merge, rebase, revert). # Borrowed from vcs_info and edited. function _git-action { local action_dir @@ -18,6 +18,8 @@ function _git-action { local rebase_formatted local rebase_interactive_formatted local rebase_merge_formatted + local revert_formatted + local revert_sequence_formatted for action_dir in \ "${git_dir}/rebase-apply" \ @@ -80,6 +82,18 @@ function _git-action { return 0 fi + if [[ -f "${git_dir}/REVERT_HEAD" ]]; then + if [[ -d "${git_dir}/sequencer" ]] ; then + zstyle -s ':prezto:module:git:info:action:revert-sequence' format 'revert_sequence_formatted' || revert_sequence_formatted='revert-sequence' + print "$revert_sequence_formatted" + else + zstyle -s ':prezto:module:git:info:action:revert' format 'revert_formatted' || revert_formatted='revert' + print "$revert_formatted" + fi + + return 0 + fi + if [[ -f "${git_dir}/BISECT_LOG" ]]; then zstyle -s ':prezto:module:git:info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' print "$bisect_formatted" @@ -164,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 @@ -180,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 @@ -190,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 @@ -198,10 +212,17 @@ 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}')" - if [[ -n "$stashed" ]]; then - zformat -f stashed_formatted "$stashed_format" "S:$stashed" + if [[ -n "$stashed_format" ]]; then + commondir="" + if [[ -f "$(git-dir)/commondir" ]]; then + commondir="$(<$(git-dir)/commondir)" + [[ "$commondir" =~ ^/ ]] || commondir="$(git-dir)/$commondir" + fi + if [[ -f "$(git-dir)/refs/stash" || ( -n "$commondir" && -f "$commondir/refs/stash" ) ]]; then + 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 fi fi @@ -215,7 +236,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' @@ -226,7 +247,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 @@ -236,7 +257,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" @@ -247,14 +268,14 @@ 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)" # 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 @@ -262,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 @@ -276,7 +297,7 @@ function git-info { if [[ -n "$indexed_format" ]]; then (( indexed+=$( - git diff-index \ + command git diff-index \ --no-ext-diff \ --name-only \ --cached \ @@ -296,7 +317,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} \ @@ -314,7 +335,7 @@ function git-info { if [[ -n "$untracked_format" ]]; then (( untracked+=$( - git ls-files \ + command git ls-files \ --other \ --exclude-standard \ 2> /dev/null \ @@ -329,7 +350,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 712e4fe6b4..643f346b36 100644 --- a/modules/git/functions/git-root +++ b/modules/git/functions/git-root @@ -5,7 +5,9 @@ # Sorin Ionescu # -local root="$(git rev-parse --show-toplevel 2> /dev/null)" +# function git-root { + +local root="$(command git rev-parse --show-toplevel 2> /dev/null)" if [[ -n "$root" ]]; then print "$root" @@ -14,3 +16,5 @@ else print "$0: not a repository work tree: $PWD" >&2 return 1 fi + +# } diff --git a/modules/git/functions/git-stash-clear-interactive b/modules/git/functions/git-stash-clear-interactive index e45165c499..cc665a1829 100644 --- a/modules/git/functions/git-stash-clear-interactive +++ b/modules/git/functions/git-stash-clear-interactive @@ -5,7 +5,9 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-stash-clear-interactive { + +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 @@ -13,10 +15,12 @@ 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 51580703f2..d9e759e872 100644 --- a/modules/git/functions/git-stash-dropped +++ b/modules/git/functions/git-stash-dropped @@ -5,18 +5,22 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-stash-dropped { + +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 [^:]+:}" \ --merges \ --no-walk \ --stdin + +# } diff --git a/modules/git/functions/git-stash-recover b/modules/git/functions/git-stash-recover index 6add26fdd9..6cb5416e6c 100644 --- a/modules/git/functions/git-stash-recover +++ b/modules/git/functions/git-stash-recover @@ -5,7 +5,9 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-stash-recover { + +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 @@ -13,6 +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 34c5e44aba..746f46e512 100644 --- a/modules/git/functions/git-submodule-move +++ b/modules/git/functions/git-submodule-move @@ -5,7 +5,9 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-submodule-move { + +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 @@ -17,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 @@ -27,6 +29,8 @@ 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 852b9cdbc8..c8c11aa8c3 100644 --- a/modules/git/functions/git-submodule-remove +++ b/modules/git/functions/git-submodule-remove @@ -5,23 +5,27 @@ # Sorin Ionescu # -if ! is-true "$(git rev-parse --is-inside-work-tree 2> /dev/null)"; then +# function git-submodule-remove { + +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}" return 0 + +# } diff --git a/modules/gnu-utility/README.md b/modules/gnu-utility/README.md index 34bc6635aa..7e62a176c2 100644 --- a/modules/gnu-utility/README.md +++ b/modules/gnu-utility/README.md @@ -20,7 +20,9 @@ Settings To use a different prefix, add the following to *zpreztorc*, and replace 'g' with the desired prefix: - zstyle ':prezto:module:gnu-utility' prefix 'g' +```sh +zstyle ':prezto:module:gnu-utility' prefix 'g' +``` Authors ------- diff --git a/modules/gnu-utility/init.zsh b/modules/gnu-utility/init.zsh index 6556032407..4675a3ca56 100644 --- a/modules/gnu-utility/init.zsh +++ b/modules/gnu-utility/init.zsh @@ -15,16 +15,16 @@ fi _gnu_utility_cmds=( # Coreutils - '[' 'base64' 'basename' 'cat' 'chcon' 'chgrp' 'chmod' 'chown' + '[' 'b2sum' 'base32' 'base64' 'basename' 'cat' 'chcon' 'chgrp' 'chmod' 'chown' 'chroot' 'cksum' 'comm' 'cp' 'csplit' 'cut' 'date' 'dd' 'df' 'dir' 'dircolors' 'dirname' 'du' 'echo' 'env' 'expand' 'expr' 'factor' 'false' 'fmt' 'fold' 'groups' 'head' 'hostid' 'id' - 'install' 'join' 'kill' 'link' 'ln' 'logname' 'ls' 'md5sum' - 'mkdir' 'mkfifo' 'mknod' 'mktemp' 'mv' 'nice' 'nl' 'nohup' 'nproc' - 'od' 'paste' 'pathchk' 'pinee' 'pr' 'printenv' 'printf' 'ptx' + 'install' 'join' 'kill' 'link' 'ln' 'logname' 'ls' 'md5sum' 'mkdir' + 'mkfifo' 'mknod' 'mktemp' 'mv' 'nice' 'nl' 'nohup' 'nproc' + 'numfmt' 'od' 'paste' 'pathchk' 'pinky' 'pr' 'printenv' 'printf' 'ptx' 'pwd' 'readlink' 'realpath' 'rm' 'rmdir' 'runcon' 'seq' 'sha1sum' 'sha224sum' 'sha256sum' 'sha384sum' 'sha512sum' 'shred' 'shuf' - 'sleep' 'sort' 'split' 'stat' 'stty' 'sum' 'sync' 'tac' 'tail' + 'sleep' 'sort' 'split' 'stat' 'stdbuf' 'stty' 'sum' 'sync' 'tac' 'tail' 'tee' 'test' 'timeout' 'touch' 'tr' 'true' 'truncate' 'tsort' 'tty' 'uname' 'unexpand' 'uniq' 'unlink' 'uptime' 'users' 'vdir' 'wc' 'who' 'whoami' 'yes' @@ -42,13 +42,13 @@ _gnu_utility_cmds=( 'libtool' 'libtoolize' # Miscellaneous - 'getopt' 'grep' 'indent' 'sed' 'tar' 'time' 'units' 'which' + 'getopt' 'grep' 'indent' 'make' 'sed' 'tar' 'time' 'units' 'which' ) # 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/README.md b/modules/gpg/README.md index 80e91d0ff6..be3c1a925c 100644 --- a/modules/gpg/README.md +++ b/modules/gpg/README.md @@ -9,7 +9,9 @@ To enable OpenSSH Agent protocol emulation, and make `gpg-agent` a drop-in replacement for `ssh-agent`, add the following line to *~/.gnupg/gpg-agent.conf*: - enable-ssh-support +```conf +enable-ssh-support +``` When OpenSSH Agent protocol emulation is enabled, this module will load the SSH module for additional processing. diff --git a/modules/gpg/init.zsh b/modules/gpg/init.zsh index b969c7a553..a3b37ba3bc 100644 --- a/modules/gpg/init.zsh +++ b/modules/gpg/init.zsh @@ -12,24 +12,25 @@ 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" +_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 # 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 + mkdir -p "$_gpg_agent_env:h" eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")" fi fi # Inform gpg-agent of the current TTY for user prompts. -export GPG_TTY="$(tty)" +export GPG_TTY=$TTY # Integrate with the SSH module. -if grep 'enable-ssh-support' "$_gpg_agent_conf" &> /dev/null; then +if grep '^enable-ssh-support' "$_gpg_agent_conf" &> /dev/null; then # Load required functions. autoload -Uz add-zsh-hook 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..6e83f89a18 100644 --- a/modules/helper/init.zsh +++ b/modules/helper/init.zsh @@ -29,3 +29,23 @@ 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* ]] +} diff --git a/modules/history-substring-search/README.md b/modules/history-substring-search/README.md index 79714fa921..050a5c2e80 100644 --- a/modules/history-substring-search/README.md +++ b/modules/history-substring-search/README.md @@ -6,8 +6,8 @@ the [Fish shell][2]'s history search feature, where the user can type in any part of a previously entered command and press up and down to cycle through matching commands. -If this module is used in conjuncture with the *syntax-highlighting* module, it -must be loaded **after** it. +If this module is used in conjunction with the *syntax-highlighting* module, +this module must be loaded **after** the *syntax-highlighting* module. Contributors ------------ @@ -24,7 +24,9 @@ Settings To enable case-sensitivity for this module only, add the following line to *zpreztorc*: - zstyle ':prezto:module:history-substring-search' case-sensitive 'yes' +```sh +zstyle ':prezto:module:history-substring-search' case-sensitive 'yes' +``` ### Highlighting @@ -34,19 +36,27 @@ positive results. To enable highlighting for this module only, add the following line to *zpreztorc*: - zstyle ':prezto:module:history-substring-search' color 'yes' +```sh +zstyle ':prezto:module:history-substring-search' color 'yes' +``` To set the query found color, add the following line to *zpreztorc*: - zstyle ':prezto:module:history-substring-search:color' found '' +```sh +zstyle ':prezto:module:history-substring-search:color' found '' +``` To set the query not found color, add the following line to *zpreztorc*: - zstyle ':prezto:module:history-substring-search:color' not-found '' +```sh +zstyle ':prezto:module:history-substring-search:color' not-found '' +``` To set the search globbing flags, add the following line to *zpreztorc*: - zstyle ':prezto:module:history-substring-search' globbing-flags '' +```sh +zstyle ':prezto:module:history-substring-search' globbing-flags '' +``` Authors ------- 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/history/README.md b/modules/history/README.md index 3dc9a26423..1a03bd95e1 100644 --- a/modules/history/README.md +++ b/modules/history/README.md @@ -3,20 +3,18 @@ History Sets [history][1] options and defines history aliases. -Variables ---------- - - - `HISTFILE` stores the path to the history file. - - `HISTSIZE` stores the maximum number of events to save in the internal history. - - `SAVEHIST` stores the maximum number of events to save in the history file. +**Note:** If you are migrating from oh-my-zsh and want to keep your history, you +will either need to set HISTFILE manually to `$HOME/.zsh_history` or rename +`~/.zsh_history` to ~/.zhistory`. Options ------- - `BANG_HIST` treats the **!** character specially during expansion. - `EXTENDED_HISTORY` writes the history file in the *:start:elapsed;command* format. - - `INC_APPEND_HISTORY` writes to the history file immediately, not when the shell exits. - - `SHARE_HISTORY` shares history between all sessions. + - `SHARE_HISTORY` shares history between all sessions. Note that + `SHARE_HISTORY`, `INC_APPEND_HISTORY`, and `INC_APPEND_HISTORY_TIME` are + mutually exclusive. - `HIST_EXPIRE_DUPS_FIRST` expires a duplicate event first when trimming history. - `HIST_IGNORE_DUPS` does not record an event that was just recorded again. - `HIST_IGNORE_ALL_DUPS` deletes an old recorded event if a new event is a duplicate. @@ -26,6 +24,13 @@ Options - `HIST_VERIFY` does not execute immediately upon history expansion. - `HIST_BEEP` beeps when accessing non-existent history. +Variables +--------- + + - `HISTFILE` stores the path to the history file. + - `HISTSIZE` stores the maximum number of events to save in the internal history. + - `SAVEHIST` stores the maximum number of events to save in the history file. + Aliases ------- diff --git a/modules/history/init.zsh b/modules/history/init.zsh index 31db4c5b3a..d1d3373a98 100644 --- a/modules/history/init.zsh +++ b/modules/history/init.zsh @@ -6,21 +6,12 @@ # Sorin Ionescu # -# -# Variables -# - -HISTFILE="${ZDOTDIR:-$HOME}/.zhistory" # The path to the history file. -HISTSIZE=10000 # The maximum number of events to save in the internal history. -SAVEHIST=10000 # The maximum number of events to save in the history file. - # # Options # setopt BANG_HIST # Treat the '!' character specially during expansion. setopt EXTENDED_HISTORY # Write the history file in the ':start:elapsed;command' format. -setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. setopt SHARE_HISTORY # Share history between all sessions. setopt HIST_EXPIRE_DUPS_FIRST # Expire a duplicate event first when trimming history. setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again. @@ -31,6 +22,14 @@ setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history setopt HIST_VERIFY # Do not execute immediately upon history expansion. setopt HIST_BEEP # Beep when accessing non-existent history. +# +# Variables +# + +HISTFILE="${HISTFILE:-${ZDOTDIR:-$HOME}/.zhistory}" # The path to the history file. +HISTSIZE=10000 # The maximum number of events to save in the internal history. +SAVEHIST=10000 # The maximum number of events to save in the history file. + # # Aliases # diff --git a/modules/homebrew/README.md b/modules/homebrew/README.md index 84b43865db..1d29871e51 100644 --- a/modules/homebrew/README.md +++ b/modules/homebrew/README.md @@ -1,7 +1,16 @@ Homebrew ======== -Defines Homebrew aliases. +Defines Homebrew specific environment variables and aliases. + +Variables +--------- + +Execute the following to list the environment variables loaded in the shell: + +```sh +brew shellenv +``` Aliases ------- @@ -9,21 +18,20 @@ Aliases ### Homebrew - `brewc` cleans outdated brews and their cached archives. - - `brewC` cleans outdated brews, including keg-only, and their cached archives. - `brewi` installs a formula. + - `brewL` lists installed formulae that are not dependencies of another installed formula. - `brewl` lists installed formulae. + - `brewo` lists brews which have an update available. - `brews` searches for a formula. - - `brewu` updates Homebrew and formulae. + - `brewu` updates and upgrades Homebrew packages and formulae. - `brewx` uninstalls a formula. ### Homebrew Cask - `cask` is aliased to `brew cask`. - - `caskc` cleans up old cached downloads. - - `caskC` cleans up all cached downloads. - `caski` installs a cask. - `caskl` lists installed casks. - - `casks` searches for a cask. + - `casko` lists casks which have an update available. - `caskx` uninstalls a cask. Authors diff --git a/modules/homebrew/init.zsh b/modules/homebrew/init.zsh index 1196fa5740..bfa667c0bc 100644 --- a/modules/homebrew/init.zsh +++ b/modules/homebrew/init.zsh @@ -5,29 +5,55 @@ # 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 +# +# Variables +# + +# Load standard Homebrew shellenv into the shell session. +# Load 'HOMEBREW_' prefixed variables only. Avoid loading 'PATH' related +# variables as they are already handled in standard zsh configuration. +if (( $+commands[brew] )); then + eval "${(@M)${(f)"$(brew shellenv 2> /dev/null)"}:#export HOMEBREW*}" +fi + # # Aliases # # Homebrew alias brewc='brew cleanup' -alias brewC='brew cleanup --force' alias brewi='brew install' +alias brewL='brew leaves' alias brewl='brew list' +alias brewo='brew outdated' alias brews='brew search' -alias brewu='brew update && brew upgrade' -alias brewx='brew remove' +alias brewu='brew upgrade' +alias brewx='brew uninstall' # Homebrew Cask alias cask='brew cask' -alias caskc='brew cask cleanup --outdated' -alias caskC='brew cask cleanup' +alias caskc='hb_deprecated brew cask cleanup' +alias caskC='hb_deprecated brew cask cleanup' alias caski='brew cask install' alias caskl='brew cask list' -alias casks='brew cask search' +alias casko='brew cask outdated' +alias casks='hb_deprecated brew cask search' alias caskx='brew cask uninstall' + +function hb_deprecated { + local cmd="${@[3]}" + local cmd_args="${@:4}" + + printf "'brew cask %s' has been deprecated, " "${cmd}" + printf "using 'brew %s' instead\n" "${cmd}" + + command brew "${cmd}" "${=cmd_args}" +} 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/README.md b/modules/node/README.md index 66e9784d99..af447c1421 100644 --- a/modules/node/README.md +++ b/modules/node/README.md @@ -10,6 +10,9 @@ nvm [nvm][5] allows for managing multiple, isolated Node.js installations in the home directory. +This will be loaded automatically if nvm is installed in `$NVM_DIR`, +`~/.nvm`, or nvm is installed with homebrew. + nodenv ------ @@ -17,6 +20,9 @@ nodenv Node versions. It's simple and predictable, Just Works, and is rock solid in production. nodenv is forked from the popular [rbenv][7]. +This will be loaded automatically if nodenv is installed in `$NODENV_ROOT`, +`~/.nodenv`, or `nodenv` is on the path. + Functions --------- @@ -31,8 +37,10 @@ Theming To display the version number of the current Node.js version, define the following style inside the `prompt_name_setup` function. - # %v - Node.js version. - zstyle ':prezto:module:node:info:version' format 'version:%v' +```sh +# %v - Node.js version. +zstyle ':prezto:module:node:info:version' format 'version:%v' +``` Then add `$node_info[version]` to either `$PROMPT` or `$RPROMPT` and call `node-info` in `prompt_name_preexec` hook function. diff --git a/modules/node/functions/node-doc b/modules/node/functions/node-doc index 24f5641422..b1a048bd24 100644 --- a/modules/node/functions/node-doc +++ b/modules/node/functions/node-doc @@ -5,6 +5,8 @@ # Sorin Ionescu # +# function node-doc { + if [[ -z "$BROWSER" ]]; then print "$0: no web browser defined" >&2 return 1 @@ -12,3 +14,5 @@ fi # TODO: Make the sections easier to use. "$BROWSER" "http://nodejs.org/docs/$(node --version | sed 's/-.*//')/api/all.html#${1}" + +# } diff --git a/modules/node/functions/node-info b/modules/node/functions/node-info index e4cd52d02c..c43759b760 100644 --- a/modules/node/functions/node-info +++ b/modules/node/functions/node-info @@ -6,6 +6,8 @@ # Zeh Rizzatti # +# function node-info { + local version local version_format local version_formatted @@ -17,10 +19,14 @@ if (( $+functions[nvm_version] )); then version="${$(nvm_version)#v}" elif (( $+commands[nodenv] )); then version="${${$(nodenv version)#v}[(w)0]}" +elif (( $+commands[node] )) ; then + version="${$(node -v)#v}" fi -if [[ "$version" != (none|) ]]; then +if [[ "$version" != (none|system) ]]; then zstyle -s ':prezto:module:node:info:version' format 'version_format' zformat -f version_formatted "$version_format" "v:$version" node_info[version]="$version_formatted" fi + +# } diff --git a/modules/node/init.zsh b/modules/node/init.zsh index 46ab4411aa..6fb68f307d 100644 --- a/modules/node/init.zsh +++ b/modules/node/init.zsh @@ -7,16 +7,18 @@ # # Load manually installed NVM into the shell session. -if [[ -s "$HOME/.nvm/nvm.sh" ]]; then - source "$HOME/.nvm/nvm.sh" +if [[ -s "${NVM_DIR:=$HOME/.nvm}/nvm.sh" ]]; then + source "${NVM_DIR}/nvm.sh" # Load package manager installed NVM into the shell session. -elif (( $+commands[brew] )) && [[ -d "$(brew --prefix nvm 2>/dev/null)" ]]; then - source $(brew --prefix nvm)/nvm.sh +elif (( $+commands[brew] )) && \ + [[ -d "${nvm_prefix::="$(brew --prefix 2> /dev/null)"/opt/nvm}" ]]; then + source "$(brew --prefix nvm)/nvm.sh" + unset nvm_prefix # Load manually installed nodenv into the shell session. -elif [[ -s "$HOME/.nodenv/bin/nodenv" ]]; then - path=("$HOME/.nodenv/bin $path") +elif [[ -s "${NODENV_ROOT:=$HOME/.nodenv}/bin/nodenv" ]]; then + path=("${NODENV_ROOT}/bin" $path) eval "$(nodenv init - --no-rehash zsh)" # Load package manager installed nodenv into the shell session. @@ -28,16 +30,29 @@ elif (( ! $+commands[node] )); then return 1 fi -# Load NPM completion. -if (( $+commands[npm] )); then - cache_file="${0:h}/cache.zsh" +# Load NPM and known helper completions. +typeset -A compl_commands=( + npm 'npm completion' + grunt 'grunt --completion=zsh' + gulp 'gulp --completion=zsh' +) - if [[ "$commands[npm]" -nt "$cache_file" || ! -s "$cache_file" ]]; then - # npm is slow; cache its output. - npm completion >! "$cache_file" 2> /dev/null - fi +for compl_command in "${(k)compl_commands[@]}"; do + if (( $+commands[$compl_command] )); then + cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/prezto/$compl_command-cache.zsh" - source "$cache_file" + # 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 - unset cache_file -fi + source "$cache_file" + + unset cache_file + fi +done + +unset compl_command{s,} diff --git a/modules/osx/README.md b/modules/osx/README.md index d8eff0ff36..1f93a2c332 100644 --- a/modules/osx/README.md +++ b/modules/osx/README.md @@ -1,7 +1,20 @@ OSX === -Defines [Mac OS X][1] aliases and functions. +Defines [macOS][1] aliases and functions. + +Settings +-------- + +### Dash Keyword + +To change the keyword used by `mand` to open man pages in [_Dash.app_][2] from +its default value of 'manpages', add the following line in *zpreztorc* and +replace the **keyword** with the one configured in [_Dash.app_][2]. + +```sh +zstyle ':prezto:module:osx:man' dash-keyword 'keyword' +``` Aliases ------- @@ -21,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/mand b/modules/osx/functions/mand index 7a9653a1fa..2902c76be7 100644 --- a/modules/osx/functions/mand +++ b/modules/osx/functions/mand @@ -7,7 +7,8 @@ function mand { if (( $# > 0 )); then - open "dash://manpages:$1" 2>/dev/null + zstyle -s ':prezto:module:osx:man' dash-keyword 'dashkw' || dashkw='manpages' + open "dash://$dashkw:$1" 2> /dev/null if (( $? != 0 )); then print "$0: Dash is not installed" >&2 break @@ -15,6 +16,8 @@ function mand { else print 'What manual page do you want?' >&2 fi + + unset dashkw } mand "$@" diff --git a/modules/osx/functions/osx-ls-download-history b/modules/osx/functions/osx-ls-download-history index 5727c1b33e..8b6eaab260 100644 --- a/modules/osx/functions/osx-ls-download-history +++ b/modules/osx/functions/osx-ls-download-history @@ -1,13 +1,17 @@ # -# Displays the Mac OS X download history. +# Displays the macOS download history. # # Authors: # Sorin Ionescu # +# function osx-ls-download-history { + local db for db in ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV*; do if grep -q 'LSQuarantineEvent' < <(sqlite3 "$db" .tables); then sqlite3 "$db" 'SELECT LSQuarantineDataURLString FROM LSQuarantineEvent' fi done + +# } diff --git a/modules/osx/functions/osx-rm-dir-metadata b/modules/osx/functions/osx-rm-dir-metadata index 0a91cedb66..f15f4ed619 100644 --- a/modules/osx/functions/osx-rm-dir-metadata +++ b/modules/osx/functions/osx-rm-dir-metadata @@ -5,7 +5,11 @@ # Sorin Ionescu # +# function osx-rm-dir-metadata { + find "${@:-$PWD}" \( \ -type f -name '.DS_Store' -o \ -type d -name '__MACOSX' \ \) -print0 | xargs -0 rm -rf + +# } diff --git a/modules/osx/functions/osx-rm-download-history b/modules/osx/functions/osx-rm-download-history index 3837709871..068ba3db93 100644 --- a/modules/osx/functions/osx-rm-download-history +++ b/modules/osx/functions/osx-rm-download-history @@ -1,13 +1,17 @@ # -# Deletes the Mac OS X download history. +# Deletes the macOS download history. # # Authors: # Sorin Ionescu # +# function osx-rm-download-history { + local db for db in ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV*; do if grep -q 'LSQuarantineEvent' < <(sqlite3 "$db" .tables); then sqlite3 "$db" 'DELETE FROM LSQuarantineEvent; VACUUM' fi done + +# } diff --git a/modules/osx/functions/pfd b/modules/osx/functions/pfd index a4d4b686bb..264b40ba6b 100644 --- a/modules/osx/functions/pfd +++ b/modules/osx/functions/pfd @@ -5,8 +5,12 @@ # Sorin Ionescu # -osascript 2>/dev/null < /dev/null < # +# function pfs { + osascript 2>&1 <&1 < # +# function ql { + if (( $# > 0 )); then qlmanage -p "$@" &> /dev/null fi + +# } diff --git a/modules/osx/functions/tab b/modules/osx/functions/tab index e0f2dc244f..c39a6a8e33 100644 --- a/modules/osx/functions/tab +++ b/modules/osx/functions/tab @@ -5,11 +5,13 @@ # Sorin Ionescu # +# function tab { + local command="cd \\\"$PWD\\\"" (( $# > 0 )) && command="${command}; $*" the_app=$( - osascript 2>/dev/null < /dev/null </dev/null < /dev/null </dev/null < /dev/null </dev/null < /dev/null < # +# 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/README.md b/modules/pacman/README.md index fb07407d69..a619a74777 100644 --- a/modules/pacman/README.md +++ b/modules/pacman/README.md @@ -7,17 +7,22 @@ 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). - zstyle ':prezto:module:pacman' frontend 'yaourt' +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. -If you have enabled color globally in *zpreztorc*, you may disable it for certain -commands. +To enable a Pacman frontend, add the following line to *zpreztorc*, substituting +`pacman_frontend` with the name of the frontent: -To disable `yaourt` highlighting, add the following line to *zpreztorc*: - - zstyle ':prezto:module:pacman:yaourt' color 'no' +```sh +zstyle ':prezto:module:pacman' frontend 'pacman_frontend' +``` Aliases ------- @@ -42,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/functions/pacman-list-disowned b/modules/pacman/functions/pacman-list-disowned index a097c9db99..c5e84fcf67 100644 --- a/modules/pacman/functions/pacman-list-disowned +++ b/modules/pacman/functions/pacman-list-disowned @@ -6,11 +6,13 @@ # Sorin Ionescu # -local tmp="${TMPDIR:-/tmp}/pacman-disowned-$UID-$$" +# function pacman-list-disowned { + +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" @@ -20,3 +22,5 @@ find /bin /etc /lib /sbin /usr \ \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" comm -23 "$fs" "$db" + +# } diff --git a/modules/pacman/functions/pacman-list-explicit b/modules/pacman/functions/pacman-list-explicit index 2967834f11..7c9b08f3c2 100644 --- a/modules/pacman/functions/pacman-list-explicit +++ b/modules/pacman/functions/pacman-list-explicit @@ -6,6 +6,8 @@ # Sorin Ionescu # +# function pacman-list-explicit { + pacman --query --explicit --info \ | awk ' BEGIN { @@ -18,3 +20,5 @@ pacman --query --explicit --info \ print $2 } ' + +# } diff --git a/modules/pacman/init.zsh b/modules/pacman/init.zsh index 9d752a9b1d..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 ' @@ -70,9 +66,9 @@ alias pacman-list-orphans="${_pacman_sudo}${_pacman_frontend} --query --deps --u alias pacman-remove-orphans="${_pacman_sudo}${_pacman_frontend} --remove --recursive \$(${_pacman_frontend} --quiet --query --deps --unrequired)" # Synchronizes the local package and Arch Build System databases against the -# repositories. -if (( $+commands[abs] )); then - alias pacu="${_pacman_sudo}${_pacman_frontend} --sync --refresh && sudo abs" +# repositories using the asp tool. +if (( $+commands[asp] )); then + alias pacu="${_pacman_sudo}${_pacman_frontend} --sync --refresh && sudo asp update" else alias pacu="${_pacman_sudo}${_pacman_frontend} --sync --refresh" fi @@ -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 90af1ebe4b..67f2a17798 100644 --- a/modules/perl/README.md +++ b/modules/perl/README.md @@ -1,28 +1,32 @@ 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 For Perl versions older than 5.14, install *local::lib*. - curl -L -C - -O http://search.cpan.org/CPAN/authors/id/A/AP/APEIRON/local-lib-1.008004.tar.gz - tar xvf local-lib-1.008004.tar.gz - cd local-lib-1.008004 - perl Makefile.PL --bootstrap=$HOME/Library/Perl/5.12 - make && make test && make install +```console +curl -L -C - -O http://search.cpan.org/CPAN/authors/id/A/AP/APEIRON/local-lib-1.008004.tar.gz +tar xvf local-lib-1.008004.tar.gz +cd local-lib-1.008004 +perl Makefile.PL --bootstrap=$HOME/Library/Perl/5.12 +make && make test && make install +``` Install *cpanminus*: - curl -L http://cpanmin.us | perl - --self-upgrade +```console +curl -L http://cpanmin.us | perl - --self-upgrade +``` Perlbrew -------- @@ -30,6 +34,14 @@ Perlbrew An alternative to the above is to use [Perlbrew][2], which allows for the management of multiple, isolated Perl installations in the home directory. +plenv +----- + +Yet another alternative is [plenv][3]. This is inspired from rbenv and enables +switching between multiple binary installations. + +The subcommands of plenv is similar with rbenv. + Aliases ------- @@ -51,13 +63,52 @@ Aliases - `plbu` uninstalls a Perl version. - `plbx` temporarily sets the Perl version to use. +### plenv + + - `plv` manages Perl environments. + - `plvc` List all available plenv commands. + - `plvl` Set or show the local application-specific Perl version. + - `plvg` Set or show the global Perl version. + - `plvs` Set or show the shell-specific Perl version. + - `plvi` Install a Perl version using the perl-build plugin. + - `plvu` Uninstall a specific Perl version. + - `plvr` Rehash plenv shims (run this after installing executables). + - `plvv` Show the current Perl version and its origin. + - `plvV` List all Perl versions available to plenv. + - `plvw` Display the full path to an executable. + - `plvW` List all Perl versions that contain the given executable. + - `plvm` List cpan modules in current perl. + - `plvM` Migrate cpan modules from other version. + - `plvI` Install cpanm. + +Functions +--------- + + - `perl-info` exposes information about the Perl environment via the + `$perl_info` associative array. + +Theming +------- + +To display the name of the current Perl version in a prompt, define the +following style in the `prompt_name_setup` function. + +```sh +# %v - perl version. +zstyle ':prezto:module:perl:info:version' format 'version:%v' +``` + +Then add `$perl_info[version]` to `$PROMPT` or `$RPROMPT` and call +`perl-info` in the `prompt_name_precmd` hook function. + 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][4].* - [Sorin Ionescu](https://github.com/sorin-ionescu) [1]: http://www.perl.org [2]: http://perlbrew.pl -[3]: https://github.com/sorin-ionescu/prezto/issues +[3]: https://github.com/tokuhirom/plenv +[4]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/perl/functions/perl-info b/modules/perl/functions/perl-info new file mode 100644 index 0000000000..b42e23d737 --- /dev/null +++ b/modules/perl/functions/perl-info @@ -0,0 +1,34 @@ +# +# Exposes information about the Perl environment via the $perl_info associative +# array. +# +# Authors: +# JINNOUCHI Yasushi +# + +# function perl-info { + +local version +local version_format +local version_formatted + +# Clean up previous $perl_info. +unset perl_info +typeset -gA perl_info + +if (( $+commands[perlbrew] )); then + version="${PERLBREW_PERL##*perl-}" +elif (( $+commands[plenv] )); then + version=$(plenv version-name) +elif (( $+commands[perl] )); then + version=$(perl -e 'printf "%vd", $^V') +fi + +# Format version. +if [[ -n "$version" ]]; then + zstyle -s ':prezto:module:perl:info:version' format 'version_format' + zformat -f version_formatted "$version_format" "v:$version" + perl_info[version]="$version_formatted" +fi + +# } diff --git a/modules/perl/init.zsh b/modules/perl/init.zsh index a8d56031bd..1b5e665761 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 @@ -10,25 +10,51 @@ if (( ! $+commands[perl] )); then return 1 fi +# Load dependencies. +pmodload 'helper' + +# +# Load Perlbrew or plenv +# + +# Load Perlbrew into the shell session. +if [[ -s "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/etc/bashrc" ]]; then + source "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/etc/bashrc" + + # Load Perlbrew completion. + if [[ -s "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/etc/perlbrew-completion.bash" ]]; then + source "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/etc/perlbrew-completion.bash" + fi + +# Load manually installed plenv into the shell session. +elif [[ -s "$HOME/.plenv/bin/plenv" ]]; then + path=("$HOME/.plenv/bin" $path) + eval "$(plenv init - --no-rehash zsh)" + +# Load package manager installed plenv into the shell session. +elif (( $+commands[plenv] )); then + eval "$(plenv init - --no-rehash zsh)" +fi + # # Local Module Installation # -if [[ "$OSTYPE" == darwin* ]]; then +if is-darwin; then # Perl is slow; cache its output. - cache_file="${0:h}/cache.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 [[ ! -s "$cache_file" ]]; 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 source "$cache_file" fi - unset perl_path - unset cache_file + unset cache_file perl_path fi # @@ -41,12 +67,31 @@ alias pld='perldoc' alias ple='perl -wlne' # Perlbrew -alias plb='perlbrew' -alias plba='perlbrew available' -alias plbi='perlbrew install' -alias plbl='perlbrew list' -alias plbo='perlbrew off' -alias plbO='perlbrew switch-off' -alias plbs='perlbrew switch' -alias plbu='perlbrew use' -alias plbx='perlbrew uninstall' +if (( $+commands[perlbrew] )); then + alias plb='perlbrew' + alias plba='perlbrew available' + alias plbi='perlbrew install' + alias plbl='perlbrew list' + alias plbo='perlbrew off' + alias plbO='perlbrew switch-off' + alias plbs='perlbrew switch' + alias plbu='perlbrew use' + alias plbx='perlbrew uninstall' + +elif (( $+commands[plenv] )); then + alias plv='plenv' + alias plvc='plenv commands' + alias plvl='plenv local' + alias plvg='plenv global' + alias plvs='plenv shell' + alias plvi='plenv install' + alias plvu='plenv uninstall' + alias plvr='plenv rehash' + alias plvv='plenv version' + alias plvV='plenv versions' + alias plvw='plenv which' + alias plvW='plenv whence' + alias plvm='plenv list-modules' + alias plvM='plenv migrate-modules' + alias plvI='plenv install-cpanm' +fi diff --git a/modules/prompt/README.md b/modules/prompt/README.md index dc02497746..ef32770b20 100644 --- a/modules/prompt/README.md +++ b/modules/prompt/README.md @@ -6,11 +6,34 @@ Loads prompt [themes][1]. Settings -------- +### Prompt Theme + To select a prompt theme, add the following to *zpreztorc*, and replace **name** with the name of the theme you wish to load. Setting it to **random** will load a random theme. - zstyle ':prezto:module:prompt' theme 'name' +```sh +zstyle ':prezto:module:prompt' theme 'name' +``` + +### Prompt Display Length + +To change working directory prompt display length from 'short', set the +following to 'long' (without `~` expansion) or 'full' (with `~` expansion) +in *zpreztorc*. + +```sh +zstyle ':prezto:module:prompt' pwd-length 'short' +``` + +### Display Return Value + +Some prompts display the return value in the prompt. If a prompt has support, +this can be disabled with the following snippet. + +```sh +zstyle ':prezto:module:prompt' show-return-val 'no' +``` Theming ------- @@ -20,13 +43,29 @@ A prompt theme is an autoloadable function file with a special name, project, themes **should** be placed in the *modules/prompt/functions* directory. +### Required Variables + +To ensure that your function works with the editor-info module you'll need to +set the following variable: + +``` + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' +``` + +This is to ensure compatibility with outside prompts, while allowing prezto +and prezto-compatible prompts to take full advantage of the editor module. +This should be set in the `prompt_name_setup` function after you've added +any additional hooks with `add-zsh-hook precmd prompt_name_precmd`. See below +for additional information about functions and hooks. + ### Theme Functions There are three theme functions, a setup function, a help function, and a preview function. The setup function **must** always be defined. The help function and the preview functions are optional. -#### prompt_name_setup +#### `prompt_name_setup` This function is called by the `prompt` function to install the theme. This function may define other functions as necessary to maintain the prompt, @@ -36,51 +75,57 @@ including a function that displays help or a function used to preview it. The most basic example of this function can be seen below. - function prompt_name_setup { - PROMPT='%m%# ' - RPROMPT='' - } +```sh +function prompt_name_setup { + PROMPT='%m%# ' + RPROMPT='' +} +``` -#### prompt_name_help +#### `prompt_name_help` If the `prompt_name_setup` function is customizable via parameters, a help function **should** be defined. The user will access it via `prompt -h name`. The most basic example of this function can be seen below. - function prompt_name_help { - cat <] [] + prompt theme [] [] - where the color is for the left-hand prompt. - EOH - } +where the color is for the left-hand prompt. +EOH +} +``` -#### prompt_name_preview +#### `prompt_name_preview` If the `prompt_name_setup` function is customizable via parameters, a preview function **should** be defined. The user will access it via `prompt -p name`. The most basic example of this function can be seen below. - function prompt_name_preview { - if (( $# > 0 )); then - prompt_preview_theme theme "$@" - else - prompt_preview_theme theme red green blue - print - prompt_preview_theme theme yellow magenta black - fi - } +```sh +function prompt_name_preview { + if (( $# > 0 )); then + prompt_preview_theme theme "$@" + else + prompt_preview_theme theme red green blue + print + prompt_preview_theme theme yellow magenta black + fi +} +``` ### Hook Functions There are many Zsh [hook][2] functions, but mostly the *precmd* hook will be used. -#### prompt_name_precmd +#### `prompt_name_precmd` This hook is called before the prompt is displayed and is useful for getting information to display in a prompt. @@ -93,11 +138,25 @@ a function before you calling it. The most basic example of this function can be seen below. - function prompt_name_precmd { - if (( $+functions[git-info] )); then - git-info - fi - } +```sh +function prompt_name_precmd { + if (( $+functions[git-info] )); then + git-info + fi +} +``` + +Troubleshooting +--------------- + +### Fonts aren't displaying properly. + +On most systems, themes which use special characters need to have a patched font +installed and configured properly. + +Powerline provides some information on [terminal support][4] and [how to install +patched fonts][5] which should fix most font issues. + Authors ------- @@ -109,3 +168,5 @@ Authors [1]: http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Prompt-Themes [2]: http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions [3]: https://github.com/sorin-ionescu/prezto/issues +[4]: http://powerline.readthedocs.io/en/master/usage.html#terminal-emulator-requirements +[5]: http://powerline.readthedocs.io/en/latest/installation.html#fonts-installation diff --git a/modules/prompt/external/async b/modules/prompt/external/async new file mode 160000 index 0000000000..95c2b1577f --- /dev/null +++ b/modules/prompt/external/async @@ -0,0 +1 @@ +Subproject commit 95c2b1577f455728ec01cec001a86c216d0af2bd diff --git a/modules/prompt/external/powerlevel10k b/modules/prompt/external/powerlevel10k new file mode 160000 index 0000000000..0c341b6702 --- /dev/null +++ b/modules/prompt/external/powerlevel10k @@ -0,0 +1 @@ +Subproject commit 0c341b67024642b8f1741920d1ae5d760bc488b0 diff --git a/modules/prompt/external/powerlevel9k b/modules/prompt/external/powerlevel9k new file mode 160000 index 0000000000..2f4b15041f --- /dev/null +++ b/modules/prompt/external/powerlevel9k @@ -0,0 +1 @@ +Subproject commit 2f4b15041fe31d85dc9ef705b818c3a0e6985da3 diff --git a/modules/prompt/functions/async b/modules/prompt/functions/async index d4b591e1e9..ae0ec558e4 120000 --- a/modules/prompt/functions/async +++ b/modules/prompt/functions/async @@ -1 +1 @@ -../external/pure/async.zsh \ No newline at end of file +../external/async/async.zsh \ No newline at end of file diff --git a/modules/prompt/functions/prompt-pwd b/modules/prompt/functions/prompt-pwd new file mode 100644 index 0000000000..d2d1788fdf --- /dev/null +++ b/modules/prompt/functions/prompt-pwd @@ -0,0 +1,31 @@ +# +# Prompt setup function commonly used by prompt themes. +# +# Authors: +# Sorin Ionescu +# + +# function prompt-pwd { + +setopt localoptions extendedglob + +local current_pwd="${PWD/#$HOME/~}" +local ret_directory + +if [[ "$current_pwd" == (#m)[/~] ]]; then + ret_directory="$MATCH" + unset MATCH +elif zstyle -m ':prezto:module:prompt' pwd-length 'full'; then + ret_directory=${PWD} +elif zstyle -m ':prezto:module:prompt' pwd-length 'long'; then + ret_directory=${current_pwd} +else + ret_directory="${${${${(@j:/:M)${(@s:/:)current_pwd}##.#?}:h}%/}//\%/%%}/${${current_pwd:t}//\%/%%}" +fi + +unset current_pwd + +print "$ret_directory" + +# } +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_cloud_setup b/modules/prompt/functions/prompt_cloud_setup index 3b048df13e..be2a33a495 100644 --- a/modules/prompt/functions/prompt_cloud_setup +++ b/modules/prompt/functions/prompt_cloud_setup @@ -76,7 +76,7 @@ function prompt_cloud_preview { function prompt_cloud_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Set the theme prefix to a cloud or to the user's given characters. if [[ -n "$1" ]]; then @@ -104,6 +104,9 @@ function prompt_cloud_setup { # Add hook for calling git-info before each command. add-zsh-hook precmd prompt_cloud_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set git-info parameters. zstyle ':prezto:module:git:info' verbose 'yes' zstyle ':prezto:module:git:info:dirty' format "%%B%F{$secondary_color}]%f%%b %F{yellow}⚡%f" @@ -119,3 +122,4 @@ function prompt_cloud_setup { } prompt_cloud_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_damoekri_setup b/modules/prompt/functions/prompt_damoekri_setup index 89e4d75836..1fbaedfb03 100644 --- a/modules/prompt/functions/prompt_damoekri_setup +++ b/modules/prompt/functions/prompt_damoekri_setup @@ -16,7 +16,7 @@ prompt_damoekri_precmd() { unsetopt XTRACE KSH_ARRAYS # Format PWD. - _prompt_damoekri_pwd=$(promptpwd) + _prompt_damoekri_pwd=$(prompt-pwd) # Get Git repository information. if (( $+functions[git-info] )); then @@ -32,7 +32,7 @@ prompt_damoekri_precmd() { function prompt_damoekri_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -40,6 +40,9 @@ function prompt_damoekri_setup { # Add hook for calling git-info and ruby-info before each command. add-zsh-hook precmd prompt_damoekri_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set editor-info parameters. zstyle ':prezto:module:editor:info:keymap:primary' format ' %F{green}»%f' @@ -63,3 +66,4 @@ function prompt_damoekri_setup { } prompt_damoekri_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_giddie_setup b/modules/prompt/functions/prompt_giddie_setup index 5a14ffe0f3..2b36ccc72a 100644 --- a/modules/prompt/functions/prompt_giddie_setup +++ b/modules/prompt/functions/prompt_giddie_setup @@ -38,7 +38,7 @@ function prompt_giddie_precmd { function prompt_giddie_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz vcs_info @@ -47,6 +47,9 @@ function prompt_giddie_setup { # Add hook to set up prompt parameters before each command. add-zsh-hook precmd prompt_giddie_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set editor-info parameters. zstyle ':prezto:module:editor:info:completing' format '%F{green}...%f' zstyle ':prezto:module:editor:info:keymap:alternate' format '%F{yellow}--- COMMAND ---%f' @@ -74,3 +77,4 @@ function prompt_giddie_setup { } prompt_giddie_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_kylewest_setup b/modules/prompt/functions/prompt_kylewest_setup index e4ee0c0ef0..d3b33a9548 100644 --- a/modules/prompt/functions/prompt_kylewest_setup +++ b/modules/prompt/functions/prompt_kylewest_setup @@ -32,7 +32,7 @@ function prompt_kylewest_precmd { function prompt_kylewest_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -40,6 +40,9 @@ function prompt_kylewest_setup { # Add hook for calling git-info before each command. add-zsh-hook precmd prompt_kylewest_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set editor-info parameters. zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b' zstyle ':prezto:module:editor:info:keymap:primary' format "%B%F{green}❯%f%b" @@ -63,3 +66,4 @@ function prompt_kylewest_setup { } prompt_kylewest_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_minimal_setup b/modules/prompt/functions/prompt_minimal_setup index 8c07e70ef5..e57aac57c1 100644 --- a/modules/prompt/functions/prompt_minimal_setup +++ b/modules/prompt/functions/prompt_minimal_setup @@ -23,7 +23,7 @@ function prompt_minimal_precmd { function prompt_minimal_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -32,6 +32,9 @@ function prompt_minimal_setup { # Add hook for calling vcs_info before each command. add-zsh-hook precmd prompt_minimal_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set vcs_info parameters. zstyle ':vcs_info:*' enable bzr git hg svn zstyle ':vcs_info:*' check-for-changes true @@ -47,4 +50,14 @@ function prompt_minimal_setup { RPROMPT='' } +function prompt_minimal_preview { + local +h PROMPT='' + local +h RPROMPT='' + local +h SPROMPT='' + + editor-info 2> /dev/null + prompt_preview_theme 'minimal' +} + prompt_minimal_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_nicoulaj_setup b/modules/prompt/functions/prompt_nicoulaj_setup index 241c8b6ea7..4b40bac8b1 100644 --- a/modules/prompt/functions/prompt_nicoulaj_setup +++ b/modules/prompt/functions/prompt_nicoulaj_setup @@ -26,7 +26,7 @@ function prompt_nicoulaj_precmd { function prompt_nicoulaj_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -35,6 +35,9 @@ function prompt_nicoulaj_setup { # Add hook for calling vcs_info before each command. add-zsh-hook precmd prompt_nicoulaj_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Customizable parameters. local max_path_chars=30 local user_char='❯' @@ -58,3 +61,4 @@ function prompt_nicoulaj_setup { } prompt_nicoulaj_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_paradox_setup b/modules/prompt/functions/prompt_paradox_setup index c5a8751568..9286967f9a 100644 --- a/modules/prompt/functions/prompt_paradox_setup +++ b/modules/prompt/functions/prompt_paradox_setup @@ -84,7 +84,7 @@ function prompt_paradox_precmd { unsetopt XTRACE KSH_ARRAYS # Format PWD. - _prompt_paradox_pwd=$(promptpwd) + _prompt_paradox_pwd=$(prompt-pwd) # Get Git repository information. if (( $+functions[git-info] )); then @@ -107,7 +107,7 @@ function prompt_paradox_preexec { function prompt_paradox_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -116,6 +116,9 @@ function prompt_paradox_setup { add-zsh-hook preexec prompt_paradox_preexec add-zsh-hook precmd prompt_paradox_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set editor-info parameters. zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b' zstyle ':prezto:module:editor:info:keymap:primary' format '%B%F{blue}❯%f%b' @@ -154,3 +157,4 @@ ${(e)$(prompt_paradox_build_prompt)} } prompt_paradox_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_peepcode_setup b/modules/prompt/functions/prompt_peepcode_setup index c70fb9a782..3a108df4a6 100644 --- a/modules/prompt/functions/prompt_peepcode_setup +++ b/modules/prompt/functions/prompt_peepcode_setup @@ -25,7 +25,7 @@ function prompt_peepcode_precmd { function prompt_peepcode_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -34,6 +34,9 @@ function prompt_peepcode_setup { # Add a hook for calling info functions before each command. add-zsh-hook precmd prompt_peepcode_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set git-info parameters. zstyle ':prezto:module:git:info' verbose 'no' zstyle ':prezto:module:git:info:action' format ' +%s' @@ -83,3 +86,4 @@ function prompt_peepcode_preview { } prompt_peepcode_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_powerlevel10k_setup b/modules/prompt/functions/prompt_powerlevel10k_setup new file mode 120000 index 0000000000..8c66c69696 --- /dev/null +++ b/modules/prompt/functions/prompt_powerlevel10k_setup @@ -0,0 +1 @@ +../external/powerlevel10k/powerlevel10k.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/prompt_powerlevel9k_setup b/modules/prompt/functions/prompt_powerlevel9k_setup new file mode 120000 index 0000000000..f692e0ae77 --- /dev/null +++ b/modules/prompt/functions/prompt_powerlevel9k_setup @@ -0,0 +1 @@ +../external/powerlevel9k/powerlevel9k.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/prompt_skwp_setup b/modules/prompt/functions/prompt_skwp_setup index 1c8f0a90af..b84011fe53 100644 --- a/modules/prompt/functions/prompt_skwp_setup +++ b/modules/prompt/functions/prompt_skwp_setup @@ -28,7 +28,7 @@ function prompt_skwp_precmd { function prompt_skwp_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -36,6 +36,9 @@ function prompt_skwp_setup { # Add hook to set up prompt parameters before each command. add-zsh-hook precmd prompt_skwp_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Use extended color pallete if available. if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then _prompt_skwp_colors=( @@ -73,3 +76,4 @@ function prompt_skwp_setup { } prompt_skwp_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_smiley_setup b/modules/prompt/functions/prompt_smiley_setup index 3066a2dc2b..cd1725bd05 100644 --- a/modules/prompt/functions/prompt_smiley_setup +++ b/modules/prompt/functions/prompt_smiley_setup @@ -36,11 +36,14 @@ 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 + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set editor-info parameters. zstyle ':prezto:module:editor:info:completing' format '%B%F{red}...%f%b' @@ -63,3 +66,4 @@ function prompt_smiley_setup { } prompt_smiley_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_sorin_setup b/modules/prompt/functions/prompt_sorin_setup index c4d12c343f..a7d341ee8d 100644 --- a/modules/prompt/functions/prompt_sorin_setup +++ b/modules/prompt/functions/prompt_sorin_setup @@ -32,33 +32,60 @@ # Load dependencies. pmodload 'helper' -prompt_sorin_git_info() { - if (( _prompt_sorin_precmd_async_pid > 0 )); then - # Append Git status. - if [[ -s "$_prompt_sorin_precmd_async_data" ]]; then - alias typeset='typeset -g' - source "$_prompt_sorin_precmd_async_data" - RPROMPT+='${git_info:+${(e)git_info[status]}}' - unalias typeset - fi - - # Reset PID. - _prompt_sorin_precmd_async_pid=0 - - # Redisplay prompt. - 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 + ;; + "[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 } -function prompt_sorin_precmd_async { - # Get Git repository information. +function prompt_sorin_async_git { + cd -q "$1" if (( $+functions[git-info] )); then git-info - typeset -p git_info >! "$_prompt_sorin_precmd_async_data" + print ${git_info[status]} fi +} - # Signal completion to parent process. - kill -WINCH $$ +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 { @@ -66,35 +93,41 @@ function prompt_sorin_precmd { unsetopt XTRACE KSH_ARRAYS # Format PWD. - _prompt_sorin_pwd=$(promptpwd) - - # Define prompts. - RPROMPT='${editor_info[overwrite]}%(?:: %F{1}⏎%f)${VIM:+" %B%F{6}V%f%b"}' + _prompt_sorin_pwd=$(prompt-pwd) + + # 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 + local new_git_root="$(git-dir 2> /dev/null)" + if [[ $new_git_root != $_sorin_cur_git_root ]]; then + _prompt_sorin_git='' + _sorin_cur_git_root=$new_git_root + fi + fi - # Kill the old process of slow commands if it is still running. - if (( _prompt_sorin_precmd_async_pid > 0 )); then - kill -KILL "$_prompt_sorin_precmd_async_pid" &>/dev/null + # 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. - trap prompt_sorin_git_info WINCH - prompt_sorin_precmd_async &! - _prompt_sorin_precmd_async_pid=$! + prompt_sorin_async_tasks } function prompt_sorin_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) - _prompt_sorin_precmd_async_pid=0 - _prompt_sorin_precmd_async_data="${TMPPREFIX}-prompt_sorin_data" + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook + autoload -Uz async && async # Add hook for calling git-info before each command. add-zsh-hook precmd prompt_sorin_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Set editor-info parameters. zstyle ':prezto:module:editor:info:completing' format '%B%F{7}...%f%b' zstyle ':prezto:module:editor:info:keymap:primary' format ' %B%F{1}❯%F{3}❯%F{2}❯%f%b' @@ -117,11 +150,29 @@ function prompt_sorin_setup { zstyle ':prezto:module:git:info:unmerged' format ' %%B%F{3}═%f%%b' zstyle ':prezto:module:git:info:untracked' format ' %%B%F{7}◼%f%%b' zstyle ':prezto:module:git:info:keys' format \ - 'status' '$(coalesce "%b" "%p" "%c")%s%A%B%S%a%d%m%r%U%u' + 'status' '%b %p %c:%s%A%B%S%a%d%m%r%U%u' + + # Set python-info parameters. + zstyle ':prezto:module:python:info:virtualenv' format '%f%F{3}(%v)%F{7} ' + + # Set up non-zero return value display + local show_return="✘ " + # Default is to show the return value + if zstyle -T ':prezto:module:prompt' show-return-val; then + show_return+='%? ' + fi + + # Get the async worker set up. + _sorin_cur_git_root='' + + _prompt_sorin_git='' + _prompt_sorin_pwd='' # Define prompts. PROMPT='${SSH_TTY:+"%F{9}%n%f%F{7}@%f%F{3}%m%f "}%F{4}${_prompt_sorin_pwd}%(!. %B%F{1}#%f%b.)${editor_info[keymap]} ' - RPROMPT='' + RPROMPT='$python_info[virtualenv]${editor_info[overwrite]}%(?:: %F{1}' + RPROMPT+=${show_return} + RPROMPT+='%f)${VIM:+" %B%F{6}V%f%b"}${_prompt_sorin_git}' SPROMPT='zsh: correct %F{1}%R%f to %F{2}%r%f [nyae]? ' } @@ -130,8 +181,9 @@ function prompt_sorin_preview { local +h RPROMPT='' local +h SPROMPT='' - editor-info 2>/dev/null + editor-info 2> /dev/null prompt_preview_theme 'sorin' } prompt_sorin_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/prompt_steeef_setup b/modules/prompt/functions/prompt_steeef_setup index 996331fd58..d32bd343f0 100644 --- a/modules/prompt/functions/prompt_steeef_setup +++ b/modules/prompt/functions/prompt_steeef_setup @@ -32,7 +32,7 @@ function prompt_steeef_precmd { function prompt_steeef_setup { setopt LOCAL_OPTIONS unsetopt XTRACE KSH_ARRAYS - prompt_opts=(cr percent subst) + prompt_opts=(cr percent sp subst) # Load required functions. autoload -Uz add-zsh-hook @@ -41,6 +41,9 @@ function prompt_steeef_setup { # Add hook for calling vcs_info before each command. add-zsh-hook precmd prompt_steeef_precmd + # Tell prezto we can manage this prompt + zstyle ':prezto:module:prompt' managed 'yes' + # Use extended color pallete if available. if [[ $TERM = *256color* || $TERM = *rxvt* ]]; then _prompt_steeef_colors=( @@ -72,6 +75,9 @@ function prompt_steeef_setup { local unstaged_format="${_prompt_steeef_colors[2]}●%f" local staged_format="${_prompt_steeef_colors[5]}●%f" + # Set editor-info parameters. + zstyle ':prezto:module:editor:info:keymap:primary' format '$' + # Set vcs_info parameters. zstyle ':vcs_info:*' enable bzr git hg svn zstyle ':vcs_info:*:prompt:*' check-for-changes true @@ -87,8 +93,18 @@ function prompt_steeef_setup { # Define prompts. PROMPT=" ${_prompt_steeef_colors[3]}%n%f at ${_prompt_steeef_colors[2]}%m%f in ${_prompt_steeef_colors[5]}%~%f "'${vcs_info_msg_0_}'" -"'$python_info[virtualenv]'"$ " +"'$python_info[virtualenv]${editor_info[keymap]} ' RPROMPT='' } +function prompt_steeef_preview { + local +h PROMPT='' + local +h RPROMPT='' + local +h SPROMPT='' + + editor-info 2> /dev/null + prompt_preview_theme 'steeef' +} + prompt_steeef_setup "$@" +# vim: ft=zsh diff --git a/modules/prompt/functions/promptpwd b/modules/prompt/functions/promptpwd deleted file mode 100644 index b8fcc0cb41..0000000000 --- a/modules/prompt/functions/promptpwd +++ /dev/null @@ -1,16 +0,0 @@ -# prompt setup function common to many prompts -# moved to external function to reduce code redundancy - -setopt localoptions extendedglob - -local current_pwd="${PWD/#$HOME/~}" -local ret_directory - -if [[ "$current_pwd" == (#m)[/~] ]]; then - ret_directory="$MATCH" - unset MATCH -else - ret_directory="${${${${(@j:/:M)${(@s:/:)current_pwd}##.#?}:h}%/}//\%/%%}/${${current_pwd:t}//\%/%%}" -fi - -print "$ret_directory" diff --git a/modules/python/README.md b/modules/python/README.md index 4047d0ff8e..91dc87feae 100644 --- a/modules/python/README.md +++ b/modules/python/README.md @@ -3,6 +3,25 @@ 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 ------------------------- @@ -14,7 +33,10 @@ execution of `pyenv`. ### Usage -Install Python versions with `pyenv install` into *~/.pyenv/versions*. +Install Python versions with `pyenv install` into `~/.pyenv/versions`. + +This will be loaded automatically if pyenv is installed to `$PYENV_ROOT`, +`~/.pyenv`, or if the `pyenv` command is on the path. Local Package Installation -------------------------- @@ -28,43 +50,81 @@ documentation. ### Usage -Install packages into the per user site directory with `easy_install --user` or -`pip install --user`. +Install packages into the per user site directory with `pip install --user`. virtualenvwrapper ----------------- -[virtualenvwrapper][2] is a frontend to the popular [virtualenv][3] utility. +[`virtualenvwrapper`][2] is a frontend to the popular [`virtualenv`][3] utility. -virtualenv creates isolated Python environments and virtualenvwrapper provides -convenient shell functions to create, switch, and manage them. +`virtualenv` creates isolated Python environments and `virtualenvwrapper` +provides convenient shell functions to create, switch, and manage them. ### Usage -Install virtualenvwrapper. +Install `virtualenvwrapper`. -Virtual environments are stored in *~/.virtualenvs*. +Virtual environments are stored in `~/.virtualenvs`. There are configuration variables that have to be set to enable certain features. -If you wish to use these features, export the variables in *~/.zshenv* +If you wish to use these features, export the variables in [`zshenv`][6]. -The variable `$PROJECT_HOME` tells virtualenvwrapper where to place project +The variable `$PROJECT_HOME` tells `virtualenvwrapper` where to place project working directories. It must be set and the directory created before `mkproject` is used. Replace *Developer* with your projects directory. - export PROJECT_HOME="$HOME/Developer" +```sh +export PROJECT_HOME="$HOME/Developer" +``` + +The variable `VIRTUALENVWRAPPER_PYTHON` tells `virtualenvwrapper` to use the +specified full path of the `python` interpreter overriding the `$PATH` search. + +```sh +export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python +``` -The variable `$VIRTUALENVWRAPPER_VIRTUALENV_ARGS` tells virtualenvwrapper what +The variable `VIRTUALENVWRAPPER_VIRTUALENV` tells `virtualenvwrapper` to use the +specified full path of `virtualenv` binary overriding the `$PATH` search. + +```sh +export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv +``` + +The variable `$VIRTUALENVWRAPPER_VIRTUALENV_ARGS` tells `virtualenvwrapper` what arguments to pass to `virtualenv`. For example, set the value to -*--system-site-packages* to ensure that all new environments have access to the +`--system-site-packages` to ensure that all new environments have access to the system site-packages directory. - export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--system-site-packages' +```sh +export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--system-site-packages' +``` + +### Additional Options + +There is a hook to enable auto-switching to virtualenvs when switching into a +directory where the root of the project matches a virtualenv name. + +This can be enabled with: + +```sh +zstyle ':prezto:module:python:virtualenv' auto-switch 'yes' +``` + +`virtualenvwrapper` is automatically initialized if pre-requisites are met +(`$VIRTUALENVWRAPPER_VIRTUALENV` is explicitly set or `virtualenv` is in +`$PATH`). This can be disabled with: + +```sh +zstyle ':prezto:module:python:virtualenv' initialize 'no' +``` Aliases ------- - `py` is short for `python`. + - `py2` is short for `python2`. + - `py3` is short for `python3`. Functions --------- @@ -84,6 +144,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 ------- @@ -97,3 +161,4 @@ Authors [3]: http://pypi.python.org/pypi/virtualenv [4]: https://github.com/yyuu/pyenv [5]: https://github.com/sorin-ionescu/prezto/issues +[6]: https://github.com/sorin-ionescu/prezto/blob/master/runcoms/zshenv diff --git a/modules/python/functions/python-info b/modules/python/functions/python-info index 6a8c758934..144a5b6a29 100644 --- a/modules/python/functions/python-info +++ b/modules/python/functions/python-info @@ -4,18 +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 458253b2e7..33248bae74 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -4,24 +4,28 @@ # Authors: # Sorin Ionescu # Sebastian Wiesner +# Patrick Bos # -# Load manually installed pyenv into the shell session. -if [[ -s "$HOME/.pyenv/bin/pyenv" ]]; then - path=("$HOME/.pyenv/bin" $path) - eval "$(pyenv init -)" +# Load dependencies +pmodload 'helper' -# Load package manager installed pyenv into the shell session. +# Load manually installed pyenv into the path +if [[ -s "${PYENV_ROOT:=$HOME/.pyenv}/bin/pyenv" ]]; then + path=("${PYENV_ROOT}/bin" $path) + eval "$(pyenv init - --no-rehash zsh)" + +# Load pyenv into the current python session elif (( $+commands[pyenv] )); then - eval "$(pyenv init -)" + eval "$(pyenv init - --no-rehash zsh)" # 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 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. @@ -34,16 +38,156 @@ if (( ! $+commands[python] && ! $+commands[pyenv] )); then return 1 fi -# Load virtualenvwrapper into the shell session, unless requested not to -zstyle -t ':prezto:module:python' skip-virtualenvwrapper-init -if (( $? && $+commands[virtualenvwrapper.sh] )); then +function _python-workon-cwd { + # Check if this is a Git repo + local GIT_REPO_ROOT="" + local GIT_TOPLEVEL="$(git rev-parse --show-toplevel 2> /dev/null)" + if [[ $? == 0 ]]; then + GIT_REPO_ROOT="$GIT_TOPLEVEL" + fi + # Get absolute path, resolving symlinks + local PROJECT_ROOT="${PWD:A}" + while [[ "$PROJECT_ROOT" != "/" && ! -e "$PROJECT_ROOT/.venv" \ + && ! -d "$PROJECT_ROOT/.git" && "$PROJECT_ROOT" != "$GIT_REPO_ROOT" ]]; do + PROJECT_ROOT="${PROJECT_ROOT:h}" + done + if [[ "$PROJECT_ROOT" == "/" ]]; then + PROJECT_ROOT="." + fi + # Check for virtualenv name override + local ENV_NAME="" + if [[ -f "$PROJECT_ROOT/.venv" ]]; then + ENV_NAME="$(cat "$PROJECT_ROOT/.venv")" + elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]]; then + ENV_NAME="$PROJECT_ROOT/.venv" + elif [[ "$PROJECT_ROOT" != "." ]]; then + ENV_NAME="${PROJECT_ROOT:t}" + fi + if [[ -n $CD_VIRTUAL_ENV && "$ENV_NAME" != "$CD_VIRTUAL_ENV" ]]; then + # We've just left the repo, deactivate the environment + # Note: this only happens if the virtualenv was activated automatically + deactivate && unset CD_VIRTUAL_ENV + fi + 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 + 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" + fi + fi + fi +} + +# 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 + +# Load virtualenvwrapper into the shell session, if pre-requisites are met +# and unless explicitly requested not to +if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) && \ + zstyle -T ':prezto:module:python:virtualenv' initialize ; then # Set the directory where virtual environments are stored. export WORKON_HOME="${WORKON_HOME:-$HOME/.virtualenvs}" - # Disable the virtualenv prompt. - VIRTUAL_ENV_DISABLE_PROMPT=1 + # Disable the virtualenv prompt. Note that we use the magic value used by the + # pure prompt because there's some additional logic in that prompt which tries + # to figure out if a user set this variable and disable the python portion of + # that prompt based on it which is the exact opposite of what we want to do. + export VIRTUAL_ENV_DISABLE_PROMPT=12 + + # Create a sorted array of available virtualenv related 'pyenv' commands to + # look for plugins of interest. Scanning shell '$path' isn't enough as they + # can exist in 'pyenv' synthesized paths (e.g., '~/.pyenv/plugins') instead. + local -a pyenv_plugins + if (( $+commands[pyenv] )); then + pyenv_plugins=(${(@oM)${(f)"$(pyenv commands --no-sh 2>/dev/null)"}:#virtualenv*}) + fi + + if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then + # Enable 'virtualenv' with 'pyenv'. + eval "$(pyenv virtualenv-init - zsh)" + + # Optionally activate 'virtualenvwrapper' plugin when available. + if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then + pyenv "$pyenv_plugins[(R)virtualenvwrapper(_lazy|)]" + fi + 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) + ) + if (( $#virtenv_sources )); then + source "${virtenv_sources[1]}" + fi + + unset virtenv_sources + fi + + unset pyenv_plugins +fi + +# Load PIP completion. +# 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 \ + | sed -e "s/\(compctl -K [-_[:alnum:]]* pip\).*/\1{,2,3}{,.{0..9}}/" \ + >! "$cache_file" \ + 2> /dev/null + fi + + source "$cache_file" - source "$commands[virtualenvwrapper.sh]" + unset cache_file +fi +unset pip_command + +# 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 # @@ -51,3 +195,5 @@ fi # alias py='python' +alias py2='python2' +alias py3='python3' diff --git a/modules/rsync/README.md b/modules/rsync/README.md index 951e3c6ad5..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 @@ -23,5 +23,5 @@ Authors - [Sorin Ionescu](https://github.com/sorin-ionescu) [1]: http://rsync.samba.org -[2]: http://help.bombich.com/kb/overview/credits#opensource +[2]: https://bombich.com/kb/ccc5/credits#rsync [3]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/rsync/init.zsh b/modules/rsync/init.zsh index 3afebdb4dd..79432c1251 100644 --- a/modules/rsync/init.zsh +++ b/modules/rsync/init.zsh @@ -10,19 +10,23 @@ if (( ! $+commands[rsync] )); then return 1 fi +# Load dependencies. +pmodload 'helper' + # # Aliases # -_rsync_cmd='rsync --verbose --progress --human-readable --compress --archive --hard-links --one-file-system' +_rsync_cmd='rsync --verbose --progress --human-readable --compress --archive \ + --hard-links --one-file-system' if grep -q 'xattrs' <(rsync --help 2>&1); then _rsync_cmd="${_rsync_cmd} --acls --xattrs" fi -# Mac OS X and HFS+ Enhancements -# http://help.bombich.com/kb/overview/credits#opensource -if [[ "$OSTYPE" == darwin* ]] && grep -q 'file-flags' <(rsync --help 2>&1); then +# macOS and HFS+ Enhancements +# https://bombich.com/kb/ccc5/credits +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/ruby/README.md b/modules/ruby/README.md index 372d00f1f5..feaa3016a5 100644 --- a/modules/ruby/README.md +++ b/modules/ruby/README.md @@ -8,7 +8,7 @@ Local Gem Installation ---------------------- When a Ruby version manager is not detected, local gems are installed in -*~/.gems*; otherwise, they are installed according to the manager. +`~/.gems`; otherwise, they are installed according to the manager. RVM --- @@ -32,10 +32,13 @@ multiple, isolated Ruby installations in the home directory. While it is not as feature rich as RVM, it is not loaded into the shell and is not known to cause conflicts with shell scripts. +This will be loaded automatically if rbenv is installed to `$RBENV_ROOT`, +`~/.rbenv`, or if the `rbenv` command is on the path. + chruby ------ -Yet another alternative is [chruby][6], which is simpler than both RVM and +Yet another alternative is [chruby][4], which is simpler than both RVM and rbenv. ### Settings @@ -43,15 +46,17 @@ rbenv. #### Auto-Switch To enable auto switching the Ruby version on directory change based on the -.ruby-version file, add the following line to *zpreztorc*: +`.ruby-version` file, add the following line to [`zpreztorc`][5]: - zstyle ':prezto:module:ruby:chruby' auto-switch 'yes' +```sh +zstyle ':prezto:module:ruby:chruby' auto-switch 'yes' +``` Bundler ------- Manage gems that are not meant to be used as commands, such as application -dependencies, with [Bundler][4]. +dependencies, with [Bundler][6]. Aliases ------- @@ -65,14 +70,14 @@ Aliases - `rbb` manages ruby dependencies (`bundle`). - `rbbc` cleans up unused gems in your bundler directory. - `rbbe` executes a script in the context of the current bundle. - - `rbbi` installs the gems specified in the *Gemfile* in *vendor/bundle*. + - `rbbi` installs the gems specified in the `Gemfile` in `vendor/bundle`. - `rbbI` installs the following: - - gems specified in the *Gemfile* in *vendor/bundle*. - - packages the gems into *vendor/cache*. - - appends bundler directories to *.gitignore*. + - gems specified in the `Gemfile` in `vendor/bundle`. + - packages the gems into `vendor/cache`. + - appends bundler directories to `.gitignore`. - `rbbl` lists all gems in the current bundle. - `rbbo` opens an installed gem in the editor. - - `rbbp` packages gem files into *vendor/cache*. + - `rbbp` packages gem files into `vendor/cache`. - `rbbu` updates gems to their latest version. Functions @@ -97,13 +102,14 @@ Then add `$ruby_info[version]` to `$PROMPT` or `$RPROMPT` and call Authors ------- -*The authors of this module should be contacted via the [issue tracker][5].* +*The authors of this module should be contacted via the [issue tracker][7].* - [Sorin Ionescu](https://github.com/sorin-ionescu) [1]: http://www.ruby-lang.org [2]: https://rvm.io [3]: https://github.com/sstephenson/rbenv -[4]: http://gembundler.com -[5]: https://github.com/sorin-ionescu/prezto/issues -[6]: https://github.com/postmodern/chruby +[4]: https://github.com/postmodern/chruby +[5]: https://github.com/sorin-ionescu/prezto/blob/master/runcoms/zpreztorc +[6]: http://gembundler.com +[7]: https://github.com/sorin-ionescu/prezto/issues diff --git a/modules/ruby/functions/ruby-app-root b/modules/ruby/functions/ruby-app-root index ea35be6059..ef28c5b0e1 100644 --- a/modules/ruby/functions/ruby-app-root +++ b/modules/ruby/functions/ruby-app-root @@ -5,6 +5,8 @@ # Sorin Ionescu # +# function ruby-app-root { + local root_dir="$PWD" while [[ "$root_dir" != '/' ]]; do @@ -16,3 +18,5 @@ while [[ "$root_dir" != '/' ]]; do done return 1 + +# } diff --git a/modules/ruby/functions/ruby-info b/modules/ruby/functions/ruby-info index ebf0f7fe8d..cba0188f98 100644 --- a/modules/ruby/functions/ruby-info +++ b/modules/ruby/functions/ruby-info @@ -6,6 +6,8 @@ # Sorin Ionescu # +# function ruby-info { + local version local version_format local version_formatted @@ -14,17 +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' -# 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" +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" && "$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..1c1fb999e1 100644 --- a/modules/ruby/init.zsh +++ b/modules/ruby/init.zsh @@ -15,8 +15,8 @@ if [[ -s "$HOME/.rvm/scripts/rvm" ]]; then source "$HOME/.rvm/scripts/rvm" # Load manually installed rbenv into the shell session. -elif [[ -s "$HOME/.rbenv/bin/rbenv" ]]; then - path=("$HOME/.rbenv/bin" $path) +elif [[ -s "${RBENV_ROOT:=$HOME/.rbenv}/bin/rbenv" ]]; then + path=("${RBENV_ROOT}/bin" $path) eval "$(rbenv init - --no-rehash zsh)" # Load package manager installed rbenv into the shell session. @@ -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/screen/README.md b/modules/screen/README.md index ef96404920..0a9ff07c8a 100644 --- a/modules/screen/README.md +++ b/modules/screen/README.md @@ -13,12 +13,16 @@ Starts a GNU Screen session automatically when Zsh is launched. To enable this feature when launching Zsh in a local terminal, add the following line to *zpreztorc*: - zstyle ':prezto:module:screen:auto-start' local 'yes' +```sh +zstyle ':prezto:module:screen:auto-start' local 'yes' +``` To enable this feature when launching Zsh in a SSH connection, add the following line to *zpreztorc*: - zstyle ':prezto:module:screen:auto-start' remote 'yes' +```sh +zstyle ':prezto:module:screen:auto-start' remote 'yes' +``` Aliases ------- diff --git a/modules/ssh/README.md b/modules/ssh/README.md index 7324ae9a88..a1727b9a15 100644 --- a/modules/ssh/README.md +++ b/modules/ssh/README.md @@ -3,10 +3,6 @@ SSH Provides for an easier use of [SSH][1] by setting up [ssh-agent][2]. -This module is disabled on Mac OS X due to custom Apple SSH support rendering it -unnecessary. Use `ssh-add -K` to store identities in Keychain; they will be -added to `ssh-agent` automatically and persist between reboots. - Settings -------- @@ -14,7 +10,9 @@ Settings To load multiple identities, add the following line to *zpreztorc*: - zstyle ':prezto:module:ssh:load' identities 'id_rsa' 'id_dsa' 'id_github' +```sh +zstyle ':prezto:module:ssh:load' identities 'id_rsa' 'id_dsa' 'id_github' +``` Authors ------- diff --git a/modules/ssh/init.zsh b/modules/ssh/init.zsh index f632328d0b..b9567d4635 100644 --- a/modules/ssh/init.zsh +++ b/modules/ssh/init.zsh @@ -6,7 +6,7 @@ # # Return if requirements are not found. -if [[ "$OSTYPE" == darwin* ]] || (( ! $+commands[ssh-agent] )); then +if (( ! $+commands[ssh-agent] )); then return 1 fi @@ -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}" +_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" +_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 @@ -39,10 +41,20 @@ fi # Load identities. if ssh-add -l 2>&1 | grep -q 'The agent has no identities'; then zstyle -a ':prezto:module:ssh:load' identities '_ssh_identities' - if (( ${#_ssh_identities} > 0 )); then - ssh-add "$_ssh_dir/${^_ssh_identities[@]}" 2> /dev/null + # ssh-add has strange requirements for running SSH_ASKPASS, so we duplicate + # them here. Essentially, if the other requirements are met, we redirect stdin + # from /dev/null in order to meet the final requirement. + # + # From ssh-add(1): + # If ssh-add needs a passphrase, it will read the passphrase from the current + # terminal if it was run from a terminal. If ssh-add does not have a terminal + # associated with it but DISPLAY and SSH_ASKPASS are set, it will execute the + # program specified by SSH_ASKPASS and open an X11 window to read the + # passphrase. + if [[ -n "$DISPLAY" && -x "$SSH_ASKPASS" ]]; then + ssh-add ${_ssh_identities:+$_ssh_dir/${^_ssh_identities[@]}} < /dev/null 2> /dev/null else - ssh-add 2> /dev/null + ssh-add ${_ssh_identities:+$_ssh_dir/${^_ssh_identities[@]}} 2> /dev/null fi fi diff --git a/modules/syntax-highlighting/README.md b/modules/syntax-highlighting/README.md index 87f85bea99..7a5a30c356 100644 --- a/modules/syntax-highlighting/README.md +++ b/modules/syntax-highlighting/README.md @@ -3,9 +3,14 @@ Syntax Highlighting Integrates [zsh-syntax-highlighting][1] into Prezto. -This module should be loaded *second to last*, where last is the *prompt* -module, unless used in conjuncture with the *history-substring-search* module -where it must be loaded **before** it. +This module should be loaded before the *prompt* module. + +Additionally, if this module is used in conjunction with the +*history-substring-search* module, this module must be loaded **before** the +*history-substring-search* module. + +To elaborate: The relative order of loading the modules would be +'syntax-highlighting', 'history-substring-search' and 'prompt'. Contributors ------------ @@ -22,7 +27,9 @@ Settings To enable highlighting for this module only, add the following line to *zpreztorc*: - zstyle ':prezto:module:syntax-highlighting' color 'yes' +```sh +zstyle ':prezto:module:syntax-highlighting' color 'yes' +``` ### Highlighters @@ -31,12 +38,15 @@ only enables the *main* highlighter by default. To enable all highlighters, add the following to *zpreztorc*: - zstyle ':prezto:module:syntax-highlighting' highlighters \ - 'main' \ - 'brackets' \ - 'pattern' \ - 'cursor' \ - 'root' +```sh +zstyle ':prezto:module:syntax-highlighting' highlighters \ + 'main' \ + 'brackets' \ + 'pattern' \ + 'line' \ + 'cursor' \ + 'root' +``` ### Highlighting Styles @@ -45,10 +55,12 @@ Each syntax highlighter defines styles used to highlight tokens. To highlight, for example, builtins, commands, and functions in blue instead of green, add the following to *zpreztorc*: - zstyle ':prezto:module:syntax-highlighting' styles \ - 'builtin' 'bg=blue' \ - 'command' 'bg=blue' \ - 'function' 'bg=blue' +```sh +zstyle ':prezto:module:syntax-highlighting' styles \ + 'builtin' 'bg=blue' \ + 'command' 'bg=blue' \ + 'function' 'bg=blue' +``` Authors ------- diff --git a/modules/terminal/README.md b/modules/terminal/README.md index 5a607880b8..41a08855ee 100644 --- a/modules/terminal/README.md +++ b/modules/terminal/README.md @@ -11,21 +11,27 @@ Settings To auto set the terminal window and tab titles with the current command or directory, add the following to *zpreztorc*: - zstyle ':prezto:module:terminal' auto-title 'yes' +```sh +zstyle ':prezto:module:terminal' auto-title 'yes' +``` Auto titling is disabled inside terminal multiplexers (except inside dvtm) since it interferes with window names defined in configuration files and profile managers. This can be overridden by setting it to `always`. - zstyle ':prezto:module:terminal' auto-title 'always' +```sh +zstyle ':prezto:module:terminal' auto-title 'always' +``` ### Title formats To format terminal window and tab titles, add the following to *zpreztorc*: - zstyle ':prezto:module:terminal:window-title' format '%n@%m: %s' - zstyle ':prezto:module:terminal:tab-title' format '%m: %s' - zstyle ':prezto:module:terminal:multiplexer-title' format '%s' +```sh +zstyle ':prezto:module:terminal:window-title' format '%n@%m: %s' +zstyle ':prezto:module:terminal:tab-title' format '%m: %s' +zstyle ':prezto:module:terminal:multiplexer-title' format '%s' +``` `%s` will be replaced with the current working directory path or the currently executing program name. diff --git a/modules/terminal/init.zsh b/modules/terminal/init.zsh index c7b22b7a5d..2a5b9bed30 100644 --- a/modules/terminal/init.zsh +++ b/modules/terminal/init.zsh @@ -49,7 +49,7 @@ function _terminal-set-titles-with-command { local -A jobtexts_from_parent_shell jobtexts_from_parent_shell=(${(kv)jobtexts}) - jobs "$job_name" 2>/dev/null > >( + jobs "$job_name" 2> /dev/null > >( read index discarded # The index is already surrounded by brackets: [1]. _terminal-set-titles-with-command "${(e):-\$jobtexts_from_parent_shell$index}" diff --git a/modules/tmux/README.md b/modules/tmux/README.md index 11c8a08a0d..0738d7cfad 100644 --- a/modules/tmux/README.md +++ b/modules/tmux/README.md @@ -13,29 +13,43 @@ Starts a tmux session automatically when Zsh is launched. To enable this feature when launching Zsh in a local terminal, add the following line to *zpreztorc*: - zstyle ':prezto:module:tmux:auto-start' local 'yes' +```sh +zstyle ':prezto:module:tmux:auto-start' local 'yes' +``` To enable this feature when launching Zsh in a SSH connection, add the following line to *zpreztorc*: - zstyle ':prezto:module:tmux:auto-start' remote 'yes' +```sh +zstyle ':prezto:module:tmux:auto-start' remote 'yes' +``` In both cases, it will create a background session named _prezto_ if the tmux server is not started. +You can change the default session name with: + +```sh +zstyle ':prezto:module:tmux:session' name '' +``` + With `auto-start` enabled, you may want to control how multiple sessions are managed. The `destroy-unattached` option of tmux controls if the unattached sessions must be kept alive, making sessions available for later use, configured in *tmux.conf*: - set-option -g destroy-unattached [on | off] +```conf +set-option -g destroy-unattached [on | off] +``` #### iTerm2 Integration [iTerm2][6] offers significant integration with tmux. This can be enabled by adding the following line to *zpreztorc*: - zstyle ':prezto:module:tmux:iterm' integrate 'yes' +```sh +zstyle ':prezto:module:tmux:iterm' integrate 'yes' +``` Read [iTerm2 and tmux Integration][7] for more information. @@ -48,14 +62,16 @@ 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*: - set-option -g default-command "reattach-to-user-namespace -l $SHELL -l" +```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 070abcaf42..5c51855f2a 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" ]] && ( \ +if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && "$TERM_PROGRAM" != "vscode" ]] && ( \ ( [[ -n "$SSH_TTY" ]] && zstyle -t ':prezto:module:tmux:auto-start' remote ) || ( [[ -z "$SSH_TTY" ]] && zstyle -t ':prezto:module:tmux:auto-start' local ) \ ); then @@ -31,14 +31,14 @@ if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" ]] && ( \ # Create a 'prezto' session if no session has been defined in tmux.conf. if ! tmux has-session 2> /dev/null; then - tmux_session='prezto' + zstyle -s ':prezto:module:tmux:session' name tmux_session || tmux_session='prezto' tmux \ new-session -d -s "$tmux_session" \; \ set-option -t "$tmux_session" destroy-unattached off &> /dev/null fi - # Attach to the 'prezto' session or to the last session used. - exec tmux $_tmux_iterm_integration attach-session + # Attach to the 'prezto' session or to the last session used. (detach first) + exec tmux $_tmux_iterm_integration attach-session -d fi # diff --git a/modules/utility/README.md b/modules/utility/README.md index 2d276d6e30..1179478703 100644 --- a/modules/utility/README.md +++ b/modules/utility/README.md @@ -8,25 +8,39 @@ Settings ### Highlighting -If you have enabled color globally in *zpreztorc*, you may disable it for certain -commands. +If you have enabled color globally in *zpreztorc*, you may disable it for +certain commands. To disable `ls` color, add the following line to *zpreztorc*; when coloring is disabled, type indicators (\*, /, =>, @, =, |, %) will be appended to entries. - zstyle ':prezto:module:utility:ls' color 'no' +```sh +zstyle ':prezto:module:utility:ls' color 'no' +``` + +To disable GNU coreutils `ls` to list directories grouped first, add the following line to *zpreztorc*: + +```sh +zstyle ':prezto:module:utility:ls' dirs-first 'no' +``` To disable `diff` highlighting, add the following line to *zpreztorc*: - zstyle ':prezto:module:utility:diff' color 'no' +```sh +zstyle ':prezto:module:utility:diff' color 'no' +``` To disable `wdiff` highlighting, add the following line to *zpreztorc*: - zstyle ':prezto:module:utility:wdiff' color 'no' +```sh +zstyle ':prezto:module:utility:wdiff' color 'no' +``` To disable `make` highlighting, add the following line to *zpreztorc*: - zstyle ':prezto:module:utility:make' color 'no' +```sh +zstyle ':prezto:module:utility:make' color 'no' +``` Aliases ------- @@ -48,6 +62,12 @@ Aliases - `mysql` - `rm` +To disable all spelling corrections, add the following line to *zpreztorc*: + +```sh +zstyle ':prezto:module:utility' correct 'no' +``` + ### Disabled File Globbing - `bower` @@ -57,25 +77,21 @@ Aliases - `history` - `locate` - `rake` - - `rsync` - - `scp` + - `rsync` (selectively enabled for local files) + - `scp` (selectively enabled for local files) - `sftp` ### General - `_` executes a command as another user (`sudo`). - `b` opens the default web browser. - - `cp` copies files and directories interactively. - `diffu` shorthand for `diff --unified` - `e` opens the default editor. - - `ln` links files and directories interactively. - `mkdir` creates directories, including intermediary directories. - - `mv` moves files and directories interactively. - `p` opens the default pager. - `po` removes a directory from the stack and changes to it (`popd`). - `pu` changes the directory and pushes the old directory onto the stack (`pushd`). - - `rm` removes files and directories interactively. - `sa` search aliases for a word. - `type` displays all the attribute values of a shell parameter. @@ -94,7 +110,7 @@ Aliases - `lu` lists sorted by date, most recent last, shows access time. - `sl` lists directory contents (`ls`). -### Mac OS X Everywhere +### macOS Everywhere - `o` opens files and directories (`open` or `xdg-open`). - `get` downloads files (`curl` or `wget`). @@ -105,13 +121,27 @@ Aliases ### Resource Usage - - `df` displays free disk space using human readable units. + - `df` displays free disk space using human readable units (aliases to `pydf`, + if installed). - `du` displays disk usage using human readable units. - - `top` displays information about processes (aliased to `htop`, if installed). - - `topc` displays information about processes sorted by CPU usage (`htop` not - installed). - - `topm` displays information about processes sorted by RAM usage (`htop` not - installed). + - `top` displays information about processes. + - `topc` displays information about processes sorted by CPU usage. + - `topm` displays information about processes sorted by RAM usage. + +### Safe ops + +By default, `cp`,`ln`, `mv` and `rm` are aliased to their interactive variants. +If this is not desired, it can be disabled by adding the following line to +*zpreztorc*: + + zstyle ':prezto:module:utility' safe-ops 'no'. + +In addition, the following aliases have been added: + + - `cpi` copies files and directories interactively. + - `lni` links files and directories interactively. + - `mvi` moves files and directories interactively. + - `rmi` removes files and directories interactively. ### Miscellaneous @@ -132,10 +162,11 @@ Functions - `mkdcd` makes a directory and changes to it. - `popdls` pops an entry off the directory stack and lists its contents. - `pushdls` pushes an entry onto the directory stack and lists its contents. + - `noremoteglob` enable local path globbing but disable remote path globbing. ### 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/_noremoteglob b/modules/utility/functions/_noremoteglob new file mode 100644 index 0000000000..de5290e477 --- /dev/null +++ b/modules/utility/functions/_noremoteglob @@ -0,0 +1,11 @@ +#compdef noremoteglob +#autoload + +# +# Completes noremoteglob. +# +# Authors: +# Indrajit Raychaudhuri +# + +_precommand 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/prep b/modules/utility/functions/prep index 23028ec436..d6448aeb20 100644 --- a/modules/utility/functions/prep +++ b/modules/utility/functions/prep @@ -5,6 +5,8 @@ # Sorin Ionescu # +# function prep { + local usage pattern modifiers invert usage="$( @@ -50,3 +52,5 @@ pattern="$1" shift perl -n -l -e "print if ${invert:+not} m/${pattern//\//\\/}/${modifiers}" "$@" + +# } diff --git a/modules/utility/functions/psub b/modules/utility/functions/psub index ffc01088f8..af191fde60 100644 --- a/modules/utility/functions/psub +++ b/modules/utility/functions/psub @@ -5,6 +5,8 @@ # Sorin Ionescu # +# function psub { + local usage pattern replacement modifiers usage="$( @@ -51,3 +53,5 @@ replacement="$2" repeat 2 shift perl -i'.orig' -n -l -e "s/${pattern//\//\\/}/${replacement//\//\\/}/${modifiers}; print" "$@" + +# } 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/functions/zsh-help b/modules/utility/functions/zsh-help new file mode 100644 index 0000000000..f6605ea066 --- /dev/null +++ b/modules/utility/functions/zsh-help @@ -0,0 +1,102 @@ +# +# Provides a much easier way to search and access ZSH's manual. First checks for +# terms at the start of the manual, then checks if it's at start of a line allowing +# whitespace. +# +# Authors: +# Samantha McVey +# + +# function zsh-help { + +local usage="$( +cat <&2; fi + if man --pager='' ${i} | grep -E ${case} "${pattern}" > /dev/null; then + printf "%s" "${i}"; return 0; + fi + done + return 1 + } + # By default search only things at start of line + local first_prefix='^' + local prefix='^\s*' + if [[ ${1} == '--zsh-help-debug' ]]; then + shift; debug=1 + fi + if [[ ${1} == "--all" ]]; then + shift; first_prefix='' # We're searching everything, so remove the prefix + fi + if [[ $# < 1 || $1 == "--help" ]]; then + printf "%s\n" "${usage}" + unfunction _zsh-help-join; unfunction _zsh-help-try-query; # unfunction so it's not in the global scope + return 1 + fi + if [[ ${1} == "test" && $# == 1 ]]; then + case='' + pattern='^CONDITIONAL EXPRESSIONS$' + elif [[ ($1 == "-eq" || $1 == "-ne" || $1 == "-lt" || $1 == "-gt" || $1 == "-le" || $1 == "-ge") && $# == 1 ]]; then + case='' + pattern="${prefix}exp1\s+${1}\s+exp2" + elif [[ $1 == 'zstyle' ]]; then + pattern=$(_zsh-help-join '\s+' "$@") + section=ZSHMODULES + fi + # If it wasn't one of the special-cased things, check ZSHBUILTINS first. If + # not found there, we will search ZSHALL + if [[ ${pattern} == "" ]]; then + pattern="$(_zsh-help-join '\s+' "$@")" + # search for sections at the start of the man page first + section=$(_zsh-help-try-query "${case}" "${first_prefix}${pattern}") + # If it exists there, keep ZSHBUILTINS as the section + if (( $? == 0 )); then + pattern="${first_prefix}${pattern}" + elif [[ "${prefix}" ]]; then + # if not found, search for the term preceeded by whitetext + section=$(_zsh-help-try-query "${case}" "${prefix}${pattern}") + if (( $? == 0 )); then + pattern="${prefix}${pattern}" + else + pattern="" + fi + fi + if [[ ! ${pattern} ]]; then # Otherwise we use zshall + printf "Can't find term\n" 2>&1 + unfunction _zsh-help-join; unfunction _zsh-help-try-query; # unfunction so it's not in the global scope + return 1; + fi + fi + local command="man --pager=\"less ${case} -p '${pattern}'\" \"${section}\"" + if [[ ${debug} ]]; then + printf "\nFinal search term is:\n"; printf "%s\n" "${command}"; + else + eval $command + fi + local rtrn=$? + unfunction _zsh-help-join; unfunction _zsh-help-try-query; # unfunction so it's not in the global scope + return $? +#} diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh index 61f82c0b86..f26c526c49 100644 --- a/modules/utility/init.zsh +++ b/modules/utility/init.zsh @@ -11,7 +11,9 @@ pmodload 'helper' 'spectrum' # Correct commands. -setopt CORRECT +if zstyle -T ':prezto:module:utility' correct; then + setopt CORRECT +fi # # Aliases @@ -61,16 +63,34 @@ alias rm="${aliases[rm]:-rm}" alias sa='alias | grep -i' alias type='type -a' +# Safe ops. Ask the user before doing anything destructive. +alias rmi="${aliases[rm]:-rm} -i" +alias mvi="${aliases[mv]:-mv} -i" +alias cpi="${aliases[cp]:-cp} -i" +alias lni="${aliases[ln]:-ln} -i" +if zstyle -T ':prezto:module:utility' safe-ops; then + alias rm="${aliases[rm]:-rm} -i" + alias mv="${aliases[mv]:-mv} -i" + alias cp="${aliases[cp]:-cp} -i" + alias ln="${aliases[ln]:-ln} -i" +fi + # ls if is-callable 'dircolors'; then # GNU Core Utilities - alias ls='ls --group-directories-first' + + if zstyle -T ':prezto:module:utility:ls' dirs-first; then + alias ls="${aliases[ls]:-ls} --group-directories-first" + fi 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" @@ -80,11 +100,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 @@ -112,10 +136,10 @@ if zstyle -t ':prezto:module:utility:grep' color; then alias grep="${aliases[grep]:-grep} --color=auto" fi -# Mac OS X Everywhere -if [[ "$OSTYPE" == darwin* ]]; then +# macOS Everywhere +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' @@ -145,16 +169,12 @@ fi alias df='df -kh' alias du='du -kh' -if (( $+commands[htop] )); then - alias top=htop +if is-darwin || is-bsd; then + alias topc='top -o cpu' + alias topm='top -o vsize' else - if [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then - alias topc='top -o cpu' - alias topm='top -o vsize' - else - alias topc='top -o %CPU' - alias topm='top -o %MEM' - fi + alias topc='top -o %CPU' + alias topm='top -o %MEM' fi # Miscellaneous @@ -204,3 +224,27 @@ function find-exec { function psu { ps -U "${1:-$LOGNAME}" -o 'pid,%cpu,%mem,command' "${(@)argv[2,-1]}" } + +# Enables globbing selectively on path arguments. +# Globbing is enabled on local paths (starting in '/' and './') and disabled +# on remote paths (containing ':' but not starting in '/' and './'). This is +# useful for programs that have their own globbing for remote paths. +# Currently, this is used by default for 'rsync' and 'scp'. +# 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" + for arg in ${argv:2}; do case $arg in + ( ./* ) argo+=( ${~arg} ) ;; # local relative, glob + ( /* ) argo+=( ${~arg} ) ;; # local absolute, glob + ( *:* ) argo+=( ${arg} ) ;; # remote, noglob + ( * ) argo+=( ${~arg} ) ;; # default, glob + esac; done + command $cmd "${(@)argo}" +} diff --git a/modules/wakeonlan/README.md b/modules/wakeonlan/README.md index 9bde199ecc..dacfa52da4 100644 --- a/modules/wakeonlan/README.md +++ b/modules/wakeonlan/README.md @@ -14,11 +14,15 @@ Each file should contain a line with the MAC address of the target device and the network broadcast address. For instance, there might be a file *~/.wakeonlan/leto* with the following contents: - 00:11:22:33:44:55:66 192.168.0.255 +```conf +00:11:22:33:44:55:66 192.168.0.255 +``` To wake that device, use the following command: - wake leto +```sh +$ wake leto +``` For more information on the configuration file format, read the [wakeonlan man page][2]. diff --git a/modules/wakeonlan/functions/wake b/modules/wakeonlan/functions/wake index 5259c95b78..6f7d6c5a26 100644 --- a/modules/wakeonlan/functions/wake +++ b/modules/wakeonlan/functions/wake @@ -6,6 +6,8 @@ # Sorin Ionescu # +# function wake { + local config_file="$HOME/.wakeonlan/$1" if [[ ! -s "$config_file" ]]; then print "$0: invalid device file: $1" >&2 @@ -18,3 +20,5 @@ if (( ! $+commands[wakeonlan] )); then fi wakeonlan -f "$config_file" + +# } diff --git a/runcoms/README.md b/runcoms/README.md index 9df890e51a..29d9f8a98d 100644 --- a/runcoms/README.md +++ b/runcoms/README.md @@ -10,7 +10,7 @@ in */etc* by default. User-local configuration files have the same name as their global counterparts but are prefixed with a dot (hidden). Zsh looks for these files in the path -stored in the `$ZDOTDIR` environmental variable. However, if said variable is +stored in the `$ZDOTDIR` environment variable. However, if said variable is not defined, Zsh will use the user's home directory. File Descriptions diff --git a/runcoms/zlogin b/runcoms/zlogin index 30549f33f6..ac4d3422a2 100644 --- a/runcoms/zlogin +++ b/runcoms/zlogin @@ -8,16 +8,19 @@ # 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 } &! -# 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. +if [[ -o INTERACTIVE && -t 2 ]]; then + + # Print a random, hopefully interesting, adage. + if (( $+commands[fortune] )); then fortune -s print fi -fi + +fi >&2 diff --git a/runcoms/zlogout b/runcoms/zlogout index 7c27e88581..b5d9858c08 100644 --- a/runcoms/zlogout +++ b/runcoms/zlogout @@ -5,9 +5,15 @@ # Sorin Ionescu # -# Print the message. -cat <<-EOF +# Execute code only if STDERR is bound to a TTY. +[[ -o INTERACTIVE && -t 2 ]] && { -Thank you. Come again! - -- Dr. Apu Nahasapeemapetilon -EOF +SAYINGS=( + "So long and thanks for all the fish.\n -- Douglas Adams" + "Good morning! And in case I don't see ya, good afternoon, good evening and goodnight.\n --Truman Burbank" +) + +# Print a randomly-chosen message: +echo $SAYINGS[$(($RANDOM % ${#SAYINGS} + 1))] + +} >&2 diff --git a/runcoms/zpreztorc b/runcoms/zpreztorc index 8b2af26759..9a3c19ae3f 100644 --- a/runcoms/zpreztorc +++ b/runcoms/zpreztorc @@ -15,6 +15,12 @@ # 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 + +# Allow module overrides when pmodule-dirs causes module name collisions +# zstyle ':prezto:load' pmodule-allow-overrides 'yes' + # Set the Zsh modules to load (man zshmodules). # zstyle ':prezto:load' zmodule 'attr' 'stat' @@ -41,6 +47,14 @@ zstyle ':prezto:load' pmodule \ # Set the query found color. # zstyle ':prezto:module:autosuggestions:color' found '' +# +# Completions +# + +# Set the entries to ignore in static */etc/hosts* for host completion. +# zstyle ':prezto:module:completion:*:hosts' etc-host-ignores \ +# '0.0.0.0' '127.0.0.1' + # # Editor # @@ -81,6 +95,13 @@ zstyle ':prezto:module:editor' key-bindings 'emacs' # Set the search globbing flags. # zstyle ':prezto:module:history-substring-search' globbing-flags '' +# +# macOS +# + +# Set the keyword used by `mand` to open man pages in Dash.app +# zstyle ':prezto:module:osx:man' dash-keyword 'manpages' + # # Pacman # @@ -97,6 +118,25 @@ zstyle ':prezto:module:editor' key-bindings 'emacs' # Auto set to 'off' on dumb terminals. zstyle ':prezto:module:prompt' theme 'sorin' +# Set the working directory prompt display length. +# By default, it is set to 'short'. Set it to 'long' (without '~' expansion) +# for longer or 'full' (with '~' expansion) for even longer prompt display. +# zstyle ':prezto:module:prompt' pwd-length 'short' + +# Set the prompt to display the return code along with an indicator for non-zero +# return codes. This is not supported by all prompts. +# zstyle ':prezto:module:prompt' show-return-val 'yes' + +# +# Python +# + +# Auto switch the Python virtualenv on directory change. +# zstyle ':prezto:module:python:virtualenv' auto-switch 'yes' + +# Automatically initialize virtualenvwrapper if pre-requisites are met. +# zstyle ':prezto:module:python:virtualenv' initialize 'yes' + # # Ruby # @@ -173,3 +213,15 @@ zstyle ':prezto:module:prompt' theme 'sorin' # Integrate with iTerm2. # zstyle ':prezto:module:tmux:iterm' integrate 'yes' + +# Set the default session name: +# zstyle ':prezto:module:tmux:session' name 'YOUR DEFAULT SESSION NAME' + +# +# Utility +# + +# Enabled safe options. This aliases cp, ln, mv and rm so that they prompt +# before deleting or overwriting files. Set to 'no' to disable this safer +# behavior. +# zstyle ':prezto:module:utility' safe-ops 'yes' diff --git a/runcoms/zprofile b/runcoms/zprofile index 052d5f9892..acd774254c 100644 --- a/runcoms/zprofile +++ b/runcoms/zprofile @@ -36,7 +36,7 @@ fi # Ensure path arrays do not contain duplicates. typeset -gU cdpath fpath mailpath path -# Set the the list of directories that cd searches. +# Set the list of directories that cd searches. # cdpath=( # $cdpath # ) @@ -61,13 +61,3 @@ export LESS='-F -g -i -M -R -S -w -X -z-4' if (( $#commands[(i)lesspipe(|.sh)] )); then export LESSOPEN="| /usr/bin/env $commands[(i)lesspipe(|.sh)] %s 2>&-" fi - -# -# Temporary Files -# - -if [[ ! -d "$TMPDIR" ]]; then - export TMPDIR="$(mktemp -d)" -fi - -TMPPREFIX="${TMPDIR%/}/zsh" diff --git a/runcoms/zshenv b/runcoms/zshenv index 2d97203180..2dbf12a8bf 100644 --- a/runcoms/zshenv +++ b/runcoms/zshenv @@ -6,6 +6,6 @@ # # Ensure that a non-login, non-interactive shell has a defined environment. -if [[ "$SHLVL" -eq 1 && ! -o LOGIN && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then +if [[ ( "$SHLVL" -eq 1 && ! -o LOGIN ) && -s "${ZDOTDIR:-$HOME}/.zprofile" ]]; then source "${ZDOTDIR:-$HOME}/.zprofile" fi