From 8dc3e43a0d6f349dc6a78f66aa953e8ec58add2e Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 7 Jan 2019 18:25:34 -0500 Subject: [PATCH 01/26] Add a plugin mechanism \o/ This is a major change, where Zsh modules/plugins are not git submodules in the Zim repo anymore, but customized and installed separately as individual repositories. The discussion about this started more than 2 years ago in #88. Closes #299. This will allow contributors' modules to live in their own repositories. See #33, #138, #262, #281, #324. The current code has what, up to this point, I considered to be the best balance between simplicity, execution speed and number of files. One measured decision was to make the initialization of modules depend only on the `':zim' modules` style, keeping it as fast as possible. The `':zim:module' module` style is used to install, update and clean the modules, all operations that happen after the user got his as-blazing-fast-possible shell prompt. Even though I didn't care much about making install or update fast, `xargs` has a nice feature of allowing commands to be executed in parallel with `-P`. I took advantage of that. I've also worked on making the `zimfw` utility give the user some nice (while still minimalistic) output. Also I'm suggesting this as the new name for the `zmanage` tool, since `zimfw` does not shadow the `zim` wiki tool. --- .gitmodules | 28 -- README.md | 95 +++- init.zsh | 142 +++--- login_init.zsh | 34 +- modules/archive/README.md | 31 -- modules/archive/functions/_unarchive | 4 - modules/archive/functions/archive | 34 -- modules/archive/functions/unarchive | 41 -- modules/archive/init.zsh | 17 - modules/autosuggestions/README.md | 13 - modules/autosuggestions/external | 1 - modules/autosuggestions/init.zsh | 9 - modules/completion/README.md | 21 - modules/completion/external | 1 - modules/completion/init.zsh | 96 ---- modules/custom/README.md | 19 - modules/custom/functions/example_function | 4 - modules/custom/init.zsh | 8 - modules/debug/README.md | 18 - modules/debug/functions/trace-zim | 105 ----- modules/directory/README.md | 16 - modules/directory/init.zsh | 38 -- modules/environment/README.md | 19 - modules/environment/init.zsh | 52 --- modules/fasd/README.md | 14 - modules/fasd/functions/fasd | 424 ------------------ modules/fasd/init.zsh | 88 ---- modules/git-info/README.md | 129 ------ modules/git-info/functions/coalesce | 8 - modules/git-info/functions/git-action | 80 ---- modules/git-info/functions/git-info | 224 --------- modules/git/README.md | 236 ---------- .../functions/_git-branch-delete-interactive | 3 - modules/git/functions/git-branch-current | 2 - .../functions/git-branch-delete-interactive | 14 - modules/git/functions/git-dir | 4 - modules/git/functions/git-ignore-add | 6 - modules/git/functions/git-root | 2 - .../git/functions/git-stash-clear-interactive | 10 - modules/git/functions/git-stash-recover | 8 - modules/git/functions/git-submodule-move | 22 - modules/git/functions/git-submodule-remove | 21 - modules/git/init.zsh | 184 -------- modules/history-substring-search/README.md | 19 - modules/history-substring-search/external | 1 - modules/history-substring-search/init.zsh | 15 - modules/history/README.md | 22 - modules/history/init.zsh | 40 -- modules/input/README.md | 11 - modules/input/init.zsh | 106 ----- modules/pacman/README.md | 61 --- modules/pacman/functions/_pacman_frontend | 3 - modules/pacman/helper_aur.zsh | 20 - modules/pacman/init.zsh | 135 ------ modules/prompt/README.md | 15 - modules/prompt/external-themes/lean | 1 - modules/prompt/external-themes/liquidprompt | 1 - modules/prompt/external-themes/pure | 1 - modules/prompt/functions/async | 1 - modules/prompt/functions/ext-liquidprompt | 1 - modules/prompt/functions/prompt_eriner_setup | 1 - modules/prompt/functions/prompt_gitster_setup | 1 - modules/prompt/functions/prompt_lean_setup | 1 - .../functions/prompt_liquidprompt_setup | 12 - .../prompt/functions/prompt_magicmace_setup | 1 - modules/prompt/functions/prompt_minimal_setup | 1 - modules/prompt/functions/prompt_pure_setup | 1 - modules/prompt/functions/prompt_steeef_setup | 1 - modules/prompt/functions/short_pwd | 10 - modules/prompt/init.zsh | 8 - modules/prompt/themes/eriner.zsh-theme | 140 ------ modules/prompt/themes/gitster.zsh-theme | 40 -- modules/prompt/themes/magicmace.zsh-theme | 72 --- modules/prompt/themes/minimal.zsh-theme | 88 ---- modules/prompt/themes/steeef.zsh-theme | 116 ----- modules/ssh/README.md | 9 - modules/ssh/init.zsh | 34 -- modules/syntax-highlighting/README.md | 21 - modules/syntax-highlighting/external | 1 - modules/syntax-highlighting/init.zsh | 8 - modules/utility/README.md | 40 -- modules/utility/functions/mkcd | 1 - modules/utility/init.zsh | 111 ----- templates/zimrc | 139 +++--- templates/zlogin | 2 +- templates/zshrc | 6 +- tools/clean-compiled.zsh | 11 + tools/clean-dumpfile.zsh | 8 + tools/clean-modules.zsh | 19 + tools/info.zsh | 3 + tools/install.zsh | 18 + tools/modules.zsh | 25 ++ tools/update.zsh | 58 +++ tools/usage.zsh | 13 + tools/zim_build_cache | 7 - tools/zim_clean_cache | 7 - tools/zim_info | 9 - tools/zim_issue | 65 --- tools/zim_remove | 13 - tools/zim_reset | 6 - tools/zim_update | 11 - 101 files changed, 401 insertions(+), 3515 deletions(-) delete mode 100644 .gitmodules mode change 100755 => 100644 init.zsh mode change 100755 => 100644 login_init.zsh delete mode 100644 modules/archive/README.md delete mode 100644 modules/archive/functions/_unarchive delete mode 100644 modules/archive/functions/archive delete mode 100644 modules/archive/functions/unarchive delete mode 100644 modules/archive/init.zsh delete mode 100644 modules/autosuggestions/README.md delete mode 160000 modules/autosuggestions/external delete mode 100644 modules/autosuggestions/init.zsh delete mode 100644 modules/completion/README.md delete mode 160000 modules/completion/external delete mode 100644 modules/completion/init.zsh delete mode 100644 modules/custom/README.md delete mode 100644 modules/custom/functions/example_function delete mode 100644 modules/custom/init.zsh delete mode 100644 modules/debug/README.md delete mode 100644 modules/debug/functions/trace-zim delete mode 100644 modules/directory/README.md delete mode 100644 modules/directory/init.zsh delete mode 100644 modules/environment/README.md delete mode 100644 modules/environment/init.zsh delete mode 100644 modules/fasd/README.md delete mode 100644 modules/fasd/functions/fasd delete mode 100644 modules/fasd/init.zsh delete mode 100644 modules/git-info/README.md delete mode 100644 modules/git-info/functions/coalesce delete mode 100644 modules/git-info/functions/git-action delete mode 100644 modules/git-info/functions/git-info delete mode 100644 modules/git/README.md delete mode 100644 modules/git/functions/_git-branch-delete-interactive delete mode 100644 modules/git/functions/git-branch-current delete mode 100644 modules/git/functions/git-branch-delete-interactive delete mode 100644 modules/git/functions/git-dir delete mode 100644 modules/git/functions/git-ignore-add delete mode 100644 modules/git/functions/git-root delete mode 100644 modules/git/functions/git-stash-clear-interactive delete mode 100644 modules/git/functions/git-stash-recover delete mode 100644 modules/git/functions/git-submodule-move delete mode 100644 modules/git/functions/git-submodule-remove delete mode 100644 modules/git/init.zsh delete mode 100644 modules/history-substring-search/README.md delete mode 160000 modules/history-substring-search/external delete mode 100644 modules/history-substring-search/init.zsh delete mode 100644 modules/history/README.md delete mode 100644 modules/history/init.zsh delete mode 100644 modules/input/README.md delete mode 100644 modules/input/init.zsh delete mode 100644 modules/pacman/README.md delete mode 100644 modules/pacman/functions/_pacman_frontend delete mode 100644 modules/pacman/helper_aur.zsh delete mode 100644 modules/pacman/init.zsh delete mode 100644 modules/prompt/README.md delete mode 160000 modules/prompt/external-themes/lean delete mode 160000 modules/prompt/external-themes/liquidprompt delete mode 160000 modules/prompt/external-themes/pure delete mode 120000 modules/prompt/functions/async delete mode 120000 modules/prompt/functions/ext-liquidprompt delete mode 120000 modules/prompt/functions/prompt_eriner_setup delete mode 120000 modules/prompt/functions/prompt_gitster_setup delete mode 120000 modules/prompt/functions/prompt_lean_setup delete mode 100644 modules/prompt/functions/prompt_liquidprompt_setup delete mode 120000 modules/prompt/functions/prompt_magicmace_setup delete mode 120000 modules/prompt/functions/prompt_minimal_setup delete mode 120000 modules/prompt/functions/prompt_pure_setup delete mode 120000 modules/prompt/functions/prompt_steeef_setup delete mode 100644 modules/prompt/functions/short_pwd delete mode 100644 modules/prompt/init.zsh delete mode 100644 modules/prompt/themes/eriner.zsh-theme delete mode 100644 modules/prompt/themes/gitster.zsh-theme delete mode 100644 modules/prompt/themes/magicmace.zsh-theme delete mode 100644 modules/prompt/themes/minimal.zsh-theme delete mode 100644 modules/prompt/themes/steeef.zsh-theme delete mode 100644 modules/ssh/README.md delete mode 100644 modules/ssh/init.zsh delete mode 100644 modules/syntax-highlighting/README.md delete mode 160000 modules/syntax-highlighting/external delete mode 100644 modules/syntax-highlighting/init.zsh delete mode 100644 modules/utility/README.md delete mode 100644 modules/utility/functions/mkcd delete mode 100644 modules/utility/init.zsh create mode 100644 tools/clean-compiled.zsh create mode 100644 tools/clean-dumpfile.zsh create mode 100644 tools/clean-modules.zsh create mode 100644 tools/info.zsh create mode 100644 tools/install.zsh create mode 100644 tools/modules.zsh create mode 100644 tools/update.zsh create mode 100644 tools/usage.zsh delete mode 100644 tools/zim_build_cache delete mode 100644 tools/zim_clean_cache delete mode 100644 tools/zim_info delete mode 100644 tools/zim_issue delete mode 100644 tools/zim_remove delete mode 100644 tools/zim_reset delete mode 100644 tools/zim_update diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 9b65f59..0000000 --- a/.gitmodules +++ /dev/null @@ -1,28 +0,0 @@ -[submodule "modules/history-substring-search/external"] - path = modules/history-substring-search/external - url = https://github.com/zsh-users/zsh-history-substring-search.git - ignore = untracked -[submodule "modules/completion/external"] - path = modules/completion/external - url = https://github.com/zsh-users/zsh-completions.git - ignore = untracked -[submodule "modules/syntax-highlighting/external"] - path = modules/syntax-highlighting/external - url = https://github.com/zsh-users/zsh-syntax-highlighting.git - ignore = untracked -[submodule "modules/prompt/external-themes/pure"] - path = modules/prompt/external-themes/pure - url = https://github.com/sindresorhus/pure.git - ignore = untracked -[submodule "modules/prompt/external-themes/liquidprompt"] - path = modules/prompt/external-themes/liquidprompt - url = https://github.com/nojhan/liquidprompt.git - ignore = untracked -[submodule "modules/prompt/external-themes/lean"] - path = modules/prompt/external-themes/lean - url = https://github.com/miekg/lean - ignore = untracked -[submodule "modules/autosuggestions/external"] - path = modules/autosuggestions/external - url = https://github.com/zsh-users/zsh-autosuggestions.git - ignore = untracked diff --git a/README.md b/README.md index 2ecafa4..55c9e78 100644 --- a/README.md +++ b/README.md @@ -59,20 +59,92 @@ Installing Zim is easy. If you have a different shell framework installed (like chsh -s =zsh -5. Open a new terminal and finish optimization (this is only needed once, hereafter it will happen upon desktop/tty login): +5. Open a new terminal and install the enabled modules. - source ${ZDOTDIR:-${HOME}}/.zlogin + zimfw install -6. You're done! Enjoy your Zsh IMproved! Take some time to read about the [available modules][modules] and tweak your `.zshrc` file. +6. Finish optimization (this is only needed once, hereafter it will happen upon + desktop/tty login): + + zimfw login-init + +7. You're done! Enjoy your Zsh IMproved! Take some time to read about the + [available modules][modules] and tweak your `.zshrc` file. + +Settings +-------- + +### Enabled modules + +Use the following zstyle to select the modules you would like enabled: + + zstyle ':zim' modules 'first-module' 'second-module' 'third-module' + +You can provide as many module names as you want. Modules are sourced in the +order given. + +By default, a module is installed from the Zim repository with the same name. +For example, the `git` module is installed from https://github.com/zimfw/git if +no additional module configuration is provided. + +### Module customization + +To configure a module, use the following format (where the style name is the +module name): + + zstyle ':zim:module' ['frozen' yes] ['url' ] ['branch' |'tag' ] + +If `frozen` is set to `yes`, then the module will not be cleaned, installed or +updated. + +You can provide a custom `url` with the following equivalent formats: + * `module` + * `zimfw/module` + * `https://github.com/zimfw/module.git` + +If no `branch` or `tag` name is given, then the default is `branch` `master`. + +Choose the module name wisely. The first file found in the module root directory, +in the following order, will be sourced (where `module` is the module name): + 1. `init.zsh` + 2. `module.zsh` + 3. `module.plugin.zsh` + 4. `module.zsh.theme` + 5. `module.sh` + +For example, https://github.com/mafredri/zsh-async must be configured as: + + zstyle ':zim:module' async 'url' 'mafredri/zsh-async' + +because it has a `async.zsh` initialization file, then enabled as `async` in the +`modules` style. + +### Prompt theme + +Prompt themes are enabled in one of two different ways, depending on how the +specific theme you want works: + + 1. If it has a `prompt_module_setup` file (where `module` is the module name): + it is enabled with Zim's `prompt` module. See [the instructions + here](https://github.com/zimfw/prompt/blob/master/README.md#settings). The + advantage of these themes is that you can customize them with additional + parameters. All [Zim themes](https://github.com/zimfw/zimfw/wiki/Themes) + work this way. + 2. If it has one of the initialization files listed above: it is enabled when + it's sourced, not with Zim's `prompt` module. Updating -------- -To update Zim, run: +To update your modules, run: - zmanage update + zimfw update -For more information about the `zmanage` tool, run `zmanage help`. +To upgrade Zim, run: + + zimfw upgrade + +For more information about the `zimfw` tool, run `zimfw` with no parameters. Uninstalling ------------ @@ -80,17 +152,6 @@ Uninstalling The best way to remove Zim is to manually delete `~/.zim`, `~/.zimrc`, and remove the initialization lines from your `~/.zshrc` and `~/.zlogin`. -However, there are some **experimental** convenience functions to remove Zim: - -**NOTE: This functionality is experimental!** - -To remove Zim, run: - - zmanage remove - -**NOTE: This functionality is experimental!** - - [fish_shell]: https://i.eriner.me/zim_history-substring-search.gif [syntax_highlighting]: https://i.eriner.me/zim_syntax-highlighting.gif [speed]: https://github.com/zimfw/zimfw/wiki/Speed diff --git a/init.zsh b/init.zsh old mode 100755 new mode 100644 index 3de17fd..43583ce --- a/init.zsh +++ b/init.zsh @@ -1,51 +1,50 @@ -# -# Zim initializition -# - autoload -Uz is-at-least && if ! is-at-least 5.2; then - print "ERROR: Zim didn't start. You're using zsh version ${ZSH_VERSION}, and versions < 5.2 are not supported. Update your zsh." >&2 + print "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." >&2 return 1 fi -# Define zim location -(( ! ${+ZIM_HOME} )) && export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim +# Define Zim location +: ${ZIM_HOME=${0:h}} # Source user configuration -[[ -s ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc +[[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc # Set input mode before loading modules -if [[ ${zinput_mode} == 'vi' ]]; then +if zstyle -t ':zim:input' mode 'vi'; then bindkey -v else bindkey -e fi -# Autoload module functions +# Autoload enabled modules' functions () { - local mod_function + local zfunction + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + setopt LOCAL_OPTIONS EXTENDED_GLOB - - # autoload searches fpath for function locations; add enabled module function paths fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath}) - - for mod_function in ${ZIM_HOME}/modules/${^zmodules}/functions/^(_*|prompt_*_setup|*.*)(-.N:t); do - autoload -Uz ${mod_function} + for zfunction in ${ZIM_HOME}/modules/${^zmodules}/functions/^(_*|*.*|prompt_*_setup)(-.N:t); do + autoload -Uz ${zfunction} done } -# Initialize modules +# Source enabled modules' init scripts () { - local zmodule zmodule_dir zmodule_file + local zmodule zdir zfile + local -a zmodules + zstyle -a ':zim' modules 'zmodules' for zmodule in ${zmodules}; do - zmodule_dir=${ZIM_HOME}/modules/${zmodule} - if [[ ! -d ${zmodule_dir} ]]; then - print "No such module \"${zmodule}\"." >&2 + zdir=${ZIM_HOME}/modules/${zmodule} + if [[ ! -d ${zdir} ]]; then + print "init: module ${zmodule} not installed" >&2 + elif [[ -f ${zdir}/prompt_${zmodule}_setup ]]; then + fpath=(${zdir} ${fpath}) # Will be loaded by promptinit else - for zmodule_file in ${zmodule_dir}/init.zsh \ - ${zmodule_dir}/{,zsh-}${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}; do - if [[ -f ${zmodule_file} ]]; then - source ${zmodule_file} + for zfile in ${zdir}/init.zsh ${zdir}/${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}; do + if [[ -f ${zfile} ]]; then + source ${zfile} break fi done @@ -53,42 +52,71 @@ fi done } -zmanage() { - local usage="zmanage [action] -Actions: - update Fetch and merge upstream zim commits if possible - info Print zim and system info - issue Create a template for reporting an issue - clean-cache Clean the zim cache - build-cache Rebuild the zim cache - remove *experimental* Remove zim as best we can - reset Reset zim to the latest commit - debug Invoke the trace-zim script which produces logs - help Print this usage message" +_zimfw_compile() { + setopt LOCAL_OPTIONS EXTENDED_GLOB + autoload -U zrecompile - if (( ${#} != 1 )); then - print ${usage} + local zdir zfile + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + # Compile the completion cache; significant speedup + local zdumpfile + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" + [[ -f ${zdumpfile} ]] && zrecompile -p ${1} ${zdumpfile} + + # Compile .zshrc + zrecompile -p ${1} ${ZDOTDIR:-${HOME}}/.zshrc + + # Compile enabled modules' autoloaded functions + for zdir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do + zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(_*|*.*|prompt_*_setup)(-.N) + done + + # Compile enabled modules' scripts + for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#{*.zsh{,-theme},prompt_*_setup}(.NLk+1); do + zrecompile -p ${1} ${zfile} + done + + # Compile this script + zrecompile -p ${1} ${ZIM_HOME}/init.zsh + + if [[ ${1} != -q ]]; then + print -P '%F{green}✓%f Done with compile.' + fi +} + +zimfw() { + if [[ ${#} -ne 1 && ${2} != -q ]]; then + source ${ZIM_HOME}/tools/usage.zsh return 1 fi case ${1} in - update) zsh ${ZIM_HOME}/tools/zim_update - ;; - info) zsh ${ZIM_HOME}/tools/zim_info - ;; - issue) zsh ${ZIM_HOME}/tools/zim_issue - ;; - clean-cache) source ${ZIM_HOME}/tools/zim_clean_cache && print 'Cache cleaned' - ;; - build-cache) source ${ZIM_HOME}/tools/zim_build_cache && print 'Cache rebuilt' - ;; - remove) zsh ${ZIM_HOME}/tools/zim_remove - ;; - reset) zsh ${ZIM_HOME}/tools/zim_reset - ;; - debug) zsh ${ZIM_HOME}/modules/debug/functions/trace-zim - ;; - *) print ${usage}; return 1 - ;; + clean) + source ${ZIM_HOME}/tools/clean-modules.zsh ${2} && \ + source ${ZIM_HOME}/tools/clean-compiled.zsh ${2} && \ + source ${ZIM_HOME}/tools/clean-dumpfile.zsh ${2} + ;; + clean-modules) source ${ZIM_HOME}/tools/clean-modules.zsh ${2} ;; + clean-compiled) source ${ZIM_HOME}/tools/clean-compiled.zsh ${2} ;; + clean-dumpfile) source ${ZIM_HOME}/tools/clean-dumpfile.zsh ${2} ;; + compile|login-init) _zimfw_compile ${2} ;; + info) source ${ZIM_HOME}/tools/info.zsh ${2} ;; + install|update) + # Source .zimrc to refresh zmodules + [[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc + source ${ZIM_HOME}/tools/modules.zsh ${2} | xargs -L1 -P10 zsh ${ZIM_HOME}/tools/${1}.zsh && \ + if [[ ${2} != -q ]]; then + print -P "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + fi + ;; + upgrade) + zsh ${ZIM_HOME}/tools/update.zsh 'https://github.com/zimfw/zimfw.git' ${ZIM_HOME} branch develop ${2} + ;; + *) + source ${ZIM_HOME}/tools/usage.zsh + return 1 + ;; esac } diff --git a/login_init.zsh b/login_init.zsh old mode 100755 new mode 100644 index 0b98bb4..5f3d1f6 --- a/login_init.zsh +++ b/login_init.zsh @@ -1,33 +1 @@ -# -# startup file read in interactive login shells -# -# The following code helps us by optimizing the existing framework. -# This includes zcompile, zcompdump, etc. -# - -( - local dir file - setopt LOCAL_OPTIONS EXTENDED_GLOB - autoload -U zrecompile - - # zcompile the completion cache; siginificant speedup - zrecompile -pq ${ZDOTDIR:-${HOME}}/${zcompdump_file:-.zcompdump} - - # zcompile .zshrc - zrecompile -pq ${ZDOTDIR:-${HOME}}/.zshrc - - # zcompile enabled module autoloaded functions - for dir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do - zrecompile -pq ${dir}.zwc ${dir}/^(_*|prompt_*_setup|*.*)(-.N) - done - - # zcompile enabled module scripts - for file in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do - zrecompile -pq ${file} - done - - # zcompile all prompt setup scripts - for file in ${ZIM_HOME}/modules/prompt/functions/prompt_*_setup; do - zrecompile -pq ${file} - done -) &! +zimfw login-init -q &! diff --git a/modules/archive/README.md b/modules/archive/README.md deleted file mode 100644 index d15080a..0000000 --- a/modules/archive/README.md +++ /dev/null @@ -1,31 +0,0 @@ -archive -======= - -Provides `archive` and `unarchive` functions for easy archive manipulation. - -This module will make use of `pigz` and `pbzip2` if available to make use of all available CPU cores. - -Functions ---------- - - * `archive` generates an archive based on file extension. Syntax is `archive myarchive.tar.gz /path/to/archive` - * `unarchive` unarchives files based on the extensions. Syntax is `unarchive myarchive.7z` - -Archive formats ---------------- - -| Format | Requirements | -| ------ | ------------ | -| .tar | `tar` | -| .tar.gz, .tgz | `tar` or `pigz` | -| .tar.bz, .tar.bz2, .tbz, .tbz2 | `tar` or `pbzip2` | -| .tar.xz, .txz | `tar` with xz support | -| .tar.zma, .tlz | `tar` with lzma support | -| .gz | `gunzip` or `pigz` | -| .bz, .bz2 | `bunzip2` or `pbzip2` | -| .xz | `unxz` | -| .lzma | `unzlma` | -| .Z | `uncompress` | -| .zip | `unzip` | -| .rar | `unrar` or `rar` | -| .7z | `7za` | diff --git a/modules/archive/functions/_unarchive b/modules/archive/functions/_unarchive deleted file mode 100644 index b188308..0000000 --- a/modules/archive/functions/_unarchive +++ /dev/null @@ -1,4 +0,0 @@ -#compdef unarchive - -_arguments \ - "*:archive:_files -g '(#i)*.(tar|gz|tgz|bz|bz2|tbz|tbz2|xz|txz|tlz|lzma|Z|zip|rar|7z|001)(-.)'" diff --git a/modules/archive/functions/archive b/modules/archive/functions/archive deleted file mode 100644 index e2225b5..0000000 --- a/modules/archive/functions/archive +++ /dev/null @@ -1,34 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# -# Creates archive files -# - -if (( # < 2 )); then - print "usage: ${0} ..." >&2 - return 1 -fi - -# we are quitting (above) if there are less than 2 vars, -# so we don't need any argc check here. - -local archive_name="${1}" -shift - -# pigz and pbzip2 are aliased in the init.zsh file. This provides a significant speedup, resulting in a -# near-liner decrease in compression time based on on the number of available cores. - -case "${archive_name}" in - (*.tar.gz|*.tgz) tar -cvzf "${archive_name}" "${@}" ;; - (*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -cvjf "${archive_name}" "${@}" ;; - (*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -cvJf "${archive_name}" "${@}" ;; - (*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -cvf "${archive_name}" "${@}" ;; - (*.tar) tar -cvf "${archive_name}" "${@}" ;; - (*.zip) zip -r "${archive_name}" "${@}" ;; - (*.rar) rar a "${archive_name}" "${@}" ;; - (*.7z) 7za a "${archive_name}" "${@}" ;; - (*.gz) print "${0}: .gz is only useful for single files, and does not capture permissions. Use .tar.gz" ;; - (*.bz|*.bz2) print "${0}: .bzip2 is only useful for single files, and does not capture permissions. Use .tar.bz2" ;; - (*.xz) print "${0}: .xz is only useful for single files, and does not capture permissions. Use .tar.xz" ;; - (*.lzma) print "${0}: .lzma is only useful for single files, and does not capture permissions. Use .tar.lzma" ;; - (*) print "${0}: unknown archive type: ${archive_name}" ;; -esac diff --git a/modules/archive/functions/unarchive b/modules/archive/functions/unarchive deleted file mode 100644 index 4f10967..0000000 --- a/modules/archive/functions/unarchive +++ /dev/null @@ -1,41 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# -# Unarchives files -# - -if (( # < 1 )); then - print "usage: ${0} ..." >&2 - return 1 -fi - -setopt LOCAL_OPTIONS ERR_RETURN - -# using unpigz/pbunzip2 provides little to decompression time; the benefit is mainly in compression time. -# setting it as an alias in the init.zsh file should be sufficient here. - -while (( # > 0 )); do - local archive_name="${1}" - case "${archive_name}" in - (*.tar.gz|*.tgz) tar -xvzf "${archive_name}" ;; - (*.tar.bz|*.tar.bz2|*.tbz|*.tbz2) tar -xvjf "${archive_name}" ;; - (*.tar.xz|*.txz) tar -J --help &>/dev/null && tar -xvJf "${archive_name}" \ - || xzcat "${archive_name}" | tar xvf - ;; - (*.tar.lzma|*.tlz) tar --lzma --help &>/dev/null && tar --lzma -xvf "${archive_name}" \ - || lzcat "${archive_name}" | tar xvf - ;; - (*.tar) tar xvf "${archive_name}" ;; - (*.gz) gunzip "${archive_name}" ;; - (*.bz|*.bz2) bunzip2 "${archive_name}" ;; - (*.xz) unxz "${archive_name}" ;; - (*.lzma) unlzma "${archive_name}" ;; - (*.Z) uncompress "${archive_name}" ;; - (*.zip) unzip "${archive_name}";; - (*.rar) (( $+{commands[unrar]} )) && unrar x -ad "${archive_name}" \ - || rar x -ad "${archive_name}" ;; - (*.7z|*.001) 7za x "${archive_name}" ;; - (*) - print "${0}: unknown archive type: ${archive_name}" - return 1 - ;; - esac - shift -done diff --git a/modules/archive/init.zsh b/modules/archive/init.zsh deleted file mode 100644 index d3c43fd..0000000 --- a/modules/archive/init.zsh +++ /dev/null @@ -1,17 +0,0 @@ -# -# Archive aliases -# - -# if pigz/pbzip2 are available, alias them as they are drop-in replacements for gzip and bzip2, respectively. - -# -# pigz -# -(( ${+commands[pigz]} )) && alias gzip='pigz' -(( ${+commands[unpigz]} )) && alias gunzip='unpigz' - -# -# pbzip2 -# -(( ${+commands[pbzip2]} )) && alias bzip2='pbzip2' -(( ${+commands[pbunzip2]} )) && alias bunzip2='pbunzip2' diff --git a/modules/autosuggestions/README.md b/modules/autosuggestions/README.md deleted file mode 100644 index 02cbc31..0000000 --- a/modules/autosuggestions/README.md +++ /dev/null @@ -1,13 +0,0 @@ -zsh-autosuggestions -=================== - -_[Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for Zsh._ - -It suggests commands as you type, based on command history. - - - -Contributing ------------- - -Contributions should be submitted [upstream to zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions) diff --git a/modules/autosuggestions/external b/modules/autosuggestions/external deleted file mode 160000 index a7f0106..0000000 --- a/modules/autosuggestions/external +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a7f0106b31c2538a36cab30428e6ca65d9a2ae60 diff --git a/modules/autosuggestions/init.zsh b/modules/autosuggestions/init.zsh deleted file mode 100644 index e6407e7..0000000 --- a/modules/autosuggestions/init.zsh +++ /dev/null @@ -1,9 +0,0 @@ -# -# Fish-like fast/unobtrusive autosuggestions for zsh. -# -# It suggests commands as you type, based on command history. -# - -# source script -source ${0:h}/external/zsh-autosuggestions.zsh || return 1 - diff --git a/modules/completion/README.md b/modules/completion/README.md deleted file mode 100644 index 7024fd3..0000000 --- a/modules/completion/README.md +++ /dev/null @@ -1,21 +0,0 @@ -completion -========== - -Enables and configures smart and extensive tab completion. - -Completions are sourced from [zsh-completions][zsh-completions]. - -Zsh options ------------ - - * `ALWAYS_TO_END` moves cursor to end of word if a full completion is inserted. - * `PATH_DIRS` performs path search even on command names with slashes in them. - * `NO_CASE_GLOB` makes globbing case insensitive. - * `NO_LIST_BEEP` doesn't beep on ambiguous completions. - -Contributing ------------- - -Command completions should be submitted [upstream to zsh-completions][zsh-completions]. - -[zsh-completions]: https://github.com/zsh-users/zsh-completions diff --git a/modules/completion/external b/modules/completion/external deleted file mode 160000 index 8ec8c8c..0000000 --- a/modules/completion/external +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8ec8c8c5c662c3cb77231b7458ce1975d2f8c967 diff --git a/modules/completion/init.zsh b/modules/completion/init.zsh deleted file mode 100644 index 437c9a6..0000000 --- a/modules/completion/init.zsh +++ /dev/null @@ -1,96 +0,0 @@ -# -# Completion enhancements -# - - -# -# initialization -# - -# if it's a dumb terminal, return. -if [[ ${TERM} == 'dumb' ]]; then - return 1 -fi - -# add the completions to the fpath -fpath=(${0:h}/external/src ${fpath}) - -# load and initialize the completion system -autoload -Uz compinit && compinit -C -d "${ZDOTDIR:-${HOME}}/${zcompdump_file:-.zcompdump}" - - -# -# zsh options -# - -# If a completion is performed with the cursor within a word, and a full -# completion is inserted, the cursor is moved to the end of the word. -setopt ALWAYS_TO_END - -# Perform a path search even on command names with slashes in them. -setopt PATH_DIRS - -# Make globbing (filename generation) not sensitive to case. -setopt NO_CASE_GLOB - -# Don't beep on an ambiguous completion. -setopt NO_LIST_BEEP - - -# -# completion module options -# - -# group matches and describe. -zstyle ':completion:*:*:*:*:*' menu select -zstyle ':completion:*:matches' group yes -zstyle ':completion:*:options' description yes -zstyle ':completion:*:options' auto-description '%d' -zstyle ':completion:*:corrections' format '%F{green}-- %d (errors: %e) --%f' -zstyle ':completion:*:descriptions' format '%F{yellow}-- %d --%f' -zstyle ':completion:*:messages' format '%F{purple}-- %d --%f' -zstyle ':completion:*:warnings' format '%F{red}-- no matches found --%f' -zstyle ':completion:*' format '%F{yellow}-- %d --%f' -zstyle ':completion:*' group-name '' -zstyle ':completion:*' verbose yes -zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' '+r:|?=**' - -# directories -if (( ! ${+LS_COLORS} )); then - # Locally use same LS_COLORS definition from utility module, in case it was not set - local LS_COLORS='di=1;34:ln=35:so=32:pi=33:ex=31:bd=1;36:cd=1;33:su=30;41:sg=30;46:tw=30;42:ow=30;43' -fi -zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} -zstyle ':completion:*:*:cd:*' tag-order local-directories directory-stack path-directories -zstyle ':completion:*:*:cd:*:directory-stack' menu yes select -zstyle ':completion:*:-tilde-:*' group-order 'named-directories' 'path-directories' 'expand' -zstyle ':completion:*' squeeze-slashes true - -# enable caching -zstyle ':completion::complete:*' use-cache on -zstyle ':completion::complete:*' cache-path "${ZDOTDIR:-${HOME}}/.zcompcache" - -# ignore useless commands and functions -zstyle ':completion:*:functions' ignored-patterns '(_*|pre(cmd|exec)|prompt_*)' - -# completion sorting -zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters - -# Man -zstyle ':completion:*:manuals' separate-sections true -zstyle ':completion:*:manuals.(^1*)' insert-sections true - -# history -zstyle ':completion:*:history-words' stop yes -zstyle ':completion:*:history-words' remove-all-dups yes -zstyle ':completion:*:history-words' list false -zstyle ':completion:*:history-words' menu yes - -# ignore multiple entries. -zstyle ':completion:*:(rm|kill|diff):*' ignore-line other -zstyle ':completion:*:rm:*' file-patterns '*:all-files' - -# If the _my_hosts function is defined, it will be called to add the ssh hosts -# completion, otherwise _ssh_hosts will fall through and read the ~/.ssh/config -zstyle -e ':completion:*:*:ssh:*:my-accounts' users-hosts \ - '[[ -f ${HOME}/.ssh/config && ${key} == hosts ]] && key=my_hosts reply=()' diff --git a/modules/custom/README.md b/modules/custom/README.md deleted file mode 100644 index 5ba0d61..0000000 --- a/modules/custom/README.md +++ /dev/null @@ -1,19 +0,0 @@ -custom -====== - -Add any custom aliases/settings to the `init.zsh` file. - -Any functions should go in the `functions` subdirectory, where the name of the -file is the name of the function. - -For example, this function from your `.zshrc`: -```zsh -foo() { - print 'bar' -} -``` - -becomes a file named `foo` in the `functions` subdirectory containing: -```zsh -print 'bar' -``` diff --git a/modules/custom/functions/example_function b/modules/custom/functions/example_function deleted file mode 100644 index fc78a6f..0000000 --- a/modules/custom/functions/example_function +++ /dev/null @@ -1,4 +0,0 @@ -# this is an example function -# running 'example_function' in a zsh session will execute the code below - -print "executed example function: ${ZIM_HOME}/modules/custom/functions/example_function!" diff --git a/modules/custom/init.zsh b/modules/custom/init.zsh deleted file mode 100644 index 57934ad..0000000 --- a/modules/custom/init.zsh +++ /dev/null @@ -1,8 +0,0 @@ -# -# Custom aliases/settings -# - -# any custom stuff should go here. -# ensure that 'custom' exists in the zmodules array in your .zimrc - - diff --git a/modules/debug/README.md b/modules/debug/README.md deleted file mode 100644 index 8f7c152..0000000 --- a/modules/debug/README.md +++ /dev/null @@ -1,18 +0,0 @@ -debug -===== - -Provides a function to debug Zim. - -Functions ---------- - - * `trace-zim` provides a trace of Zsh/Zim startup - -Notes ------ - -`trace-zim` will not alter your current dotfiles. It will copy your environment -to a temporary directory, launch Zsh within that environment, and output logs. - -This will provide a `ztrace.tar.gz` archive, which should be attached to any bug -reports if you need help with an issue that you don't understand. diff --git a/modules/debug/functions/trace-zim b/modules/debug/functions/trace-zim deleted file mode 100644 index 65d3dee..0000000 --- a/modules/debug/functions/trace-zim +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env zsh -# -# Generates trace log to debug zim and zsh issues -# - -print "This function creates a trace log to debug -Zsh and Zim functionality. - -It will copy your .zshrc to /tmp/ztrace/, ammend profiling -code, launch a new shell, log the trace, close the shell, -archive the logs, and finally print the path to the archive." - -read \?"Press [Enter] to begin trace." - -mkdir -p /tmp/ztrace -# make sure that we were able to create the directory -if [[ ! -d /tmp/ztrace ]]; then - print 'failed to create /tmp/ztrace directory. Aborting.' - return 1 -else - # check if known output file, if exists - # rm all directory contents - if [[ -e /tmp/ztrace/ztrace.log ]]; then - print "\nLogs from previous run of trace-zim are present -Deleting old logs now..." - # use of anonymous function for dotglob opt - () { - setopt dotglob - rm -rf /tmp/ztrace/* - } - fi -fi - -# get some basic system information (kernel and zsh version) -print "Zsh version: - $(zsh --version) -Kernel information: - $(uname -a) -fpath info: - ${fpath}" >! /tmp/ztrace/sysinfo - -cp ${ZDOTDIR:-${HOME}}/.zshrc /tmp/ztrace/.zshrc.orig -cp ${ZDOTDIR:-${HOME}}/.zimrc /tmp/ztrace/.zimrc -# rsync will allow us to not have to copy the .git folder; use if available -if (( ${+commands[rsync]} )); then - rsync -az --exclude .git ${ZIM_HOME} /tmp/ztrace/ -else - cp -R ${ZIM_HOME} /tmp/ztrace/ -fi - -# create a modified .zshrc to produce a trace log -cat <! /tmp/ztrace/.zshrc -################### -# zim trace start # -################### -PS4=$'%D{%s%6.}-_-' -exec 3>&2 2>/tmp/ztrace/sample-time.$$.log -zmodload zsh/zprof -setopt xtrace prompt_subst -EOF - -cat /tmp/ztrace/.zshrc.orig >>! /tmp/ztrace/.zshrc - -cat <>! /tmp/ztrace/.zshrc -################# -# zim trace end # -################# - -unsetopt xtrace -zprof >! /tmp/ztrace/zprof -#non-linux systems have weird fd; also, no real need to redirect back -#prompt is (practically speaking) non-interactive, fd exists only for that process -#which is closed (by typing exit) - -#exec 2>&3 3>&- -EOF - -print "\nSpawning zsh and producing trace...\n\n" -ZDOTDIR=/tmp/ztrace zsh -ic 'exit' -print "Trace complete. -Parsing logs to a nicer format; this may take some time..." - -# this is ugly thing makes it pretty... -while read line; do if [[ ${line} =~ '^[0-9]+-_-' ]]; then crt=000000$((${line%%-_-*}-10#0$last)); printf "%12.9f %s\n" ${crt:0:${#crt}-6}.${crt:${#crt}-6} ${line#*-_-}; last=${line%%-_-*}; fi; done < /tmp/ztrace/sample-time.(*).log > /tmp/ztrace/ztrace.log -print "Parsing complete!" - -# safe to remove old, unneeded environment files -print "Tidying up before archive..." -rm -f /tmp/ztrace/sample-time.* -rm -rf /tmp/ztrace/.zim -rm -f /tmp/ztrace/.zshrc -mv /tmp/ztrace/.zshrc.orig /tmp/ztrace/.zshrc -rm -f /tmp/ztrace/.zhistory -rm -f /tmp/ztrace/.zcompdump* - -print "Archiving trace logs...\n" - -tar -czf /tmp/ztrace.tar.gz /tmp/ztrace/ - -print "Archive complete!\n -Trace by with execution time available at: - /tmp/ztrace/ztrace.log -Archive (for sharing/help) available at: - /tmp/ztrace.tar.gz" - diff --git a/modules/directory/README.md b/modules/directory/README.md deleted file mode 100644 index 93f9d0a..0000000 --- a/modules/directory/README.md +++ /dev/null @@ -1,16 +0,0 @@ -directory -========= - -Sets directory, navigation, and redirect options. - -Zsh options ------------ - - * `AUTO_CD` performs cd to a directory if the typed command is invalid, but is a directory. - * `AUTO_PUSHD` makes cd push the old directory to the directory stack. - * `PUSHD_IGNORE_DUPS` does not push multiple copies of the same directory to the stack. - * `PUSHD_SILENT` does not print the directory stack after pushd or popd. - * `PUSHD_TO_HOME` has pushd without arguments act like `pushd ${HOME}`. - * `EXTENDED_GLOB` treats `#`, `~`, and `^` as patterns for filename globbing. - * `MULTIOS` performs implicit tees or cats when using multiple redirections. - * `NO_CLOBBER` disallows `>` to overwrite existing files. Use `>|` or `>!` instead. diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh deleted file mode 100644 index 60e332d..0000000 --- a/modules/directory/init.zsh +++ /dev/null @@ -1,38 +0,0 @@ -# -# Directory navigation options -# - -# -# Navigation -# - -# If a command is issued that can’t be executed as a normal command, -# and the command is the name of a directory, perform the cd command to that directory. -setopt AUTO_CD - -# Make cd push the old directory onto the directory stack. -setopt AUTO_PUSHD - -# Don’t push multiple copies of the same directory onto the directory stack. -setopt PUSHD_IGNORE_DUPS - -# Do not print the directory stack after pushd or popd. -setopt PUSHD_SILENT - -# Have pushd with no arguments act like ‘pushd ${HOME}’. -setopt PUSHD_TO_HOME - -# -# Globbing and fds -# - -# Treat the ‘#’, ‘~’ and ‘^’ characters as part of patterns for filename generation, etc. -# (An initial unquoted ‘~’ always produces named directory expansion.) -setopt EXTENDED_GLOB - -# Perform implicit tees or cats when multiple redirections are attempted. -setopt MULTIOS - -# Disallow ‘>’ redirection to overwrite existing files. -# ‘>|’ or ‘>!’ must be used to overwrite a file. -setopt NO_CLOBBER diff --git a/modules/environment/README.md b/modules/environment/README.md deleted file mode 100644 index 7a1cb02..0000000 --- a/modules/environment/README.md +++ /dev/null @@ -1,19 +0,0 @@ -environment -=========== - -Sets generic Zsh built-in environment options. - -Also enables smart URL-pasting. This prevents the user from having to manually escape URLs. - -Uses `.zimrc` defined `${ztermtitle}` variable to set the terminal title, if defined. - -Zsh options ------------ - - * `AUTO_RESUME` resumes an existing job before creating a new one. - * `INTERACTIVE_COMMENTS` allows comments starting with `#` in the shell. - * `LONG_LIST_JOBS` lists jobs in verbose format by default. - * `NOTIFY` reports job status immediately instead of waiting for the prompt. - * `NO_BG_NICE` prevents background jobs being given a lower priority. - * `NO_CHECK_JOBS` prevents status report of jobs on shell exit. - * `NO_HUP` prevents SIGHUP to jobs on shell exit. diff --git a/modules/environment/init.zsh b/modules/environment/init.zsh deleted file mode 100644 index 31ff079..0000000 --- a/modules/environment/init.zsh +++ /dev/null @@ -1,52 +0,0 @@ -# -# generic options and environment settings -# - -# Use smart URL pasting and escaping. -autoload -Uz bracketed-paste-url-magic && zle -N bracketed-paste bracketed-paste-url-magic -autoload -Uz url-quote-magic && zle -N self-insert url-quote-magic - -# Treat single word simple commands without redirection as candidates for resumption of an existing job. -setopt AUTO_RESUME - -# Allow comments starting with `#` even in interactive shells. -setopt INTERACTIVE_COMMENTS - -# List jobs in the long format by default. -setopt LONG_LIST_JOBS - -# Report the status of background jobs immediately, rather than waiting until just before printing a prompt. -setopt NOTIFY - -# Prevent runing all background jobs at a lower priority. -setopt NO_BG_NICE - -# Prevent reporting the status of background and suspended jobs before exiting a shell with job control. -# NO_CHECK_JOBS is best used only in combination with NO_HUP, else such jobs will be killed automatically. -setopt NO_CHECK_JOBS - -# Prevent sending the HUP signal to running jobs when the shell exits. -setopt NO_HUP - -# Remove path separtor from WORDCHARS. -WORDCHARS=${WORDCHARS//[\/]} - -# Set less or more as the default pager. -if (( ! ${+PAGER} )); then - if (( ${+commands[less]} )); then - export PAGER=less - else - export PAGER=more - fi -fi - -# sets the window title and updates upon directory change -# more work probably needs to be done here to support multiplexers -if (( ${+ztermtitle} )); then - case ${TERM} in - xterm*|*rxvt) - precmd() { print -Pn "\e]0;${ztermtitle}\a" } - precmd # we execute it once to initialize the window title - ;; - esac -fi diff --git a/modules/fasd/README.md b/modules/fasd/README.md deleted file mode 100644 index 2d85197..0000000 --- a/modules/fasd/README.md +++ /dev/null @@ -1,14 +0,0 @@ -fasd -==== - -[Fasd](https://github.com/clvv/fasd) (pronounced similar to "fast") is a command-line productivity booster. -Fasd offers quick access to files and directories for POSIX shells. It is -inspired by tools like [autojump](https://github.com/joelthelion/autojump), -[z](http://github.com/rupa/z) and [v](https://github.com/rupa/v). Fasd keeps -track of files and directories you have accessed, so that you can quickly -reference them in the command line. - -Contributing ------------- - -Contributions should be submitted [upstream to fasd](https://github.com/clvv/fasd). diff --git a/modules/fasd/functions/fasd b/modules/fasd/functions/fasd deleted file mode 100644 index 6319df1..0000000 --- a/modules/fasd/functions/fasd +++ /dev/null @@ -1,424 +0,0 @@ -# Fasd is originally written based on code from z (https://github.com/rupa/z) -# by rupa deadwyler under the WTFPL license. Most if not all of the code has -# been rewritten. - -# Copyright (C) 2011, 2012 by Wei Dai. All rights reserved. -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -# make zsh do word splitting inside this function -[ "$ZSH_VERSION" ] && emulate sh && setopt localoptions - -case $1 in ---init) shift - while [ "$1" ]; do - case $1 in - env) - { # Load configuration files - - if [[ -s ${XDG_CONFIG_HOME:-"${HOME}/.config"}/fasd/config ]]; then - source ${XDG_CONFIG_HOME:-"${HOME}/.config"}/fasd/config - else - [[ -s /etc/fasdrc ]] && source /etc/fasd - [[ -s ${HOME}/.fasdrc ]] && source ${HOME}/.fasdrc - fi - - # set default options - (( ! ${+_FASD_DATA} )) && _FASD_DATA="$HOME/.fasd" - (( ! ${+_FASD_BLACKLIST} )) && _FASD_BLACKLIST="--help" - (( ! ${+_FASD_SHIFT} )) && _FASD_SHIFT="sudo busybox" - (( ! ${+_FASD_IGNORE} )) && _FASD_IGNORE="fasd ls echo" - (( ! ${+_FASD_SINK} )) && _FASD_SINK=/dev/null - (( ! ${+_FASD_TRACK_PWD} )) && _FASD_TRACK_PWD=1 - (( ! ${+_FASD_MAX} )) && _FASD_MAX=2000 - (( ! ${+_FASD_BACKENDS} )) && _FASD_BACKENDS=native - (( ! ${+_FASD_FUZZY} )) && _FASD_FUZZY=2 - (( ! ${+_FASD_VIMINFO} )) && _FASD_VIMINFO="$HOME/.viminfo" - (( ! ${+_FASD_RECENTLY_USED_XBEL} )) && \ - _FASD_RECENTLY_USED_XBEL="$HOME/.local/share/recently-used.xbel" - - if (( ! ${+_FASD_AWK} )); then - # awk preferences - local awk; for awk in mawk gawk original-awk nawk awk; do - $awk "" && _FASD_AWK=$awk && break - done - fi - } >> ${_FASD_SINK:-/dev/null} 2>&1 - ;; - esac; shift - done - ;; - -# if "$_fasd_cur" or "$2" is a query, then output shell code to be eval'd ---word-complete-trigger) - shift; [ "$2" ] && local _fasd_cur="$2" || return - case $_fasd_cur in - ,*) printf %s\\n "$1 e $_fasd_cur";; - f,*) printf %s\\n "$1 f ${_fasd_cur#?}";; - d,*) printf %s\\n "$1 d ${_fasd_cur#?}";; - *,,) printf %s\\n "$1 e $_fasd_cur";; - *,,f) printf %s\\n "$1 f ${_fasd_cur%?}";; - *,,d) printf %s\\n "$1 d ${_fasd_cur%?}";; - esac - ;; - ---sanitize) shift; printf %s\\n "$*" | \ - sed 's/\([^\]\)$( *[^ ]* *\([^)]*\)))*/\1\2/g - s/\([^\]\)[|&;<>$`{}]\{1,\}/\1 /g' - ;; - ---proc) shift # process commands - # stop if we don't own $_FASD_DATA or $_FASD_RO is set - [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return - - # blacklists - local each; for each in $_FASD_BLACKLIST; do - case " $* " in *\ $each\ *) return;; esac - done - - # shifts - while true; do - case " $_FASD_SHIFT " in - *\ $1\ *) shift;; - *) break;; - esac - done - - # ignores - case " $_FASD_IGNORE " in - *\ $1\ *) return;; - esac - - shift; fasd --add "$@" # add all arguments except command - ;; - ---add|-A) shift # add entries - # stop if we don't own $_FASD_DATA or $_FASD_RO is set - [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return - - # find all valid path arguments, convert them to simplest absolute form - local paths="$(while [ "$1" ]; do - [ -e "$1" ] && printf %s\\n "$1"; shift - done | sed '/^[^/]/s@^@'"$PWD"'/@ - s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 - s@[^/][^/]*//*\.\./@/@;t 0 - s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@;s@^$@/@' 2>> "$_FASD_SINK" \ - | tr '\n' '|')" - - # add current pwd if the option is set - [ "$_FASD_TRACK_PWD" = "1" -a "$PWD" != "$HOME" ] && paths="$paths|$PWD" - - [ -z "${paths##\|}" ] && return # stop if we have nothing to add - - # maintain the file - local tempfile - tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return - $_FASD_AWK -v list="$paths" -v now="$(date +%s)" -v max="$_FASD_MAX" -F"|" ' - BEGIN { - split(list, files, "|") - for(i in files) { - path = files[i] - if(path == "") continue - paths[path] = path # array for checking - rank[path] = 1 - time[path] = now - } - } - $2 >= 1 { - if($1 in paths) { - rank[$1] = $2 + 1 / $2 - time[$1] = now - } else { - rank[$1] = $2 - time[$1] = $3 - } - count += $2 - } - END { - if(count > max) - for(i in rank) print i "|" 0.9*rank[i] "|" time[i] # aging - else - for(i in rank) print i "|" rank[i] "|" time[i] - }' "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" - if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then - env rm -f "$tempfile" - else - env mv -f "$tempfile" "$_FASD_DATA" - fi - ;; - ---delete|-D) shift # delete entries - # stop if we don't own $_FASD_DATA or $_FASD_RO is set - [ -f "$_FASD_DATA" -a ! -O "$_FASD_DATA" ] || [ "$_FASD_RO" ] && return - - # turn valid arguments into entry-deleting sed commands - local sed_cmd="$(while [ "$1" ]; do printf %s\\n "$1"; shift; done | \ - sed '/^[^/]/s@^@'"$PWD"'/@;s@/\.\.$@/../@;s@/\(\./\)\{1,\}@/@g;:0 - s@[^/][^/]*//*\.\./@/@;t 0 - s@^/*\.\./@/@;s@//*@/@g;s@/\.\{0,1\}$@@ - s@^$@/@;s@\([.[\/*^$]\)@\\\1@g;s@^\(.*\)$@/^\1|/d@' 2>> "$_FASD_SINK")" - - # maintain the file - local tempfile - tempfile="$(mktemp "$_FASD_DATA".XXXXXX)" || return - - sed "$sed_cmd" "$_FASD_DATA" 2>> "$_FASD_SINK" >| "$tempfile" - - if [ $? -ne 0 -a -f "$_FASD_DATA" ]; then - env rm -f "$tempfile" - else - env mv -f "$tempfile" "$_FASD_DATA" - fi - ;; - ---query) shift # query the db, --query [$typ ["$fnd" [$mode]]] - [ -f "$_FASD_DATA" ] || return # no db yet - [ "$1" ] && local typ="$1" - [ "$2" ] && local fnd="$2" - [ "$3" ] && local mode="$3" - - # cat all backends - local each _fasd_data; for each in $_FASD_BACKENDS; do - _fasd_data="$_fasd_data -$(fasd --backend $each)" - done - [ "$_fasd_data" ] || _fasd_data="$(cat "$_FASD_DATA")" - - # set mode specific code for calculating the prior - case $mode in - rank) local prior='times[i]';; - recent) local prior='sqrt(100000/(1+t-la[i]))';; - *) local prior='times[i] * frecent(la[i])';; - esac - - if [ "$fnd" ]; then # dafault matching - local bre="$(printf %s\\n "$fnd" | sed 's/\([*\.\\\[]\)/\\\1/g - s@ @[^|]*@g;s/\$$/|/')" - bre='^[^|]*'"$bre"'[^|/]*|' - local _ret="$(printf %s\\n "$_fasd_data" | grep "$bre")" - [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do - [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" - done)" - if [ "$_ret" ]; then - _fasd_data="$_ret" - else # no case mathcing - _ret="$(printf %s\\n "$_fasd_data" | grep -i "$bre")" - [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do - [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" - done)" - if [ "$_ret" ]; then - _fasd_data="$_ret" - elif [ "${_FASD_FUZZY:-0}" -gt 0 ]; then # fuzzy matching - local fuzzy_bre="$(printf %s\\n "$fnd" | \ - sed 's/\([*\.\\\[]\)/\\\1/g;s/\$$/|/ - s@\(\\\{0,1\}[^ ]\)@\1[^|/]\\{0,'"$_FASD_FUZZY"'\\}@g - s@ @[^|]*@g')" - fuzzy_bre='^[^|]*'"$fuzzy_bre"'[^|/]*|' - _ret="$(printf %s\\n "$_fasd_data" | grep -i "$fuzzy_bre")" - [ "$_ret" ] && _ret="$(printf %s\\n "$_ret" | while read -r line; do - [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" - done)" - [ "$_ret" ] && _fasd_data="$_ret" || _fasd_data= - fi - fi - else # no query arugments - _fasd_data="$(printf %s\\n "$_fasd_data" | while read -r line; do - [ -${typ:-e} "${line%%\|*}" ] && printf %s\\n "$line" - done)" - fi - - # query the database - [ "$_fasd_data" ] && printf %s\\n "$_fasd_data" | \ - $_FASD_AWK -v t="$(date +%s)" -F"|" ' - function frecent(time) { - dx = t-time - if( dx < 3600 ) return 6 - if( dx < 86400 ) return 4 - if( dx < 604800 ) return 2 - return 1 - } - { - if(!paths[$1]) { - times[$1] = $2 - la[$1] = $3 - paths[$1] = 1 - } else { - times[$1] += $2 - if($3 > la[$1]) la[$1] = $3 - } - } - END { - for(i in paths) printf "%-10s %s\n", '"$prior"', i - }' - 2>> "$_FASD_SINK" - ;; - ---backend) - case $2 in - native) cat "$_FASD_DATA";; - viminfo) - < "$_FASD_VIMINFO" sed -n '/^>/{s@~@'"$HOME"'@ - s/^..// - p - }' | $_FASD_AWK -v t="$(date +%s)" '{ - t -= 60 - print $0 "|1|" t - }' - ;; - recently-used) - local nl="$(printf '\\\nX')"; nl="${nl%X}" # slash newline for sed - tr -d '\n' < "$_FASD_RECENTLY_USED_XBEL" | \ - sed 's@file:/@'"$nl"'@g;s@count="@'"$nl"'@g' | sed '1d;s/".*$//' | \ - tr '\n' '|' | sed 's@|/@'"$nl"'@g' | $_FASD_AWK -F'|' '{ - sum = 0 - for( i=2; i<=NF; i++ ) sum += $i - print $1 "|" sum - }' - ;; - current) - for path in *; do - printf "$PWD/%s|1\\n" "$path" - done - ;; - spotlight) - mdfind '(kMDItemFSContentChangeDate >= $time.today) || - kMDItemLastUsedDate >= $time.this_month' \ - | sed '/Library\//d - /\.app$/d - s/$/|2/' - ;; - *) eval "$2";; - esac - ;; - -*) # parsing logic and processing - local fnd= last= _FASD_BACKENDS="$_FASD_BACKENDS" _fasd_data= comp= exec= - while [ "$1" ]; do case $1 in - --complete) [ "$2" = "--" ] && shift; set -- $2; local lst=1 r=r comp=1;; - --query|--add|--delete|-A|-D) fasd "$@"; return $?;; - --version) [ -z "$comp" ] && echo "1.0.1" && return;; - --) while [ "$2" ]; do shift; fnd="$fnd $1"; last="$1"; done;; - -*) local o="${1#-}"; while [ "$o" ]; do case $o in - s*) local show=1;; - l*) local lst=1;; - i*) [ -z "$comp" ] && local interactive=1 show=1;; - r*) local mode=rank;; - t*) local mode=recent;; - e*) o="${o#?}"; if [ "$o" ]; then # there are characters after "-e" - local exec="$o" # anything after "-e" - else # use the next argument - local exec="${2:?"-e: Argument needed "}" - shift - fi; break;; - b*) o="${o#?}"; if [ "$o" ]; then - _FASD_BACKENDS="$o" - else - _FASD_BACKENDS="${2:?"-b: Argument needed"}" - shift - fi; break;; - B*) o="${o#?}"; if [ "$o" ]; then - _FASD_BACKENDS="$_FASD_BACKENDS $o" - else - _FASD_BACKENDS="$_FASD_BACKENDS ${2:?"-B: Argument needed"}" - shift - fi; break;; - a*) local typ=e;; - d*) local typ=d;; - f*) local typ=f;; - R*) local r=r;; - [0-9]*) local _fasd_i="$o"; break;; - h*) [ -z "$comp" ] && echo "fasd [options] [query ...] -[f|a|s|d|z] [options] [query ...] - options: - -s list paths with scores - -l list paths without scores - -i interactive mode - -e set command to execute on the result file - -b only use backend - -B add additional backend - -a match files and directories - -d match directories only - -f match files only - -r match by rank only - -t match by recent access only - -R reverse listing order - -h show a brief help message - -[0-9] select the nth entry - -fasd [-A|-D] [paths ...] - -A add paths - -D delete paths" >&2 && return;; - esac; o="${o#?}"; done;; - *) fnd="$fnd $1"; last="$1";; - esac; shift; done - - # guess whether the last query is selected from tab completion - case $last in - /?*) if [ -z "$show$lst" -a -${typ:-e} "$last" -a "$exec" ]; then - $exec "$last" - return - fi;; - esac - - local R; [ -z "$r" ] && R=r || R= # let $R be the opposite of $r - fnd="${fnd# }" - - local res - res="$(fasd --query 2>> "$_FASD_SINK")" # query the database - [ $? -gt 0 ] && return - if [ 0 -lt ${_fasd_i:-0} ] 2>> "$_FASD_SINK"; then - res="$(printf %s\\n "$res" | sort -n${R} | \ - sed -n "$_fasd_i"'s/^[^ ]*[ ]*//p')" - elif [ "$interactive" ] || [ "$exec" -a -z "$fnd$lst$show" -a -t 1 ]; then - if [ "$(printf %s "$res" | sed -n '$=')" -gt 1 ]; then - res="$(printf %s\\n "$res" | sort -n${R})" - printf %s\\n "$res" | sed = | sed 'N;s/\n/ /' | sort -nr >&2 - printf "> " >&2 - local i; read i; [ 0 -lt "${i:-0}" ] 2>> "$_FASD_SINK" || return 1 - fi - res="$(printf %s\\n "$res" | sed -n "${i:-1}"'s/^[^ ]*[ ]*//p')" - elif [ "$lst" ]; then - [ "$res" ] && printf %s\\n "$res" | sort -n${r} | sed 's/^[^ ]*[ ]*//' - return - elif [ "$show" ]; then - [ "$res" ] && printf %s\\n "$res" | sort -n${r} - return - elif [ "$fnd" ] && [ "$exec" -o ! -t 1 ]; then # exec or subshell - res="$(printf %s\\n "$res" | sort -n | sed -n '$s/^[^ ]*[ ]*//p')" - else # no args, show - [ "$res" ] && printf %s\\n "$res" | sort -n${r} - return - fi - if [ "$res" ]; then - fasd --add "$res" - [ -z "$exec" ] && exec='printf %s\n' - $exec "$res" - fi - ;; -esac - -#case $- in -# *i*) ;; # assume being sourced, do nothing -# *) # assume being executed as an executable -# if [ -x "$_FASD_SHELL" -a -z "$_FASD_SET" ]; then -# _FASD_SET=1 exec $_FASD_SHELL "$0" "$@" -# else -# fasd "$@" -# fi;; -#esac diff --git a/modules/fasd/init.zsh b/modules/fasd/init.zsh deleted file mode 100644 index cc05f62..0000000 --- a/modules/fasd/init.zsh +++ /dev/null @@ -1,88 +0,0 @@ -fasd --init env - -# function to execute built-in cd -fasd_cd() { - if [ $# -le 1 ]; then - fasd "$@" - else - local _fasd_ret="$(fasd -e 'printf %s' "$@")" - [ -z "$_fasd_ret" ] && return - [ -d "$_fasd_ret" ] && cd "$_fasd_ret" || printf %s\n "$_fasd_ret" - fi -} - -alias a='fasd -a' -alias s='fasd -si' -alias sd='fasd -sid' -alias sf='fasd -sif' -alias d='fasd -d' -alias f='fasd -f' -alias v='f -e vim -b viminfo' -alias z='fasd_cd -d' -alias zz='fasd_cd -d -i' - -# add zsh hook -_fasd_preexec() { - { eval "fasd --proc $(fasd --sanitize $2)"; } >> "/dev/null" 2>&1 -} -autoload -Uz add-zsh-hook -add-zsh-hook preexec _fasd_preexec - -# zsh command mode completion -_fasd_zsh_cmd_complete() { - local compl - read -c compl - (( $+compstate )) && compstate[insert]=menu # no expand if compsys loaded - reply=(${(f)"$(fasd --complete "$compl")"}) -} - -# enable command mode completion -compctl -U -K _fasd_zsh_cmd_complete -V fasd -x 'C[-1,-*e],s[-]n[1,e]' -c - \ - 'c[-1,-A][-1,-D]' -f -- fasd fasd_cd - -(( $+functions[compdef] )) && { - # zsh word mode completion - _fasd_zsh_word_complete() { - [ "$2" ] && local _fasd_cur="$2" - [ -z "$_fasd_cur" ] && local _fasd_cur="${words[CURRENT]}" - local fnd="${_fasd_cur//,/ }" - local typ=${1:-e} - fasd --query $typ "$fnd" 2>> "/dev/null" | \ - sort -nr | sed 's/^[^ ]*[ ]*//' | while read -r line; do - compadd -U -V fasd "$line" - done - compstate[insert]=menu # no expand - } - _fasd_zsh_word_complete_f() { _fasd_zsh_word_complete f ; } - _fasd_zsh_word_complete_d() { _fasd_zsh_word_complete d ; } - _fasd_zsh_word_complete_trigger() { - local _fasd_cur="${words[CURRENT]}" - eval $(fasd --word-complete-trigger _fasd_zsh_word_complete $_fasd_cur) - } - # define zle widgets - zle -C fasd-complete complete-word _generic - zstyle ':completion:fasd-complete:*' completer _fasd_zsh_word_complete - zstyle ':completion:fasd-complete:*' menu-select - - zle -C fasd-complete-f complete-word _generic - zstyle ':completion:fasd-complete-f:*' completer _fasd_zsh_word_complete_f - zstyle ':completion:fasd-complete-f:*' menu-select - - zle -C fasd-complete-d complete-word _generic - zstyle ':completion:fasd-complete-d:*' completer _fasd_zsh_word_complete_d - zstyle ':completion:fasd-complete-d:*' menu-select -} - -(( $+functions[compdef] )) && { - # enable word mode completion - orig_comp="$(zstyle -L ':completion:\*' completer 2>> "/dev/null")" - if [ "$orig_comp" ]; then - case $orig_comp in - *_fasd_zsh_word_complete_trigger*);; - *) eval "$orig_comp _fasd_zsh_word_complete_trigger";; - esac - else - zstyle ':completion:*' completer _complete _fasd_zsh_word_complete_trigger - fi - unset orig_comp -} diff --git a/modules/git-info/README.md b/modules/git-info/README.md deleted file mode 100644 index be649ba..0000000 --- a/modules/git-info/README.md +++ /dev/null @@ -1,129 +0,0 @@ -git-info -======== - -Exposes git repository status information to prompts. - -Many thanks to [Sorin Ionescu](https://github.com/sorin-ionescu) and -[Colin Hebert](https://github.com/ColinHebert) for the original code. - -Git **1.7.2** is the -[minimum required version](https://github.com/sorin-ionescu/prezto/issues/219). - -Settings --------- - -### Ignore submodules - -Retrieving the status of a repository with submodules can take a long time. -So by default 'all' submodules are ignored. Optionally, 'untracked', 'dirty', or -'none' submodules can be ignored: - - zstyle ':zim:git-info' ignore-submodules 'none' - -### Verbose mode - -Verbose mode uses `git status` and computes the count of indexed, unindexed and -also untracked files. It can be enabled with the following zstyle: - - zstyle ':zim:git-info' verbose yes - -In non-verbose mode, the 'untracked' context is not available (see *Main -contexts* below), and untracked files are also not considered for computing the -'dirty' context. Using `git status` to check for untracked files can be -[expensive](https://gist.github.com/sindresorhus/3898739). - -Theming -------- - -To display information about the current repository in a prompt, define your -custom styles in the `prompt_name_setup` function, where the syntax for setting -a style is: - - zstyle ':zim:git-info:context' format 'string' - -### Main contexts - -| Name | Code | Description -| --------- | :----: | --------------------------------------------------------- -| action | %s | Special action name (see *Special action contexts* below) -| ahead | %A | Commits ahead of remote count -| behind | %B | Commits behind of remote count -| diverged | %V | Diverged commits (both ahead and behind are yield when it's not defined) -| branch | %b | Branch name -| commit | %c | Commit short hash (when in 'detached HEAD' state) -| clean | %C | Clean state -| dirty | %D | Dirty state (count with untracked files when verbose mode enabled) -| indexed | %i | Indexed files (count when verbose mode enabled) -| unindexed | %I | Unindexed files (count when verbose mode enabled) -| position | %p | Commits from nearest tag count (when in 'detached HEAD' state) -| remote | %R | Remote name -| stashed | %S | Stashed states count -| untracked | %u | Untracked files count (only when verbose mode enabled) - -While `commit` and `position` are only available when in ['detached HEAD' -state](http://gitfaq.org/articles/what-is-a-detached-head.html), on the other -hand, `ahead`, `behind`, `diverged`, `branch` and `remote` are only available -when an actual branch is checked out (so when **not** in 'detached HEAD' state). - -### Special action contexts - -| Name | Format | Default Value -| --------------------------- | :-----: | -------------------------------------- -| action:apply | value | 'apply' -| action:bisect | value | 'bisect' -| action:cherry-pick | value | 'cherry-pick' -| action:cherry-pick-sequence | value | 'cherry-pick-sequence' -| action:merge | value | 'merge' -| action:rebase | value | 'rebase' -| action:rebase-interactive | value | 'rebase-interactive' -| action:rebase-merge | value | 'rebase-merge' - -Formatting example for special actions: - - zstyle ':zim:git-info:action:bisect' format '' - zstyle ':zim:git-info:action:merge' format '>M<' - zstyle ':zim:git-info:action:rebase' format '>R>' - -### Usage - -First, format the repository state attributes. For example, to format the -branch name, commit, and remote name, define the following styles: - - zstyle ':zim:git-info:branch' format 'branch:%b' - zstyle ':zim:git-info:commit' format 'commit:%c' - zstyle ':zim:git-info:remote' format 'remote:%R' - -Second, format how the above attributes are displayed in prompts: - - zstyle ':zim:git-info:keys' format \ - 'prompt' 'git(%b%c)' \ - 'rprompt' '[%R]' - -Last, add `${(e)git_info[prompt]}` and `${(e)git_info[rprompt]}` to `PS1` and -`RPS1` respectively, and call `git-info` in the `prompt_name_precmd` hook function. - -Here's a complete example of a `prompt_example_setup` file: -```zsh -prompt_example_precmd() { - (( ${+functions[git-info]} )) && git-info -} - -prompt_example_setup() { - autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_example_precmd - - prompt_opts=(cr percent sp subst) - - zstyle ':zim:git-info:branch' format 'branch:%b' - zstyle ':zim:git-info:commit' format 'commit:%c' - zstyle ':zim:git-info:remote' format 'remote:%R' - - zstyle ':zim:git-info:keys' format \ - 'prompt' 'git(%b%c)' \ - 'rprompt' '[%R]' - - PS1='${(e)git_info[prompt]}%# ' - RPS1='${(e)git_info[rprompt]}' -} - -prompt_example_setup "${@}" -``` diff --git a/modules/git-info/functions/coalesce b/modules/git-info/functions/coalesce deleted file mode 100644 index 972a83c..0000000 --- a/modules/git-info/functions/coalesce +++ /dev/null @@ -1,8 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# Prints the first non-empty string in the arguments array. -local arg -for arg in ${argv}; do - print -n ${arg} - return 0 -done -return 1 diff --git a/modules/git-info/functions/git-action b/modules/git-info/functions/git-action deleted file mode 100644 index 007da9a..0000000 --- a/modules/git-info/functions/git-action +++ /dev/null @@ -1,80 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# Gets the Git special action (am, bisect, cherry, merge, rebase). -# Borrowed from vcs_info and edited. -local git_dir=${$(command git rev-parse --git-dir):A} -local action_dir -for action_dir in \ - "${git_dir}/rebase-apply" \ - "${git_dir}/rebase" \ - "${git_dir}/../.dotest" -do - if [[ -d ${action_dir} ]]; then - local apply_formatted rebase_formatted - zstyle -s ':zim:git-info:action:apply' format 'apply_formatted' || apply_formatted='apply' - zstyle -s ':zim:git-info:action:rebase' format 'rebase_formatted' || rebase_formatted='rebase' - - if [[ -f "${action_dir}/rebasing" ]]; then - print ${rebase_formatted} - elif [[ -f "${action_dir}/applying" ]]; then - print ${apply_formatted} - else - print "${rebase_formatted}/${apply_formatted}" - fi - - return 0 - fi -done - -for action_dir in \ - "${git_dir}/rebase-merge/interactive" \ - "${git_dir}/.dotest-merge/interactive" -do - if [[ -f ${action_dir} ]]; then - local rebase_interactive_formatted - zstyle -s ':zim:git-info:action:rebase-interactive' format 'rebase_interactive_formatted' || rebase_interactive_formatted='rebase-interactive' - print ${rebase_interactive_formatted} - return 0 - fi -done - -for action_dir in \ - "${git_dir}/rebase-merge" \ - "${git_dir}/.dotest-merge" -do - if [[ -d ${action_dir} ]]; then - local rebase_merge_formatted - zstyle -s ':zim:git-info:action:rebase-merge' format 'rebase_merge_formatted' || rebase_merge_formatted='rebase-merge' - print ${rebase_merge_formatted} - return 0 - fi -done - -if [[ -f "${git_dir}/MERGE_HEAD" ]]; then - local merge_formatted - zstyle -s ':zim:git-info:action:merge' format 'merge_formatted' || merge_formatted='merge' - print ${merge_formatted} - return 0 -fi - -if [[ -f "${git_dir}/CHERRY_PICK_HEAD" ]]; then - if [[ -d "${git_dir}/sequencer" ]]; then - local cherry_pick_sequence_formatted - zstyle -s ':zim:git-info:action:cherry-pick-sequence' format 'cherry_pick_sequence_formatted' || cherry_pick_sequence_formatted='cherry-pick-sequence' - print ${cherry_pick_sequence_formatted} - else - local cherry_pick_formatted - zstyle -s ':zim:git-info:action:cherry-pick' format 'cherry_pick_formatted' || cherry_pick_formatted='cherry-pick' - print ${cherry_pick_formatted} - fi - - return 0 -fi - -if [[ -f "${git_dir}/BISECT_LOG" ]]; then - local bisect_formatted - zstyle -s ':zim:git-info:action:bisect' format 'bisect_formatted' || bisect_formatted='bisect' - print ${bisect_formatted} - return 0 -fi - -return 1 diff --git a/modules/git-info/functions/git-info b/modules/git-info/functions/git-info deleted file mode 100644 index 1484e58..0000000 --- a/modules/git-info/functions/git-info +++ /dev/null @@ -1,224 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# -# Exposes Git repository information via the git_info associative array. -# - -# Extended globbing is needed to parse repository status. -setopt LOCAL_OPTIONS EXTENDED_GLOB - -# Clean up previous git_info. -unset git_info -typeset -gA git_info - -# Return if not inside a Git repository work tree. -if ! command git rev-parse --is-inside-work-tree &>/dev/null; then - return 1 -fi - -# Ignore submodule status. -local ignore_submodules -zstyle -s ':zim:git-info' ignore-submodules 'ignore_submodules' || ignore_submodules='all' - -# Format stashed. -local stashed_format stashed_formatted -if zstyle -s ':zim:git-info:stashed' format 'stashed_format'; then - local -i stashed=$(command git stash list 2>/dev/null | wc -l) - (( stashed )) && zformat -f stashed_formatted ${stashed_format} "S:${stashed}" -fi - -# Format action. -local action_format action_formatted -if zstyle -s ':zim:git-info:action' format 'action_format'; then - local action=$(git-action) - if [[ -n ${action} ]]; then - zformat -f action_formatted ${action_format} "s:${action}" - fi -fi - -# The contents of git_info are subject to expansion by the shell. Avoid -# putting raw ref names in the prompt to protect the user from arbitrary code -# execution via specially crafted ref names (e.g., a ref named -# '$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' would execute 'sudo rm -rf /' when the -# prompt is drawn). Instead, put the ref names in new global variables and -# reference these variables from git_info. -# See https://github.com/njhartwell/pw3nage - -# Get the branch. -__GIT_INFO_BRANCH=$(command git symbolic-ref -q --short HEAD 2>/dev/null) - -local ahead_formatted behind_formatted branch_formatted commit_formatted diverged_formatted position_formatted remote_formatted -if [[ -n ${__GIT_INFO_BRANCH} ]]; then - unset __GIT_INFO_POSITION - - # Format branch. - local branch_format - if zstyle -s ':zim:git-info:branch' format 'branch_format'; then - zformat -f branch_formatted ${branch_format} 'b:${__GIT_INFO_BRANCH}' - fi - - # Format remote. - local remote_format - if zstyle -s ':zim:git-info:remote' format 'remote_format'; then - # Gets the remote name. - local remote_cmd='command git rev-parse --symbolic-full-name --verify HEAD@{upstream}' - __GIT_INFO_REMOTE=${$(${(z)remote_cmd} 2>/dev/null)##refs/remotes/} - if [[ -n ${__GIT_INFO_REMOTE} ]]; then - zformat -f remote_formatted ${remote_format} 'R:${__GIT_INFO_REMOTE}' - else - unset __GIT_INFO_REMOTE - fi - fi - - local ahead_format behind_format diverged_format - zstyle -s ':zim:git-info:ahead' format 'ahead_format' - zstyle -s ':zim:git-info:behind' format 'behind_format' - zstyle -s ':zim:git-info:diverged' format 'diverged_format' - if [[ -n ${ahead_format} || -n ${behind_format} || -n ${diverged_format} ]]; then - # Gets the commit difference counts between local and remote. - local ahead_and_behind_cmd='command git rev-list --count --left-right HEAD...@{upstream}' - - # Get ahead and behind counts. - local ahead_and_behind=$(${(z)ahead_and_behind_cmd} 2>/dev/null) - local -i ahead=${ahead_and_behind[(w)1]} - local -i behind=${ahead_and_behind[(w)2]} - - if [[ -n ${diverged_format} && ${ahead} -gt 0 && ${behind} -gt 0 ]]; then - # Format diverged. - diverged_formatted=${diverged_format} - else - # Format ahead. - if [[ -n ${ahead_format} && ${ahead} -gt 0 ]]; then - zformat -f ahead_formatted ${ahead_format} "A:${ahead}" - fi - # Format behind. - if [[ -n ${behind_format} && ${behind} -gt 0 ]]; then - zformat -f behind_formatted ${behind_format} "B:${behind}" - fi - fi - fi -else - unset __GIT_INFO_BRANCH - unset __GIT_INFO_REMOTE - - # Format commit. - local commit_format - if zstyle -s ':zim:git-info:commit' format 'commit_format'; then - local commit=$(command git rev-parse --short HEAD 2>/dev/null) - if [[ -n ${commit} ]]; then - zformat -f commit_formatted ${commit_format} "c:${commit}" - fi - fi - - # Format position. - local position_format - if zstyle -s ':zim:git-info:position' format 'position_format'; then - __GIT_INFO_POSITION=$(command git describe --contains --all HEAD 2>/dev/null) - if [[ -n ${__GIT_INFO_POSITION} ]]; then - zformat -f position_formatted ${position_format} 'p:${__GIT_INFO_POSITION}' - fi - fi -fi - -# Dirty and clean format. -local dirty_format dirty_formatted clean_format clean_formatted -zstyle -s ':zim:git-info:dirty' format 'dirty_format' -zstyle -s ':zim:git-info:clean' format 'clean_format' - -local -i dirty -local indexed_formatted unindexed_formatted untracked_formatted -if ! zstyle -t ':zim:git-info' verbose; then - # Format unindexed. - local unindexed_format - zstyle -s ':zim:git-info:unindexed' format 'unindexed_format' - if [[ -n ${unindexed_format} || -n ${dirty_format} || -n ${clean_format} ]]; then - if ! command git diff-files --no-ext-diff --quiet --ignore-submodules=${ignore_submodules} &>/dev/null; then - unindexed_formatted=${unindexed_format} - dirty=1 - fi - fi - - # Format indexed. - local indexed_format - zstyle -s ':zim:git-info:indexed' format 'indexed_format' - if [[ -n ${indexed_format} || (${dirty} -eq 0 && (-n ${dirty_format} || -n ${clean_format})) ]]; then - if ! command git diff-index --no-ext-diff --quiet --cached --ignore-submodules=${ignore_submodules} HEAD &>/dev/null; then - indexed_formatted=${indexed_format} - dirty=1 - fi - fi - - # Format dirty and clean. - if (( dirty )); then - dirty_formatted=${dirty_format} - else - clean_formatted=${clean_format} - fi -else - # Use porcelain status for easy parsing. - local status_cmd="command git status --porcelain --ignore-submodules=${ignore_submodules}" - - local -i indexed unindexed untracked - # Get current status. - while IFS=$'\n' read line; do - if [[ ${line:0:2} == '??' ]]; then - (( untracked++ )) - else - [[ ${line:0:1} != ' ' ]] && (( indexed++ )) - [[ ${line:1:1} != ' ' ]] && (( unindexed++ )) - fi - (( dirty++ )) - done < <(${(z)status_cmd} 2>/dev/null) - - # Format indexed. - if (( indexed )); then - local indexed_format - zstyle -s ':zim:git-info:indexed' format 'indexed_format' - zformat -f indexed_formatted ${indexed_format} "i:${indexed}" - fi - - # Format unindexed. - if (( unindexed )); then - local unindexed_format - zstyle -s ':zim:git-info:unindexed' format 'unindexed_format' - zformat -f unindexed_formatted ${unindexed_format} "I:${unindexed}" - fi - - # Format untracked. - if (( untracked )); then - local untracked_format - zstyle -s ':zim:git-info:untracked' format 'untracked_format' - zformat -f untracked_formatted ${untracked_format} "u:${untracked}" - fi - - # Format dirty and clean. - if (( dirty )); then - zformat -f dirty_formatted ${dirty_format} "u:${dirty}" - else - clean_formatted=${clean_format} - fi -fi - -# Format info. -local -A info_formats -local info_format reply -zstyle -a ':zim:git-info:keys' format 'info_formats' -for info_format in ${(k)info_formats}; do - zformat -f reply "${info_formats[${info_format}]}" \ - "A:${ahead_formatted}" \ - "B:${behind_formatted}" \ - "b:${branch_formatted}" \ - "C:${clean_formatted}" \ - "c:${commit_formatted}" \ - "D:${dirty_formatted}" \ - "i:${indexed_formatted}" \ - "I:${unindexed_formatted}" \ - "p:${position_formatted}" \ - "R:${remote_formatted}" \ - "s:${action_formatted}" \ - "S:${stashed_formatted}" \ - "u:${untracked_formatted}" \ - "V:${diverged_formatted}" - git_info[${info_format}]=${reply} -done - -return 0 diff --git a/modules/git/README.md b/modules/git/README.md deleted file mode 100644 index 9c0abc7..0000000 --- a/modules/git/README.md +++ /dev/null @@ -1,236 +0,0 @@ -git -=== - -Provides handy git aliases and functions. - -Many thanks to [Sorin Ionescu](https://github.com/sorin-ionescu) for the -excellent original aliases. - -Aliases -------- - -### Git - - * `g` is short for `git`. - -### Branch - - * `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. - * `gbm` renames a branch. - * `gbM` renames a branch even if the new branch name already exists. - * `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. - -### Commit - - * `gc` records changes to the repository. - * `gca` commits all modified and deleted files. - * `gcm` commits with the given message. - * `gco` checks out a branch or paths to the working tree. - * `gcO` checks out hunks from the index or the tree interactively. - * `gcf` amends the tip of the current branch reusing the same log message as - *HEAD*. - * `gcF` amends the tip of the current branch. - * `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` shows one or more objects (blobs, trees, tags and commits). - * `gcS` commits with GPG signature. - * `gcv` verifies the GPG signature of commits. - -### Conflict - - * `gCl` lists unmerged files. - * `gCa` adds unmerged file contents to the index. - * `gCe` executes merge-tool on all unmerged files. - * `gCo` checks out our changes for unmerged paths. - * `gCO` checks out our changes for all unmerged paths. - * `gCt` checks out their changes for unmerged paths. - * `gCT` checks out their changes for all unmerged paths. - -### Data - - * `gd` displays information about files in the index and the work tree. - * `gdc` lists cached files. - * `gdx` lists deleted files. - * `gdm` lists modified files. - * `gdu` lists untracked files. - * `gdk` lists killed files. - * `gdi` lists ignored files. - -### Fetch - - * `gf` downloads objects and references from another repository. - * `gfc` clones a repository into a new directory. - * `gfm` fetches from and merges with another repository or local branch. - * `gfr` fetches from and rebases on top of another repository or local branch. - * `gfu` removes unexisting remote-tracking references, fetches all remotes and - merges. - -### Grep - - * `gg` displays lines matching a pattern. - * `ggi` displays lines matching a pattern ignoring case. - * `ggl` lists files matching a pattern. - * `ggL` lists files that are not matching a pattern. - * `ggv` displays lines not matching a pattern. - * `ggw` displays lines matching a pattern at word boundary. - -### Index - - * `gia` adds file contents to the index. - * `giA` adds file contents to the index interactively. - * `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). - * `gir` resets the current *HEAD* to the specified state. - * `giR` resets the current index interactively. - * `gix` removes files/directories from the index (recursively). - * `giX` removes files/directories from the index (recursively and forced). - -### Log - - * `gl` displays the log. - * `gls` displays the stats log. - * `gld` displays the diff log. - * `glo` displays the one line log. - * `glO` displays the one line log with authors and dates. - * `glg` displays the graph log. - * `glG` displays the graph log with authors and dates. - * `glv` displays the log verifying the GPG signature of commits. - * `glc` displays the commit count for each contributor in descending order. - -### Merge - - * `gm` joins two or more development histories together. - * `gmC` performs the merge but does not commit. - * `gmF` performs the merge generating a commit even if the merge resolved as a - fast-forward. - * `gma` aborts the conflict resolution, and reconstructs the pre-merge state. - * `gmt` runs the merge conflict resolution tools to resolve conflicts. - -### Push - - * `gp` updates remote refs along with associated objects. - * `gpf` forces a push safely (with "lease"). - * `gpF` forces a push. - * `gpa` pushes all branches. - * `gpA` pushes all branches and tags. - * `gpt` pushes all tags. - * `gpc` pushes the current branch and adds *origin* as an upstream reference - for it. - * `gpp` pulls and pushes the current branch from *origin* to *origin*. - -### Rebase - - * `gr` forward-ports local commits to the updated upstream head. - * `gra` aborts the rebase. - * `grc` continues the rebase after merge conflicts are resolved. - * `gri` makes a list of commits to be rebased and opens the editor. - * `grs` skips the current patch. - -### Remote - - * `gR` manages tracked repositories. - * `gRl` lists remote names and their URLs. - * `gRa` adds a new remote. - * `gRx` removes a remote. - * `gRm` renames a remote. - * `gRu` fetches remotes updates. - * `gRp` prunes all stale remote tracking branches. - * `gRs` shows information about a given remote. - -### Stash - - * `gs` stashes the changes of the dirty working directory. - * `gsa` applies the changes recorded in a stash to the working directory. - * `gsx` drops a stashed state. - * `gsX` drops all the stashed states. - * `gsl` lists stashed states. - * `gsd` displays changes between the stash and its original parent. - * `gsp` removes and applies a single stashed state from the stash list. - * `gsr` recovers a given stashed state. - * `gss` stashes the working directory changes, including untracked files. - * `gsS` stashes the working directory changes interactively. - * `gsw` stashes the working directory changes retaining the index. - * `gsu` unapplies (reverts) applied changes. - -### Submodule - - * `gS` initializes, updates, or inspects submodules. - * `gSa` adds given a repository as a submodule. - * `gSf` evaluates a shell command in each of checked out submodules. - * `gSi` initializes submodules. - * `gSI` initializes and clones submodules recursively. - * `gSl` lists the commits of all submodules. - * `gSm` moves a submodule. - * `gSs` synchronizes submodules' remote URL to the value specified in - `.gitmodules`. - * `gSu` fetches and merges the latest changes for all submodules. - * `gSx` removes a submodule. - -### Tag - - * `gt` creates, lists, deletes or verifies a tag object signed with GPG. - * `gts` creates a GPG-signed tag. - * `gtv` verifies the GPG signature of tags. - * `gtx` deletes tags with given names. - -### Working tree - - * `gws` displays working-tree status in the short format. - * `gwS` displays working-tree status. - * `gwd` displays changes between the working tree and the index (diff). - * `gwD` displays changes between the working tree and the index (word diff). - * `gwr` resets the current *HEAD* to the specified state, does not touch the - index nor the working tree. - * `gwR` resets the current *HEAD*, index and working tree to the specified - state. - * `gwc` cleans untracked files from the working tree (dry-run). - * `gwC` cleans untracked files from the working tree. - * `gwx` removes files from the working tree and from the index recursively. - * `gwX` removes files from the working tree and from the index recursively and - forcefully. - -### Misc - - * `g..` changes the current directory to the top level of the working tree. - -### Shadows - -The following aliases may shadow system commands: - - * `gb` shadows a [build tool for the Go programming language](https://getgb.io/). - * `gm` shadows [GraphicsMagick](http://www.graphicsmagick.org/). - * `gpt` shadows the GUID partition table maintenance utility. - * `grc` shadows [Generic Colouriser](https://github.com/garabik/grc). - * `gs` shadows [Ghostscript](https://www.ghostscript.com/). - -If you frequently use the above commands, you may wish to disable this module -altogether, or to disable the specific aliases with `unalias` at the bottom of -your `.zshrc`. - -You can temporarily bypass an alias by prefixing it with a backward slash: -`\gpt`. - -Functions ---------- - - * `git-branch-current` displays the current branch. - * `git-branch-delete-interactive` asks for confirmation to also delete the - upstream remote branch(es). - * `git-dir` displays the path to the Git directory. - * `git-ignore-add` adds any arguments to the .gitignore in the project root. - * `git-root` displays the path to the working tree root. - * `git-stash-clear-interactive` asks for confirmation before clearing the stash. - * `git-stash-recover` recovers given dropped stashed states. - * `git-submodule-move` moves a submodule. - * `git-submodule-remove` removes a submodule. diff --git a/modules/git/functions/_git-branch-delete-interactive b/modules/git/functions/_git-branch-delete-interactive deleted file mode 100644 index e102f80..0000000 --- a/modules/git/functions/_git-branch-delete-interactive +++ /dev/null @@ -1,3 +0,0 @@ -#compdef git-branch-delete-interactive - -words[1]=(git branch); (( CURRENT++ )); service=git; _git diff --git a/modules/git/functions/git-branch-current b/modules/git/functions/git-branch-current deleted file mode 100644 index e118d46..0000000 --- a/modules/git/functions/git-branch-current +++ /dev/null @@ -1,2 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -command git symbolic-ref -q --short HEAD diff --git a/modules/git/functions/git-branch-delete-interactive b/modules/git/functions/git-branch-delete-interactive deleted file mode 100644 index f6e7310..0000000 --- a/modules/git/functions/git-branch-delete-interactive +++ /dev/null @@ -1,14 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -local -a remotes -if (( ${*[(I)(-r|--remotes)]} )); then - remotes=(${^*:#-*}) -else - remotes=(${(f)"$(command git rev-parse --abbrev-ref ${^*:#-*}@{u} 2>/dev/null)"}) || remotes=() -fi -if command git branch --delete ${@} && \ - (( ${#remotes} )) && \ - read -q "?Also delete remote branch(es) ${remotes} [y/N]? "; then - print - local remote - for remote (${remotes}) command git push ${remote%%/*} :${remote#*/} -fi diff --git a/modules/git/functions/git-dir b/modules/git/functions/git-dir deleted file mode 100644 index b18901f..0000000 --- a/modules/git/functions/git-dir +++ /dev/null @@ -1,4 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -local git_dir -git_dir=$(command git rev-parse --git-dir) || return 1 -print ${git_dir:A} diff --git a/modules/git/functions/git-ignore-add b/modules/git/functions/git-ignore-add deleted file mode 100644 index 0022b9e..0000000 --- a/modules/git/functions/git-ignore-add +++ /dev/null @@ -1,6 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -local git_root -git_root=$(git-root) || return 1 - -# we are in a git repository. add parameters to .gitignore -for file (${@}) print ${file} >>! "${git_root}/.gitignore" diff --git a/modules/git/functions/git-root b/modules/git/functions/git-root deleted file mode 100644 index af4d0a5..0000000 --- a/modules/git/functions/git-root +++ /dev/null @@ -1,2 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -command git rev-parse --show-toplevel diff --git a/modules/git/functions/git-stash-clear-interactive b/modules/git/functions/git-stash-clear-interactive deleted file mode 100644 index b677b2a..0000000 --- a/modules/git/functions/git-stash-clear-interactive +++ /dev/null @@ -1,10 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -setopt LOCAL_OPTIONS PIPE_FAIL - -local -i stashed -stashed=$(command git stash list | wc -l) || return 1 -if (( stashed )) && \ - read -q "?Clear ${stashed} stashed state(s) [y/N]? "; then - print - command git stash clear -fi diff --git a/modules/git/functions/git-stash-recover b/modules/git/functions/git-stash-recover deleted file mode 100644 index ad44ab1..0000000 --- a/modules/git/functions/git-stash-recover +++ /dev/null @@ -1,8 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -command git rev-parse --is-inside-work-tree >/dev/null || return 1 - -local commit -for commit in "${@}"; do - 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 deleted file mode 100644 index a3878d5..0000000 --- a/modules/git/functions/git-submodule-move +++ /dev/null @@ -1,22 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -local git_root -git_root=$(git-root) || return 1 - -if [[ ${PWD} != ${git_root} ]]; then - print "${0}: must be run from the root of the work tree" >&2 - return 1 -fi - -local src="${1}" -local dst="${2}" -local url=$(command git config --file .gitmodules --get "submodule.${src}.url") -if [[ -z "${url}" ]]; then - print "${0}: submodule not found: ${src}" >&2 - return 1 -fi - -mkdir -p "${dst:h}" -git-submodule-remove "${src}" -git submodule add "${url}" "${dst}" - -return 0 diff --git a/modules/git/functions/git-submodule-remove b/modules/git/functions/git-submodule-remove deleted file mode 100644 index 4ad00c6..0000000 --- a/modules/git/functions/git-submodule-remove +++ /dev/null @@ -1,21 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -local git_dir -git_dir=$(git-dir) || return 1 - -if [[ ${PWD} != $(git-root) ]]; then - print "${0}: must be run from the root of the work tree" >&2 - return 1 -elif ! command git config --file .gitmodules --get "submodule.${1}.path" &>/dev/null; then - print "${0}: submodule not found: ${1}" >&2 - return 1 -fi - -command git config --file "${git_dir}/config" --remove-section "submodule.${1}" &>/dev/null -command git config --file .gitmodules --remove-section "submodule.${1}" &>/dev/null -command git add .gitmodules - -command git rm --cached "${1}" &>/dev/null -rm -rf "${1}" -rm -rf "${git_dir}/modules/${1}" - -return 0 diff --git a/modules/git/init.zsh b/modules/git/init.zsh deleted file mode 100644 index 6141801..0000000 --- a/modules/git/init.zsh +++ /dev/null @@ -1,184 +0,0 @@ -# -# Git aliases. -# - -# -# Settings -# - -# Log colour scheme has yellow commit hash, bold blue author, cyan date, auto ref names -# See https://git-scm.com/docs/pretty-formats -_git_log_medium_format='%C(bold)Commit:%C(reset) %C(yellow)%H%C(auto)%d%n%C(bold)Author:%C(reset) %C(bold blue)%an <%ae>%n%C(bold)Date:%C(reset) %C(cyan)%ai (%ar)%C(reset)%n%+B' -_git_log_oneline_format='%C(yellow)%h%C(reset) %s%C(auto)%d%C(reset)' -_git_log_oneline_medium_format='%C(yellow)%h%C(reset) %<|(60,trunc)%s %C(bold blue)<%an> %C(reset)%C(cyan)(%ar)%C(auto)%d%C(reset)' - -# -# Aliases -# - -# Git -alias g='git' - -# Branch (b) -alias gb='git branch' -alias gbc='git checkout -b' -alias gbl='git branch -vv' -alias gbL='git branch --all -vv' -alias gbm='git branch --move' -alias gbM='git branch --move --force' -alias gbs='git show-branch' -alias gbS='git show-branch --all' -alias gbx='git-branch-delete-interactive' -alias gbX='git-branch-delete-interactive --force' - -# Commit (c) -alias gc='git commit --verbose' -alias gca='git commit --verbose --all' -alias gcm='git commit --message' -alias gco='git checkout' -alias gcO='git checkout --patch' -alias gcf='git commit --amend --reuse-message HEAD' -alias gcF='git commit --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 --pretty=format:"${_git_log_medium_format}"' -alias gcS='git commit -S' -alias gcv='git verify-commit' - -# Conflict (C) -alias gCl='git --no-pager diff --diff-filter=U --name-only' -alias gCa='git add $(gCl)' -alias gCe='git mergetool $(gCl)' -alias gCo='git checkout --ours --' -alias gCO='gCo $(gCl)' -alias gCt='git checkout --theirs --' -alias gCT='gCt $(gCl)' - -# Data (d) -alias gd='git ls-files' -alias gdc='git ls-files --cached' -alias gdx='git ls-files --deleted' -alias gdm='git ls-files --modified' -alias gdu='git ls-files --other --exclude-standard' -alias gdk='git ls-files --killed' -alias gdi='git status --porcelain --short --ignored | sed -n "s/^!! //p"' - -# Fetch (f) -alias gf='git fetch' -alias gfc='git clone' -alias gfm='git pull' -alias gfr='git pull --rebase' -alias gfu='git fetch --all --prune && git merge --ff-only @\{u\}' - -# Grep (g) -alias gg='git grep' -alias ggi='git grep --ignore-case' -alias ggl='git grep --files-with-matches' -alias ggL='git grep --files-without-match' -alias ggv='git grep --invert-match' -alias ggw='git grep --word-regexp' - -# Index (i) -alias gia='git add' -alias giA='git add --patch' -alias giu='git add --update' -alias gid='git diff --no-ext-diff --cached' -alias giD='git diff --no-ext-diff --cached --word-diff' -alias gir='git reset' -alias giR='git reset --patch' -alias gix='git rm --cached -r' -alias giX='git rm --cached -rf' - -# Log (l) -alias gl='git log --topo-order --pretty=format:"${_git_log_medium_format}"' -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 glO='git log --topo-order --pretty=format:"${_git_log_oneline_medium_format}"' -alias glg='git log --topo-order --all --graph --pretty=format:"${_git_log_oneline_format}"' -alias glG='git log --topo-order --all --graph --pretty=format:"${_git_log_oneline_medium_format}"' -alias glv='git log --topo-order --show-signature --pretty=format:"${_git_log_medium_format}"' -alias glc='git shortlog --summary --numbered' - -# Merge (m) -alias gm='git merge' -alias gmC='git merge --no-commit' -alias gmF='git merge --no-ff' -alias gma='git merge --abort' -alias gmt='git mergetool' - -# Push (p) -alias gp='git push' -alias gpf='git push --force-with-lease' -alias gpF='git push --force' -alias gpa='git push --all' -alias gpA='git push --all && git push --tags' -alias gpt='git push --tags' -alias gpc='git push --set-upstream origin "$(git-branch-current 2> /dev/null)"' -alias gpp='git pull origin "$(git-branch-current 2> /dev/null)" && git push origin "$(git-branch-current 2> /dev/null)"' - -# Rebase (r) -alias gr='git rebase' -alias gra='git rebase --abort' -alias grc='git rebase --continue' -alias gri='git rebase --interactive' -alias grs='git rebase --skip' - -# Remote (R) -alias gR='git remote' -alias gRl='git remote --verbose' -alias gRa='git remote add' -alias gRx='git remote rm' -alias gRm='git remote rename' -alias gRu='git remote update' -alias gRp='git remote prune' -alias gRs='git remote show' - -# Stash (s) -alias gs='git stash' -alias gsa='git stash apply' -alias gsx='git stash drop' -alias gsX='git-stash-clear-interactive' -alias gsl='git stash list' -alias gsd='git stash show --patch --stat' -alias gsp='git stash pop' -alias gsr='git-stash-recover' -alias gss='git stash save --include-untracked' -alias gsS='git stash save --patch --no-keep-index' -alias gsw='git stash save --include-untracked --keep-index' -alias gsu='git stash show --patch | git apply --reverse' - -# Submodule (S) -alias gS='git submodule' -alias gSa='git submodule add' -alias gSf='git submodule foreach' -alias gSi='git submodule init' -alias gSI='git submodule update --init --recursive' -alias gSl='git submodule status' -alias gSm='git-submodule-move' -alias gSs='git submodule sync' -alias gSu='git submodule foreach git pull origin master' -alias gSx='git-submodule-remove' - -# Tag (t) -alias gt='git tag' -alias gts='git tag --sign' -alias gtv='git verify-tag' -alias gtx='git tag --delete' - -# Working tree (w) -alias gws='git status --short' -alias gwS='git status' -alias gwd='git diff --no-ext-diff' -alias gwD='git diff --no-ext-diff --word-diff' -alias gwr='git reset --soft' -alias gwR='git reset --hard' -alias gwc='git clean --dry-run' -alias gwC='git clean -d --force' -alias gwx='git rm -r' -alias gwX='git rm -rf' - -# Misc -alias g..='cd "$(git-root || print .)"' diff --git a/modules/history-substring-search/README.md b/modules/history-substring-search/README.md deleted file mode 100644 index 17778c3..0000000 --- a/modules/history-substring-search/README.md +++ /dev/null @@ -1,19 +0,0 @@ -history-substring-search -======================== - -Allows for fish-like searching of history with UP and DOWN. - -![example][example] - -If you use -[syntax-highlighting](https://github.com/zimfw/zimfw/tree/master/modules/syntax-highlighting), -make sure you place 'syntax-highlighting' before 'history-substring-search' on -the second line of `zmodules` in your `.zimrc`. - -Contributing ------------- - -Contributions should be submitted [upstream to -zsh-history-substring-search](https://github.com/zsh-users/zsh-history-substring-search). - -[example]: https://i.eriner.me/zim_history-substring-search.gif diff --git a/modules/history-substring-search/external b/modules/history-substring-search/external deleted file mode 160000 index 933733e..0000000 --- a/modules/history-substring-search/external +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 933733e86724a018cb98cb8f514fc3d323461f74 diff --git a/modules/history-substring-search/init.zsh b/modules/history-substring-search/init.zsh deleted file mode 100644 index 2d8ea43..0000000 --- a/modules/history-substring-search/init.zsh +++ /dev/null @@ -1,15 +0,0 @@ -# -# Enable searching history with substrings -# - -# Source script -source ${0:h}/external/zsh-history-substring-search.zsh || return 1 - -# Binding ^[[A/^[[B manually mean up/down works with history-substring-search both before and after zle-line-init -bindkey '^[[A' history-substring-search-up -bindkey '^[[B' history-substring-search-down - -# Bind up and down keys -zmodload -F zsh/terminfo +p:terminfo -bindkey "${terminfo[kcuu1]}" history-substring-search-up -bindkey "${terminfo[kcud1]}" history-substring-search-down diff --git a/modules/history/README.md b/modules/history/README.md deleted file mode 100644 index 7dad823..0000000 --- a/modules/history/README.md +++ /dev/null @@ -1,22 +0,0 @@ -history -======= - -Sets sane history options. - -The history is set to be saved in the `${ZDOTDIR:-${HOME}}/.zhistory` file. - -Zsh options ------------ - - * `BANG_HIST` performs csh-style '!' expansion. - * `SHARE_HISTORY` causes all terminals to share the same history 'session'. - * `HIST_IGNORE_DUPS` does not enter immediate duplicates into the history. - * `HIST_IGNORE_ALL_DUPS` removes older command from the history if a duplicate is to be added. - * `HIST_IGNORE_SPACE` removes commands from the history that begin with a space. - * `HIST_SAVE_NO_DUPS` ommits older commands that duplicate newer ones when saving. - * `HIST_VERIFY` doesn't execute the command directly upon history expansion. - -Aliases -------- - - * `history-stat` lists the 10 most used commands diff --git a/modules/history/init.zsh b/modules/history/init.zsh deleted file mode 100644 index 80e6a40..0000000 --- a/modules/history/init.zsh +++ /dev/null @@ -1,40 +0,0 @@ -# -# Configures history options -# - -# The file to save the history in. -HISTFILE="${ZDOTDIR:-${HOME}}/.zhistory" - -# The maximum number of events stored in the internal history list and in the history file. -HISTSIZE=10000 -SAVEHIST=10000 - -# Perform textual history expansion, csh-style, treating the character ‘!’ specially. -setopt BANG_HIST - -# This option both imports new commands from the history file, and also causes your -# typed commands to be appended to the history file (like specifying INC_APPEND_HISTORY). -# The history lines are also output with timestamps ala EXTENDED_HISTORY. -setopt SHARE_HISTORY - -# Do not enter command lines into the history list if they are duplicates of the previous event. -setopt HIST_IGNORE_DUPS - -# If a new command line being added to the history list duplicates an older one, -# the older command is removed from the list (even if it is not the previous event). -setopt HIST_IGNORE_ALL_DUPS - -# Remove command lines from the history list when the first character on the -# line is a space, or when one of the expanded aliases contains a leading space. -setopt HIST_IGNORE_SPACE - -# When writing out the history file, older commands that duplicate newer ones are omitted. -setopt HIST_SAVE_NO_DUPS - -# Whenever the user enters a line with history expansion, don't execute the line directly; -# instead, perform history expansion and reload the line into the editing buffer. -setopt HIST_VERIFY - - -# Lists the ten most used commands. -alias history-stat="fc -ln 0 | awk '{print \$1}' | sort | uniq -c | sort -nr | head" diff --git a/modules/input/README.md b/modules/input/README.md deleted file mode 100644 index a05ff46..0000000 --- a/modules/input/README.md +++ /dev/null @@ -1,11 +0,0 @@ -input -===== - -Applies correct bindkeys for input events. - -Without this module, you may experience oddities in how Zsh interprets input. -For example, pressing LEFT and then the DELETE key may capitalize characters -rather than delete them. - -This module also provides double-dot parent directory expansion. -It can be enabled by uncommenting `zdouble_dot_expand='true'` in your `.zimrc`. diff --git a/modules/input/init.zsh b/modules/input/init.zsh deleted file mode 100644 index e0962dc..0000000 --- a/modules/input/init.zsh +++ /dev/null @@ -1,106 +0,0 @@ -# -# Editor and input char assignment -# - - -# Return if requirements are not found. -if [[ ${TERM} == 'dumb' ]]; then - return 1 -fi - -# Use human-friendly identifiers. -zmodload -F zsh/terminfo +b:echoti +p:terminfo -typeset -gA key_info -key_info=( - 'Control' '\C-' - 'ControlLeft' '\e[1;5D \e[5D \e\e[D \eOd \eOD' - 'ControlRight' '\e[1;5C \e[5C \e\e[C \eOc \eOC' - 'Escape' '\e' - 'Meta' '\M-' - 'Backspace' "${terminfo[kbs]}" - 'BackTab' "${terminfo[kcbt]}" - 'Left' "${terminfo[kcub1]}" - 'Down' "${terminfo[kcud1]}" - 'Right' "${terminfo[kcuf1]}" - 'Up' "${terminfo[kcuu1]}" - 'Delete' "${terminfo[kdch1]}" - 'End' "${terminfo[kend]}" - 'F1' "${terminfo[kf1]}" - 'F2' "${terminfo[kf2]}" - 'F3' "${terminfo[kf3]}" - 'F4' "${terminfo[kf4]}" - 'F5' "${terminfo[kf5]}" - 'F6' "${terminfo[kf6]}" - 'F7' "${terminfo[kf7]}" - 'F8' "${terminfo[kf8]}" - 'F9' "${terminfo[kf9]}" - 'F10' "${terminfo[kf10]}" - 'F11' "${terminfo[kf11]}" - 'F12' "${terminfo[kf12]}" - 'Home' "${terminfo[khome]}" - 'Insert' "${terminfo[kich1]}" - 'PageDown' "${terminfo[knp]}" - 'PageUp' "${terminfo[kpp]}" -) - -# Bind the keys - -local key -for key (${(s: :)key_info[ControlLeft]}) bindkey ${key} backward-word -for key (${(s: :)key_info[ControlRight]}) bindkey ${key} forward-word - -[[ -n ${key_info[Home]} ]] && bindkey ${key_info[Home]} beginning-of-line -[[ -n ${key_info[End]} ]] && bindkey ${key_info[End]} end-of-line - -[[ -n ${key_info[PageUp]} ]] && bindkey ${key_info[PageUp]} up-line-or-history -[[ -n ${key_info[PageDown]} ]] && bindkey ${key_info[PageDown]} down-line-or-history - -[[ -n ${key_info[Insert]} ]] && bindkey ${key_info[Insert]} overwrite-mode - -if [[ ${zdouble_dot_expand} == 'true' ]]; then - double-dot-expand() { - if [[ ${LBUFFER} == *.. ]]; then - LBUFFER+='/..' - else - LBUFFER+='.' - fi - } - zle -N double-dot-expand - bindkey '.' double-dot-expand -fi - -[[ -n ${key_info[Backspace]} ]] && bindkey ${key_info[Backspace]} backward-delete-char -[[ -n ${key_info[Delete]} ]] && bindkey ${key_info[Delete]} delete-char - -[[ -n ${key_info[Left]} ]] && bindkey ${key_info[Left]} backward-char -[[ -n ${key_info[Right]} ]] && bindkey ${key_info[Right]} forward-char - -# Expandpace. -bindkey ' ' magic-space - -# Clear -bindkey "${key_info[Control]}L" clear-screen - -# Bind Shift + Tab to go to the previous menu item. -[[ -n ${key_info[BackTab]} ]] && bindkey ${key_info[BackTab]} reverse-menu-complete - -autoload -Uz is-at-least && if ! is-at-least 5.3; then - # Redisplay after completing, and avoid blank prompt after - expand-or-complete-with-redisplay() { - print -Pn '...' - zle expand-or-complete - zle redisplay - } - zle -N expand-or-complete-with-redisplay - bindkey "${key_info[Control]}I" expand-or-complete-with-redisplay -fi - -# Put into application mode and validate ${terminfo} -zle-line-init() { - (( ${+terminfo[smkx]} )) && echoti smkx -} -zle-line-finish() { - (( ${+terminfo[rmkx]} )) && echoti rmkx -} -zle -N zle-line-init -zle -N zle-line-finish diff --git a/modules/pacman/README.md b/modules/pacman/README.md deleted file mode 100644 index 588854c..0000000 --- a/modules/pacman/README.md +++ /dev/null @@ -1,61 +0,0 @@ -pacman -====== - -Adds aliases for the pacman package manager. - -Also includes optional helper(s). - -.zimrc Configuration -------------- - * `zpacman_frontend='helper_here'` Set helper_here to a wrapper if applicable (powerpill, pacmatic, etc). - * `zpacman_helper=(aur)` add/remove any helper scripts to be loaded here. - -Helpers -------- - -### aur - -provides simple AUR helper aliases. - - * `aurb package_name` clone the package from the AUR, build, and install. - * `aurd package_name` clone the package from the AUR, but do not build. - * `auru` run inside a directory created with `aurb`, this will update, build, and install a package. - -Aliases -------- - -### Build - - * `pacb` build package in the current directory, cleanup, and install. - -### Install - - * `paci` install, sync, and upgrade packages. - * `pacu` install, sync, and upgrade packages (forcibly refresh package list). - * `pacU` install packages from pkg file. - * `pacd` install all packages in current directory. - -### Remove - - * `pacr` remove package and unneeded dependencies. - * `pacrm` remove package, unneded dependencies, and configuration files. - -### Query - - * `pacq` query package information from remote repository - * `pacQ` query package information from local repository - -### Search - - * `pacs` search for package in the remote repository - * `pacS` search for package in the local repository - -### Orphans - - * `pacol` list orphan packages - * `pacor` remove all orphan packages - -### Ownership - - * `pacown` list all files provided by a given package - * `pacblame` show package(s) that own a specified file diff --git a/modules/pacman/functions/_pacman_frontend b/modules/pacman/functions/_pacman_frontend deleted file mode 100644 index 2f2bf71..0000000 --- a/modules/pacman/functions/_pacman_frontend +++ /dev/null @@ -1,3 +0,0 @@ -#compdef aurman packer wrapaur yaourt - -service=pacman; _pacman diff --git a/modules/pacman/helper_aur.zsh b/modules/pacman/helper_aur.zsh deleted file mode 100644 index 3d88883..0000000 --- a/modules/pacman/helper_aur.zsh +++ /dev/null @@ -1,20 +0,0 @@ -# -# AUR aliases -# - -# download and build AUR package -aurb() { - git clone https://aur.archlinux.org/${1}.git && cd ${1} && makepkg --clean --install --syncdeps -} - -# only download aur package; do not build -aurd() { - git clone https://aur.archlinux.org/${1}.git -} - -# remove old package, rebuild, and install. -#NOTE: this is will remove any unstashed/uncommitted changes. -# due to how makepkg will update the PKGBUILD, a git pull alone will not suffice. -auru() { - git reset HEAD --hard && git pull && makepkg --clean --force --install --syncdeps --cleanbuild -} diff --git a/modules/pacman/init.zsh b/modules/pacman/init.zsh deleted file mode 100644 index 397ae45..0000000 --- a/modules/pacman/init.zsh +++ /dev/null @@ -1,135 +0,0 @@ -# -# Pacman aliases -# - -# ${zpacman_frontend} is provided by either .zimrc or (if not set) init.zsh -# The zpacman_frontend is _only_ used for package installs. - -# -# Setup -# - -# ensure pacman is available -if (( ! ${+commands[pacman]} )); then - return 1 -fi - -local zpacman_frontend_priv helper - -if (( ! ${+zpacman_frontend} )); then - zpacman_frontend='pacman' - zpacman_frontend_priv='sudo pacman' -elif (( ! ${+commands[${zpacman_frontend}]} )); then - print "pacman frontend \"${zpacman_frontend}\" is invalid or not installed. Reverting to \"pacman\". -You can fix this error by editing the 'zpacman_frontend' variable in your .zimrc" >&2 - zpacman_frontend='pacman' - zpacman_frontend_priv='sudo pacman' -elif [[ ${zpacman_frontend} == ("yaourt"|"pacaur"|"yay"|"pikaur") ]]; then - # those AUR helpers handle SUID themselves - zpacman_frontend_priv="${zpacman_frontend}" -else - zpacman_frontend_priv="sudo ${zpacman_frontend}" -fi - - -# -# General -# - -alias pac=${zpacman_frontend} - -# -# Build -# - -# build package in current directory, cleanup, and install -alias pacb='makepkg -sci' - -# -# Install -# - -#NOTE: Installing/upgrading individual packages is NOT supported. Sync and upgrade ALL on install. - -# install, sync, and upgrade packages -alias paci="${zpacman_frontend_priv} -Syu" - -# install packages without syncing -alias pacI="${zpacman_frontend_priv} -S" - -# install, sync, and upgrade packages (forcibly refresh package lists) -alias pacu="${zpacman_frontend_priv} -Syyu" - -# install packages by filename -alias pacU="${zpacman_frontend_priv} -U" - -# install all packages in current directory -alias pacd="${zpacman_frontend_priv} -U *.pkg.*" - - -# -# Remove -# - -# remove package and unneeded dependencies -alias pacr="${zpacman_frontend_priv} -R" - -# remove package, unneeded dependencies, and configuration files -alias pacrm="${zpacman_frontend_priv} -Rns" - - -# -# Query -# - -# query package information from the remote repository -alias pacq="${zpacman_frontend} -Si" - -# query package information from the local repository -alias pacQ="${zpacman_frontend} -Qi" - - -# -# Search -# - -# search for package in the remote repository -alias pacs="${zpacman_frontend} -Ss" - -# search for the package in the local repository -alias pacS="${zpacman_frontend} -Qs" - - -# -# Orphans -# - -# list orphan packages -alias pacol="${zpacman_frontend} -Qdt" - -# remove orphan packages -alias pacor="${zpacman_frontend_priv} -Rns \$(pacman -Qtdq)" - - -# -# Ownership -# - -# list all files that belong to a package -alias pacown="${zpacman_frontend} -Ql" - -# show package(s) owning the specified file -alias pacblame="${zpacman_frontend} -Qo" - -# -# Helpers -# - -# source helper functions/aliases -for helper in ${zpacman_helper}; do - if [[ -s ${0:h}/helper_${helper}.zsh ]]; then - source ${0:h}/helper_${helper}.zsh - else - print "no such helper script \"helper_${helper}.zsh\"" >&2 - fi -done diff --git a/modules/prompt/README.md b/modules/prompt/README.md deleted file mode 100644 index 0f0270c..0000000 --- a/modules/prompt/README.md +++ /dev/null @@ -1,15 +0,0 @@ -prompt -====== - -Initializes and provides customizable prompt themes. - -Images of various prompt themes can be found on the [wiki](https://github.com/zimfw/zimfw/wiki/Themes). - -A list of available prompts can be found by running `prompt -l`. - -To test a prompt, simply run `prompt prompt_name_here`. - -.zimrc Configuration --------------------- - - * `zprompt_theme='eriner'` change 'eriner' to the name of your desired prompt. This will set it as you default prompt. diff --git a/modules/prompt/external-themes/lean b/modules/prompt/external-themes/lean deleted file mode 160000 index 3cf61b2..0000000 --- a/modules/prompt/external-themes/lean +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3cf61b240d0bb0e3d1c517d2324534ddbf3614e8 diff --git a/modules/prompt/external-themes/liquidprompt b/modules/prompt/external-themes/liquidprompt deleted file mode 160000 index 9c80396..0000000 --- a/modules/prompt/external-themes/liquidprompt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9c80396021a8106bfaeade9a1ea51b85152e951d diff --git a/modules/prompt/external-themes/pure b/modules/prompt/external-themes/pure deleted file mode 160000 index 7aade5f..0000000 --- a/modules/prompt/external-themes/pure +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7aade5fca2acae3f10e260d0c076af6356da9dc6 diff --git a/modules/prompt/functions/async b/modules/prompt/functions/async deleted file mode 120000 index 0429419..0000000 --- a/modules/prompt/functions/async +++ /dev/null @@ -1 +0,0 @@ -../external-themes/pure/async.zsh \ No newline at end of file diff --git a/modules/prompt/functions/ext-liquidprompt b/modules/prompt/functions/ext-liquidprompt deleted file mode 120000 index 588a0c8..0000000 --- a/modules/prompt/functions/ext-liquidprompt +++ /dev/null @@ -1 +0,0 @@ -../external-themes/liquidprompt/liquidprompt \ No newline at end of file diff --git a/modules/prompt/functions/prompt_eriner_setup b/modules/prompt/functions/prompt_eriner_setup deleted file mode 120000 index d727475..0000000 --- a/modules/prompt/functions/prompt_eriner_setup +++ /dev/null @@ -1 +0,0 @@ -../themes/eriner.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/prompt_gitster_setup b/modules/prompt/functions/prompt_gitster_setup deleted file mode 120000 index a818a68..0000000 --- a/modules/prompt/functions/prompt_gitster_setup +++ /dev/null @@ -1 +0,0 @@ -../themes/gitster.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/prompt_lean_setup b/modules/prompt/functions/prompt_lean_setup deleted file mode 120000 index 13294d9..0000000 --- a/modules/prompt/functions/prompt_lean_setup +++ /dev/null @@ -1 +0,0 @@ -../external-themes/lean/prompt_lean_setup \ No newline at end of file diff --git a/modules/prompt/functions/prompt_liquidprompt_setup b/modules/prompt/functions/prompt_liquidprompt_setup deleted file mode 100644 index fa2b0b1..0000000 --- a/modules/prompt/functions/prompt_liquidprompt_setup +++ /dev/null @@ -1,12 +0,0 @@ -prompt_liquidprompt_setup() { - autoload -Uz ex-liquidprompt - ext-liquidprompt -} - -prompt_liquidprompt_preview() { - _lp_set_prompt - prompt_preview_theme liquidprompt - prompt_off -} - -prompt_liquidprompt_setup "$@" diff --git a/modules/prompt/functions/prompt_magicmace_setup b/modules/prompt/functions/prompt_magicmace_setup deleted file mode 120000 index cafc569..0000000 --- a/modules/prompt/functions/prompt_magicmace_setup +++ /dev/null @@ -1 +0,0 @@ -../themes/magicmace.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/prompt_minimal_setup b/modules/prompt/functions/prompt_minimal_setup deleted file mode 120000 index 7e226df..0000000 --- a/modules/prompt/functions/prompt_minimal_setup +++ /dev/null @@ -1 +0,0 @@ -../themes/minimal.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/prompt_pure_setup b/modules/prompt/functions/prompt_pure_setup deleted file mode 120000 index 30f245d..0000000 --- a/modules/prompt/functions/prompt_pure_setup +++ /dev/null @@ -1 +0,0 @@ -../external-themes/pure/pure.zsh \ No newline at end of file diff --git a/modules/prompt/functions/prompt_steeef_setup b/modules/prompt/functions/prompt_steeef_setup deleted file mode 120000 index c2abe5e..0000000 --- a/modules/prompt/functions/prompt_steeef_setup +++ /dev/null @@ -1 +0,0 @@ -../themes/steeef.zsh-theme \ No newline at end of file diff --git a/modules/prompt/functions/short_pwd b/modules/prompt/functions/short_pwd deleted file mode 100644 index d110933..0000000 --- a/modules/prompt/functions/short_pwd +++ /dev/null @@ -1,10 +0,0 @@ -# shortens the pwd for use in prompt - -local current_dir="${${1:-${PWD}}/#${HOME}/~}" - -# if we aren't in ~ -if [[ ${current_dir} != '~' ]]; then - current_dir="${${${${(@j:/:M)${(@s:/:)current_dir}##.#?}:h}%/}//\%/%%}/${${current_dir:t}//\%/%%}" -fi - -print ${current_dir} diff --git a/modules/prompt/init.zsh b/modules/prompt/init.zsh deleted file mode 100644 index f3f5e8d..0000000 --- a/modules/prompt/init.zsh +++ /dev/null @@ -1,8 +0,0 @@ -# -# load user-defined prompt -# - -if [[ ! ${TERM} == (linux|*bsd*|dumb) ]] && (( ${+zprompt_theme} )); then - autoload -Uz promptinit && promptinit - prompt ${(ps: :)${zprompt_theme}} -fi diff --git a/modules/prompt/themes/eriner.zsh-theme b/modules/prompt/themes/eriner.zsh-theme deleted file mode 100644 index 68ac756..0000000 --- a/modules/prompt/themes/eriner.zsh-theme +++ /dev/null @@ -1,140 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# -# Eriner's Theme - fork of agnoster -# A Powerline-inspired theme for ZSH -# -# In order for this theme to render correctly, a font with Powerline symbols is -# required. A simple way to install a font with Powerline symbols is to follow -# the instructions here: https://github.com/powerline/fonts#installation -# -# The aim of this theme is to only show you *relevant* information. Like most -# prompts, it will only show git information when in a git working directory. -# However, it goes a step further: everything from the current user and -# hostname to whether the last call exited with an error to whether background -# jobs are running in this shell will all be displayed automatically when -# appropriate. -# -# Requires the `git-info` zmodule to be included in the .zimrc file. - -prompt_eriner_help () { - cat < /dev/null) && prompt_short_dir=${prompt_short_dir#${$(short_pwd $git_root):h}/} - print -n "%F{white}${prompt_short_dir}" -} - -prompt_gitster_git() { - [[ -n ${git_info} ]] && print -n "${(e)git_info[prompt]}" -} - -prompt_gitster_precmd() { - (( ${+functions[git-info]} )) && git-info -} - -prompt_gitster_setup() { - local prompt_gitster_status='%(?:%F{green}:%F{red})➜ ' - - autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_gitster_precmd - - prompt_opts=(cr percent sp subst) - - zstyle ':zim:git-info:branch' format '%b' - zstyle ':zim:git-info:commit' format '%c' - zstyle ':zim:git-info:clean' format '%F{green}✓' - zstyle ':zim:git-info:dirty' format '%F{yellow}✗' - zstyle ':zim:git-info:keys' format \ - 'prompt' ' %F{cyan}%b%c %C%D' - - PS1="${prompt_gitster_status}\$(prompt_gitster_pwd)\$(prompt_gitster_git)%f " - RPS1='' -} - -prompt_gitster_setup "${@}" diff --git a/modules/prompt/themes/magicmace.zsh-theme b/modules/prompt/themes/magicmace.zsh-theme deleted file mode 100644 index 1cceb34..0000000 --- a/modules/prompt/themes/magicmace.zsh-theme +++ /dev/null @@ -1,72 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# -# magicmace theme -# Ideas and code taken from: -# xero's zsh prompt -# eriner's eriner prompt -# -# Requires the `git-info` zmodule to be included in the .zimrc file. - -# Global variables -function { - COLOR_ROOT="%F{red}" - COLOR_USER="%F{cyan}" - COLOR_NORMAL="%F{white}" - COLOR_ERROR="%F{red}" - - if (( ${EUID} )); then - COLOR_USER_LEVEL=${COLOR_USER} - else - COLOR_USER_LEVEL=${COLOR_ROOT} - fi -} - -# Status: -# - was there an error? -# - are there background jobs? -# - are we in a ranger session? -prompt_magicmace_status() { - local symbols="" - - (( ${RETVAL} )) && symbols+="${COLOR_ERROR}${RETVAL}${COLOR_NORMAL}" # $? for error. - (( $(jobs -l | wc -l) > 0 )) && symbols+='b' # 'b' for background. - (( ${RANGER_LEVEL} )) && symbols+='r' # 'r' for... you guessed it! - - [[ -n ${symbols} ]] && print -n "─${COLOR_NORMAL}${symbols}${COLOR_USER_LEVEL}─" -} - -prompt_magicmace_git() { - [[ -n ${git_info} ]] && print -n "${(e)git_info[prompt]}" -} - -prompt_magicmace_precmd() { - # While it would be apt to have this as a local variable in prompt_status(), - # $? (returned value) and ${(%):-%?} ("The return status of the last command - # executed just before the prompt") both change before executing the function. - # Is this perhaps because prompt_status _is_ here? - # We could also just set $? as an argument, and thus get our nifty local variable, - # but that's stretching it, and makes the code harder to read. - RETVAL=$? - (( ${+functions[git-info]} )) && git-info -} - -prompt_magicmace_setup() { - autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_magicmace_precmd - autoload -Uz colors && colors - - prompt_opts=(cr percent sp subst) - - zstyle ':zim:git-info:branch' format '%b' - zstyle ':zim:git-info:commit' format '%c...' - zstyle ':zim:git-info:dirty' format '*' - zstyle ':zim:git-info:ahead' format '↑' - zstyle ':zim:git-info:behind' format '↓' - zstyle ':zim:git-info:keys' format \ - 'prompt' '─[${COLOR_NORMAL}%b%c%D%A%B${COLOR_USER_LEVEL}]' - - # Call git directly, ignoring aliases under the same name. - PS1='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]$(prompt_magicmace_git)── ─%f ' - RPS1='' -} - -prompt_magicmace_setup "${@}" diff --git a/modules/prompt/themes/minimal.zsh-theme b/modules/prompt/themes/minimal.zsh-theme deleted file mode 100644 index de10543..0000000 --- a/modules/prompt/themes/minimal.zsh-theme +++ /dev/null @@ -1,88 +0,0 @@ -# -# Minimal theme -# https://github.com/S1cK94/minimal -# -# Requires the `git-info` zmodule to be included in the .zimrc file. - -# Global variables -function { - PROMPT_CHAR='❯' - - ON_COLOR='%F{green}' - OFF_COLOR='%f' - ERR_COLOR='%F{red}' -} - -prompt_minimal_user() { - print -n '%(!.${ON_COLOR}.${OFF_COLOR})${PROMPT_CHAR}' -} - -prompt_minimal_jobs() { - print -n '%(1j.${ON_COLOR}.${OFF_COLOR})${PROMPT_CHAR}' -} - -prompt_minimal_vimode() { - local color - - case ${KEYMAP} in - main|viins) - color=${ON_COLOR} - ;; - *) - color=${OFF_COLOR} - ;; - esac - - print -n "${color}${PROMPT_CHAR}" -} - -prompt_minimal_status() { - print -n '%(0?.${ON_COLOR}.${ERR_COLOR})${PROMPT_CHAR}' -} - -prompt_minimal_path() { - local path_color='%F{244}' - print -n "${path_color}${$(short_pwd)//\//%f\/${path_color}}%f" -} - -prompt_minimal_git() { - if [[ -n ${git_info} ]]; then - print -n " ${(e)git_info[color]}${(e)git_info[prompt]}" - fi -} - -function zle-line-init zle-keymap-select { - zle reset-prompt - zle -R -} - -prompt_minimal_precmd() { - (( ${+functions[git-info]} )) && git-info -} - -prompt_minimal_setup() { - zle -N zle-line-init - zle -N zle-keymap-select - - autoload -Uz colors && colors - autoload -Uz add-zsh-hook - - prompt_opts=(cr percent sp subst) - - add-zsh-hook precmd prompt_minimal_precmd - - zstyle ':zim:git-info:branch' format '%b' - zstyle ':zim:git-info:commit' format '%c' - zstyle ':zim:git-info:dirty' format '${ERR_COLOR}' - zstyle ':zim:git-info:diverged' format '${ERR_COLOR}' - zstyle ':zim:git-info:behind' format '%F{11}' - zstyle ':zim:git-info:ahead' format '${OFF_COLOR}' - zstyle ':zim:git-info:keys' format \ - 'prompt' '%b%c' \ - 'color' '$(coalesce "%D" "%V" "%B" "%A" "${ON_COLOR}")' - - PROMPT="$(prompt_minimal_user)$(prompt_minimal_jobs)\$(prompt_minimal_vimode)$(prompt_minimal_status)%f " - RPROMPT='$(prompt_minimal_path)$(prompt_minimal_git)' -} - -prompt_minimal_setup "$@" diff --git a/modules/prompt/themes/steeef.zsh-theme b/modules/prompt/themes/steeef.zsh-theme deleted file mode 100644 index 344edcb..0000000 --- a/modules/prompt/themes/steeef.zsh-theme +++ /dev/null @@ -1,116 +0,0 @@ -# vim:et sts=2 sw=2 ft=zsh -# -# A customizable version of the steeef theme from -# https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/steeef.zsh-theme -# -# Requires the `git-info` zmodule to be included in the .zimrc file. - -prompt_steeef_help () { - cat <= 256 )); then - col_user="%F{${1:-135}}" - col_host="%F{${2:-166}}" - col_pwd="%F{${3:-118}}" - col_brnch="%F{${4:-81}}" - col_unidx="%F{${5:-166}}" - col_idx="%F{${7:-118}}" - col_untrk="%F{${9:-161}}" - else - col_user="%F{${1:-magenta}}" - col_host="%F{${2:-yellow}}" - col_pwd="%F{${3:-green}}" - col_brnch="%F{${4:-cyan}}" - col_unidx="%F{${5:-yellow}}" - col_idx="%F{${7:-green}}" - col_untrk="%F{${9:-red}}" - fi - local ind_unidx=${6:-●} - local ind_idx=${8:-●} - local ind_untrk=${10:-●} - local col_stash=${11:+%F{${11}}} - local ind_stash=${12} - - autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_steeef_precmd - - prompt_opts=(cr percent sp subst) - - zstyle ':zim:git-info' verbose 'yes' - zstyle ':zim:git-info:branch' format '%b' - zstyle ':zim:git-info:commit' format '%c' - zstyle ':zim:git-info:action' format "(${col_idx}%s%f)" - zstyle ':zim:git-info:unindexed' format "${col_unidx}${ind_unidx}" - zstyle ':zim:git-info:indexed' format "${col_idx}${ind_idx}" - zstyle ':zim:git-info:untracked' format "${col_untrk}${ind_untrk}" - if [[ -n ${ind_stash} ]]; then - zstyle ':zim:git-info:stashed' format "${col_stash}${ind_stash}" - fi - zstyle ':zim:git-info:keys' format \ - 'prompt' "(${col_brnch}%b%c%I%i%u%f%S%f)%s" - - PS1=" -${col_user}%n%f at ${col_host}%m%f in ${col_pwd}%~%f\$(prompt_steeef_git)\$(prompt_steeef_virtualenv) -%(!.#.$) " - RPS1='' -} - -prompt_steeef_preview () { - if (( ${#} )); then - prompt_preview_theme steeef "${@}" - else - prompt_preview_theme steeef - print - prompt_preview_theme steeef magenta yellow green cyan magenta '!' green '+' red '?' yellow '$' - fi -} - -prompt_steeef_setup "${@}" diff --git a/modules/ssh/README.md b/modules/ssh/README.md deleted file mode 100644 index 30195bc..0000000 --- a/modules/ssh/README.md +++ /dev/null @@ -1,9 +0,0 @@ -ssh -=== - -Provides a convenient way to load ssh-agent. This enables one-time login and caching of SSH credentials per session. - -.zimrc Configuration --------------------- - - * `zssh_ids=(id_rsa)` add any identities (from ~/.ssh) to this list to have them loaded and cached on login. diff --git a/modules/ssh/init.zsh b/modules/ssh/init.zsh deleted file mode 100644 index 0b6b735..0000000 --- a/modules/ssh/init.zsh +++ /dev/null @@ -1,34 +0,0 @@ -# -# sets up ssh-agent -# - -# don't do anything unless we can actually use ssh-agent -if (( ! ${+commands[ssh-agent]} )); then - return 1 -fi - -ssh-add -l &>/dev/null -if (( ? == 2 )); then - # Unable to contact the authentication agent - - # Load stored agent connection info - local ssh_env="${HOME}/.ssh-agent" - [[ -r ${ssh_env} ]] && source ${ssh_env} >/dev/null - - ssh-add -l &>/dev/null - if (( ? == 2 )); then - # Start agent and store agent connection info - (umask 066; ssh-agent >! ${ssh_env}) - source ${ssh_env} >/dev/null - fi -fi - -# Load identities -ssh-add -l &>/dev/null -if (( ? == 1 )); then - if (( ${#zssh_ids} > 0 )); then - ssh-add "${HOME}/.ssh/${^zssh_ids[@]}" 2> /dev/null - else - ssh-add 2> /dev/null - fi -fi diff --git a/modules/syntax-highlighting/README.md b/modules/syntax-highlighting/README.md deleted file mode 100644 index d9ae4df..0000000 --- a/modules/syntax-highlighting/README.md +++ /dev/null @@ -1,21 +0,0 @@ -syntax-highlighting -=================== - -Adds fish shell-like [syntax highlighting](https://github.com/zsh-users/zsh-syntax-highlighting) to your shell. - -![syntax-highlighting][syntax_highlighting] - -If you are also using [history-substring-search](https://github.com/zimfw/zimfw/blob/master/modules/history-substring-search/README.md), -ensure you have placed 'syntax-highlighting' before 'history-substring-search' on the second line of `zmodules` in your `.zimrc`. - -.zimrc Configuration --------------------- - - * `zhighlighters=(main brackets cursor)` add any highlighters you want as described [here](https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md#zsh-syntax-highlighting--highlighters). - -Contributing ------------- - -Contributions should be submitted [upstream to zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting) - -[syntax_highlighting]: https://i.eriner.me/zim_syntax-highlighting.gif diff --git a/modules/syntax-highlighting/external b/modules/syntax-highlighting/external deleted file mode 160000 index 434af7b..0000000 --- a/modules/syntax-highlighting/external +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 434af7b11dd33641231f1b48b8432e68eb472e46 diff --git a/modules/syntax-highlighting/init.zsh b/modules/syntax-highlighting/init.zsh deleted file mode 100644 index 6dddf5e..0000000 --- a/modules/syntax-highlighting/init.zsh +++ /dev/null @@ -1,8 +0,0 @@ -# -# enables fish-shell like syntax highlighting -# - -# highlighters -ZSH_HIGHLIGHT_HIGHLIGHTERS=(${zhighlighters[@]}) - -source "${0:h}/external/zsh-syntax-highlighting.zsh" || return 1 diff --git a/modules/utility/README.md b/modules/utility/README.md deleted file mode 100644 index 8a8cfde..0000000 --- a/modules/utility/README.md +++ /dev/null @@ -1,40 +0,0 @@ -utility -======= - -Utility aliases and functions. - -Adds colour to `ls`, `grep` and `less`. - -Aliases -------- - -### ls - - * `ls` lists directories first (GNU only) and with colour (applies to all aliases below). - * `ll` lists with long format and human-readable sizes (applies to all aliases below). - * `l` lists all files. - * `lm` lists all files using pager. - * `lr` lists recursively. - * `lx` lists sorted by extension (GNU only). - * `lk` lists sorted by largest file size last. - * `lt` lists sorted by newest modification time last. - * `lc` lists sorted by newest status change (ctime) last. - -### File downloads - - * `get` is short for ( `aria2c` || `axel` || `wget` || `curl` ). - -### Resource usage - - * `df` reports file system disk usage with human-readable sizes. - * `du` reports file disk usage with human-readable sizes. - -### Condoms - - * `chmod` changes file mode verbosely, not operating from `/` (GNU only). - * `chown` changes file owner verbosely, not operating from `/` (GNU only). - * `rm` uses `safe-rm` if available. - -### Misc - - * `mkcd` creates and changes to the given directory. diff --git a/modules/utility/functions/mkcd b/modules/utility/functions/mkcd deleted file mode 100644 index 4f795ce..0000000 --- a/modules/utility/functions/mkcd +++ /dev/null @@ -1 +0,0 @@ -[[ -n ${1} ]] && mkdir -p ${1} && builtin cd ${1} diff --git a/modules/utility/init.zsh b/modules/utility/init.zsh deleted file mode 100644 index b998cc0..0000000 --- a/modules/utility/init.zsh +++ /dev/null @@ -1,111 +0,0 @@ -# -# Utility Functions and Options -# - -# -# Colours -# - -if (( terminfo[colors] >= 8 )); then - - # ls Colours - if (( ${+commands[dircolors]} )); then - # GNU - - (( ! ${+LS_COLORS} )) && if [[ -s ${HOME}/.dir_colors ]]; then - eval "$(dircolors --sh ${HOME}/.dir_colors)" - else - export LS_COLORS='di=1;34:ln=35:so=32:pi=33:ex=31:bd=1;36:cd=1;33:su=30;41:sg=30;46:tw=30;42:ow=30;43' - fi - - alias ls='ls --group-directories-first --color=auto' - else - # BSD - - (( ! ${+CLICOLOR} )) && export CLICOLOR=1 - (( ! ${+LSCOLORS} )) && export LSCOLORS='ExfxcxdxbxGxDxabagacad' - - # stock OpenBSD ls does not support colors at all, but colorls does. - if [[ ${OSTYPE} == openbsd* && ${+commands[colorls]} -ne 0 ]]; then - alias ls='colorls' - fi - fi - - # grep Colours - (( ! ${+GREP_COLOR} )) && export GREP_COLOR='37;45' #BSD - (( ! ${+GREP_COLORS} )) && export GREP_COLORS="mt=${GREP_COLOR}" #GNU - if [[ ${OSTYPE} == openbsd* ]]; then - (( ${+commands[ggrep]} )) && alias grep='ggrep --color=auto' - else - alias grep='grep --color=auto' - fi - - # less Colours - if [[ ${PAGER} == 'less' ]]; then - (( ! ${+LESS_TERMCAP_mb} )) && export LESS_TERMCAP_mb=$'\E[1;31m' # Begins blinking. - (( ! ${+LESS_TERMCAP_md} )) && export LESS_TERMCAP_md=$'\E[1;31m' # Begins bold. - (( ! ${+LESS_TERMCAP_me} )) && export LESS_TERMCAP_me=$'\E[0m' # Ends mode. - (( ! ${+LESS_TERMCAP_se} )) && export LESS_TERMCAP_se=$'\E[0m' # Ends standout-mode. - (( ! ${+LESS_TERMCAP_so} )) && export LESS_TERMCAP_so=$'\E[7m' # Begins standout-mode. - (( ! ${+LESS_TERMCAP_ue} )) && export LESS_TERMCAP_ue=$'\E[0m' # Ends underline. - (( ! ${+LESS_TERMCAP_us} )) && export LESS_TERMCAP_us=$'\E[1;32m' # Begins underline. - fi -fi - - -# -# ls Aliases -# - -alias ll='ls -lh' # long format and human-readable sizes -alias l='ll -A' # long format, all files -[[ -n ${PAGER} ]] && alias lm="l | ${PAGER}" # long format, all files, use pager -alias lr='ll -R' # long format, recursive -alias lk='ll -Sr' # long format, largest file size last -alias lt='ll -tr' # long format, newest modification time last -alias lc='lt -c' # long format, newest status change (ctime) last - - -# -# File Downloads -# - -# order of preference: aria2c, axel, wget, curl. This order is derrived from speed based on personal tests. -if (( ${+commands[aria2c]} )); then - alias get='aria2c --max-connection-per-server=5 --continue' -elif (( ${+commands[axel]} )); then - alias get='axel --num-connections=5 --alternate' -elif (( ${+commands[wget]} )); then - alias get='wget --continue --progress=bar --timestamping' -elif (( ${+commands[curl]} )); then - alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time' -fi - - -# -# Resource Usage -# - -alias df='df -h' -alias du='du -h' - - -# -# GNU only -# - -if (( ${+commands[dircolors]} )); then - - alias lx='ll -X' # long format, sort by extension - - # Always wear a condom - alias chmod='chmod --preserve-root -v' - alias chown='chown --preserve-root -v' -fi - - -# not aliasing rm -i, but if safe-rm is available, use condom. -# if safe-rmdir is available, the OS is suse which has its own terrible 'safe-rm' which is not what we want -if (( ${+commands[safe-rm]} && ! ${+commands[safe-rmdir]} )); then - alias rm='safe-rm' -fi diff --git a/templates/zimrc b/templates/zimrc index b6e70c6..b86ec39 100644 --- a/templates/zimrc +++ b/templates/zimrc @@ -1,96 +1,113 @@ -################# -# CORE SETTINGS # -################# +################ +# ZIM SETTINGS # +################ -# -# Zim settings -# +# Set input mode to 'emacs' (default) or 'vi'. +#zstyle ':zim:input' mode 'vi' -# Select what modules you would like enabled. -# The second line of modules may depend on options set by modules in the first -# line. These dependencies are noted on the respective module's README.md. -zmodules=(directory environment git git-info history input utility custom \ - prompt completion syntax-highlighting history-substring-search ) +# Select what modules you would like enabled. Modules are sourced in the order given. +zstyle ':zim' modules \ + directory environment git git-info history input utility \ + eriner gitster magicmace s1ck94 steeef prompt \ + zsh-completions completion zsh-autosuggestions zsh-syntax-highlighting history-substring-search +# Modules setup configuration. +# See ... +zstyle ':zim:module' zsh-completions 'url' 'zsh-users/zsh-completions' +zstyle ':zim:module' zsh-autosuggestions 'url' 'zsh-users/zsh-autosuggestions' +zstyle ':zim:module' zsh-syntax-highlighting 'url' 'zsh-users/zsh-syntax-highlighting' ################### # MODULE SETTINGS # ################### # -# Prompt +# completion # -# Set your desired prompt here -zprompt_theme='steeef' +# Set a custom path for the completion dump file. +# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zcompdump is used. +#zstyle ':zim:completion' dumpfile "${ZDOTDIR:-${HOME}}/.zcompdump-${ZSH_VERSION}" # -# Completion -# - -# Set an optional host-specific filename for the completion cache file. If none -# is provided, the default '.zcompdump' is used. -#zcompdump_file=".zcompdump-${HOST}-${ZSH_VERSION}" - -# -# Utility -# - -# Uncomment to enable spelling correction prompt for commands. See: -# http://zsh.sourceforge.net/Doc/Release/Options.html#Input_002fOutput -#setopt CORRECT - -# Set custom spelling correction prompt -#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' - -# -# Environment +# environment # # Set the string below to the desired terminal title format string. -# The terminal title is redrawn upon directory change, however, variables like -# ${PWD} are only evaluated once. Use prompt expansion strings for dynamic data: -# http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes -# The example below uses the following format: 'username@host:/current/directory' -ztermtitle='%n@%m:%~' +# The terminal title is redrawn upon directory change, however, variables like +# ${PWD} are only evaluated once. Use prompt expansion strings for dynamic data. +# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes +# For example, '%n@%m: %1~' corresponds to 'username@host: /current/directory'. +#zstyle ':zim:environment' termtitle '%n@%m: %1~' # -# Input +# history # -# Set to vi or emacs -zinput_mode='emacs' - -# Uncomment to enable double-dot expansion. This appends '../' to your input for -# each '.' you type after an initial '..' -#zdouble_dot_expand='true' +# Save the history in a custom file path. +# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zhistory is used. +#HISTFILE=${ZDOTDIR:-${HOME}}/.zsh_history # -# Syntax-Highlighting +# input # -# This determines what highlighters will be used with the syntax-highlighting module. -# Documentation of the highlighters can be found here: -# https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md -# For (u)rxvt, termite and gnome-terminal users, -# removing the 'cursor' highlighter will fix the disappearing cursor problem -zhighlighters=(main brackets cursor) +# Enable double-dot expansion. +# This appends '../' to your input for each '.' you type after an initial '..' +#zstyle ':zim:input' double-dot-expand yes # -# SSH +# pacman # -# Load these ssh identities with the ssh module -#zssh_ids=(id_rsa) +# Set an optional pacman frontend. +#zstyle ':zim:pacman' frontend 'powerpill' + +# Load any helper scripts as defined here. +#zstyle ':zim:pacman' helpers 'aur' # -# Pacman +# prompt # -# Set (optional) pacman front-end. -#zpacman_frontend='powerpill' +# Set your desired prompt theme. +zstyle ':zim:prompt' theme 'steeef' -# Load any helper scripts as defined here -#zpacman_helper=(aur) +# +# ssh +# +# Load these ssh identities with the ssh module. +#zstyle ':zim:ssh' ids 'id_rsa' +# +# utility +# + +# Enable spelling correction prompts. +# See http://zsh.sourceforge.net/Doc/Release/Options.html#index-CORRECT +#setopt CORRECT + +# Set a custom spelling correction prompt. +#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' + +# +# zsh-autosuggestions +# + +# Customize the style that the suggestions are shown with. +# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style +#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10' + +# +# zsh-syntax-highlighting +# + +# Set what highlighters will be used. +# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md +ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) + +# Customize the main highlighter styles. +# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it +#typeset -A ZSH_HIGHLIGHT_STYLES +#ZSH_HIGHLIGHT_STYLES[comment]='fg=10' diff --git a/templates/zlogin b/templates/zlogin index d174793..231607b 100644 --- a/templates/zlogin +++ b/templates/zlogin @@ -2,6 +2,6 @@ # User configuration sourced by login shells # -# Initialize zim +# Initialize Zim [[ -s ${ZIM_HOME}/login_init.zsh ]] && source ${ZIM_HOME}/login_init.zsh diff --git a/templates/zshrc b/templates/zshrc index 4e84ff1..159c7ee 100644 --- a/templates/zshrc +++ b/templates/zshrc @@ -2,9 +2,9 @@ # User configuration sourced by interactive shells # -# Define zim location -export ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim +# Define Zim location +ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim -# Start zim +# Start Zim [[ -s ${ZIM_HOME}/init.zsh ]] && source ${ZIM_HOME}/init.zsh diff --git a/tools/clean-compiled.zsh b/tools/clean-compiled.zsh new file mode 100644 index 0000000..56e96db --- /dev/null +++ b/tools/clean-compiled.zsh @@ -0,0 +1,11 @@ +setopt LOCAL_OPTIONS PIPE_FAIL +local find_opt rm_opt +if [[ ${1} != -q ]]; then + find_opt='-print' + rm_opt='-v' +fi +command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${find_opt} || return 1 +command rm -f ${rm_opt} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 +if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with ${0:t:r}. Run %Bzimfw compile%b to re-compile." +fi diff --git a/tools/clean-dumpfile.zsh b/tools/clean-dumpfile.zsh new file mode 100644 index 0000000..25e25ef --- /dev/null +++ b/tools/clean-dumpfile.zsh @@ -0,0 +1,8 @@ +setopt LOCAL_OPTIONS PIPE_FAIL +local zdumpfile zout zopt +zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" +[[ ${1} != -q ]] && zopt='-v' +command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 +if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with ${0:t:r}. Restart your terminal to dump an updated configuration." +fi diff --git a/tools/clean-modules.zsh b/tools/clean-modules.zsh new file mode 100644 index 0000000..c192d9b --- /dev/null +++ b/tools/clean-modules.zsh @@ -0,0 +1,19 @@ +local zdir zmodule +local -a zmodules +local -A zoptions +# Source .zimrc to refresh zmodules +[[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc +zstyle -a ':zim' modules 'zmodules' +for zdir in ${ZIM_HOME}/modules/*(/N); do + zmodule=${zdir:t} + # If zmodules does not contain the zmodule + if (( ! ${zmodules[(I)${zmodule}]} )); then + zstyle -a ':zim:module' ${zmodule} 'zoptions' + [[ ${zoptions[frozen]} == yes ]] && continue + command rm -rf ${zdir} || return 1 + [[ ${1} != -q ]] && print ${zdir} + fi +done +if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with ${0:t:r}." +fi diff --git a/tools/info.zsh b/tools/info.zsh new file mode 100644 index 0000000..5263168 --- /dev/null +++ b/tools/info.zsh @@ -0,0 +1,3 @@ +print "Zim commit ref: $(builtin cd ${ZIM_HOME} && command git rev-parse --short HEAD)" +print "Zsh version: ${ZSH_VERSION}" +print "System info: $(command uname -a)" diff --git a/tools/install.zsh b/tools/install.zsh new file mode 100644 index 0000000..02dcde7 --- /dev/null +++ b/tools/install.zsh @@ -0,0 +1,18 @@ +# This runs in a new shell +URL=${1} +DIR=${2} +REV=${4} +OPT=${5} +MODULE=${DIR:t} +if [[ -e ${DIR} ]]; then + # Already exists + return 0 +fi +if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then + if [[ ${OPT} != -q ]]; then + print -P "%F{green}✓%f ${MODULE}: Installed" + fi +else + print -P "%F{red}✗ ${MODULE}: Error%f\n${ERR}" + return 1 +fi diff --git a/tools/modules.zsh b/tools/modules.zsh new file mode 100644 index 0000000..3f5572b --- /dev/null +++ b/tools/modules.zsh @@ -0,0 +1,25 @@ +local zmodule zurl ztype zrev +local -a zmodules +local -A zoptions +zstyle -a ':zim' modules 'zmodules' +for zmodule in ${zmodules}; do + zstyle -a ':zim:module' ${zmodule} 'zoptions' + [[ ${zoptions[frozen]} == yes ]] && continue + zurl=${zoptions[url]:-${zmodule}} + if [[ ${zurl} != /* && ${zurl} != *@*:* ]]; then + # Count number of slashes + case ${#zurl//[^\/]/} in + 0) zurl="https://github.com/zimfw/${zurl}.git" ;; + 1) zurl="https://github.com/${zurl}.git" ;; + esac + fi + if [[ -n ${zoptions[tag]} ]]; then + ztype=tag + zrev=${zoptions[tag]} + else + ztype=branch + zrev=${zoptions[branch]:-master} + fi + # Cannot have an empty space at the EOL because this is read by xargs -L1 + print "${zurl} ${ZIM_HOME}/modules/${zmodule} ${ztype} ${zrev}${1:+ ${1}}" +done diff --git a/tools/update.zsh b/tools/update.zsh new file mode 100644 index 0000000..99ed4b9 --- /dev/null +++ b/tools/update.zsh @@ -0,0 +1,58 @@ +# This runs in a new shell +URL=${1} +DIR=${2} +TYPE=${3} +REV=${4} +OPT=${5} +MODULE=${DIR:t} +if ! cd ${DIR} 2>/dev/null; then + print -P "%F{red}✗ ${MODULE}: Not installed%f" + return 1 +fi +if ! command git rev-parse --is-inside-work-tree &>/dev/null; then + # Not a git repository. Will not try to update. + return 0 +fi +if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then + print -P "%F{red}✗ ${MODULE}: URL does not match. Expected ${URL}. Will not try to update.%f" + return 1 +fi +if [[ ${TYPE} == 'tag' ]]; then + if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then + [[ ${OPT} != -q ]] && print -P "%F{green}✓%f ${MODULE}: Already up to date" + return 0 + fi +fi +if ! ERR=$(command git fetch -pq origin ${REV} 2>&1); then + print -P "%F{red}✗ ${MODULE}: Error (1)%f\n${ERR}" + return 1 +fi +if [[ ${TYPE} == 'branch' ]]; then + LOG_REV="${REV}@{u}" +else + LOG_REV=${REV} +fi +LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null) +if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then + print -P "%F{red}✗ ${MODULE}: Error (2)%f\n${ERR}" + return 1 +fi +if [[ ${TYPE} == 'branch' ]]; then + if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then + print -P "%F{red}✗ ${MODULE}: Error (3)%f\n${OUT}" + return 1 + fi + # keep just first line of OUT + OUT=${OUT%%($'\n'|$'\r')*} +else + OUT="Updating to ${TYPE} ${REV}" +fi +[[ -n ${LOG} ]] && OUT="${OUT}\n${LOG}" +if ERR=$(command git submodule update --init --recursive -q 2>&1); then + if [[ ${OPT} != -q ]]; then + print -P "%F{green}✓%f ${MODULE}: ${OUT}" + fi +else + print -P "%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}" + return 1 +fi diff --git a/tools/usage.zsh b/tools/usage.zsh new file mode 100644 index 0000000..5228efd --- /dev/null +++ b/tools/usage.zsh @@ -0,0 +1,13 @@ +print 'usage: zimfw [-q] +actions: + clean Clean all (see below). + clean-modules Clean unused modules. + clean-compiled Clean Zsh compiled files. + clean-dumpfile Clean completion dump file. + compile Compile Zsh files. + info Print Zim and system info. + install Install new modules. + update Update current modules. + upgrade Upgrade Zim. +options: + -q Quiet, only outputs errors.' diff --git a/tools/zim_build_cache b/tools/zim_build_cache deleted file mode 100644 index f9bdf39..0000000 --- a/tools/zim_build_cache +++ /dev/null @@ -1,7 +0,0 @@ -# -# zim_build_cache - rebuilds the zim cache -# - -source ${ZIM_HOME}/login_init.zsh - -print 'To rebuild the completion cache, please restart your terminal' diff --git a/tools/zim_clean_cache b/tools/zim_clean_cache deleted file mode 100644 index d19cce6..0000000 --- a/tools/zim_clean_cache +++ /dev/null @@ -1,7 +0,0 @@ -# -# zim_clean_cache - removes all zcompiled files -# - -find ${ZIM_HOME} \( -name '*.zwc' -or -name '*.zwc.old' \) -delete -rm -f ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} -rm -f ${ZDOTDIR:-${HOME}}/${zcompdump_file:-.zcompdump}{,.zwc{,.old}} diff --git a/tools/zim_info b/tools/zim_info deleted file mode 100644 index 1c00230..0000000 --- a/tools/zim_info +++ /dev/null @@ -1,9 +0,0 @@ -# -# zim_info - prints zim and system info -# - -cd ${ZIM_HOME} - -print "Zim commit ref: $(command git rev-parse --short HEAD)" -print "Zsh version: $(command zsh --version)" -print "System info: $(command uname -a)" diff --git a/tools/zim_issue b/tools/zim_issue deleted file mode 100644 index b1c9d18..0000000 --- a/tools/zim_issue +++ /dev/null @@ -1,65 +0,0 @@ -# -# zim_info - easily create an issue template -# - -# create our 'pause' function -waiter_func() { - local input_key - read -sk \?"Press [Enter] to continue; anything else to quit." input_key - if [[ ${input_key} == $'\n' ]]; then - print "\r " - return 0 - else - return 1 - fi -} - -# print init dialog -print "Please check the existing issues to make sure you\'re not duplicating a report" -print "https://github.com/zimfw/zimfw/issues" - -# if they don't accept, bail -if ! waiter_func; then - return 1 -fi - -# for convenience, this is our new home -cd ${ZIM_HOME} - -# collect sys info -local git_dirty=$(command git status --porcelain 2>/dev/null | tail -n1) -local zim_info=$(zsh tools/zim_info) - -print "Environment Info ----------------- -${zim_info} - -Description ------------ -${user_desc} - -Steps to Reproduce ------------------- -${user_reproduce} - -Images or other Information ---------------------------- -" - - -# if we have a dirty git, report it -if [[ -n ${git_dirty} ]]; then - print "${ZIM_HOME} has a dirty git working tree." - print "here is the diff:" - print '```' - print $(command git diff) - print '```' -fi - - -print '\n\n' -print 'Please copy the above and use this when reporting the issue\n' - -# optionally, now we can produce debug info -print 'If you would like to produce some helpful logs about your environment, run:' -print '$ zmanage debug' diff --git a/tools/zim_remove b/tools/zim_remove deleted file mode 100644 index a19b42d..0000000 --- a/tools/zim_remove +++ /dev/null @@ -1,13 +0,0 @@ -# -# zim_remove - removes zim from the system -# -# Note: this doesn't remove _everything_. It removes as much as -# possible while maintaining safety (don't delete custom user content). -# - -sed '/# Source zim/,/fi/d' ${ZDOTDIR:-${HOME}}/.zshrc -sed '/# The following code helps/,/) &!/d' ${ZDOTDIR:-${HOME}}/.zlogin -rm -f ${ZDOTDIR:-${HOME}}/.zimrc - -# not forcing this one, as it is recursive. It's possible something went wrong. -rm -r ${ZIM_HOME} diff --git a/tools/zim_reset b/tools/zim_reset deleted file mode 100644 index f1e33b7..0000000 --- a/tools/zim_reset +++ /dev/null @@ -1,6 +0,0 @@ -# -# zim_reset - resets the zim repository to latest commit -# - -cd ${ZIM_HOME} -git reset --hard diff --git a/tools/zim_update b/tools/zim_update deleted file mode 100644 index 38c9e38..0000000 --- a/tools/zim_update +++ /dev/null @@ -1,11 +0,0 @@ -# -# zim_update - update the zim repository -# - -cd ${ZIM_HOME} - -# this is the cleanest way I know how to update a repository -git remote update -p -git merge --ff-only @\{u\} -# and update the submodules -git submodule update --init --recursive From 2a51211ab7aa0d110a105f379a257fa095ee1252 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 10 Jan 2019 19:59:04 -0500 Subject: [PATCH 02/26] Update README.md with automatic installer Also change formatting of the settings. Using `` to prevent URL autolinking in some cases, and to add emphasis where `*foo*` would be ambiguous for the Markdown format. Copy was also slightly improved, hopefully for better clarity. --- README.md | 89 +++++++++++++++++++------------------------------------ 1 file changed, 30 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 55c9e78..d0082ca 100644 --- a/README.md +++ b/README.md @@ -37,39 +37,15 @@ Zim has many modules! Enable as many or as few as you'd like. Installation ------------ -Installing Zim is easy. If you have a different shell framework installed (like oh-my-zsh or prezto), -*uninstall those first to prevent conflicts*. It can be installed manually by following the instructions below: +Installing Zim is easy: -1. Start a Zsh shell: + curl -s --proto -all,+https https://raw.githubusercontent.com/zimfw/install/develop/install.zsh | zsh - zsh +Open a new terminal and you're done! Enjoy your Zsh IMproved! Take some time to +read about the [available modules][modules] and tweak your `.zshrc` file. -2. Clone the repository: - - git clone --recursive https://github.com/zimfw/zimfw.git ${ZDOTDIR:-${HOME}}/.zim - -3. Paste this into your terminal to prepend the initialization templates to your configs: - - for template_file in ${ZDOTDIR:-${HOME}}/.zim/templates/*; do - user_file="${ZDOTDIR:-${HOME}}/.${template_file:t}" - cat ${template_file} ${user_file}(.N) > ${user_file}.tmp && mv ${user_file}{.tmp,} - done - -4. Set Zsh as the default shell: - - chsh -s =zsh - -5. Open a new terminal and install the enabled modules. - - zimfw install - -6. Finish optimization (this is only needed once, hereafter it will happen upon - desktop/tty login): - - zimfw login-init - -7. You're done! Enjoy your Zsh IMproved! Take some time to read about the - [available modules][modules] and tweak your `.zshrc` file. +If you have a different shell framework installed (like oh-my-zsh or prezto), +*uninstall those first to prevent conflicts*. Settings -------- @@ -84,54 +60,49 @@ You can provide as many module names as you want. Modules are sourced in the order given. By default, a module is installed from the Zim repository with the same name. -For example, the `git` module is installed from https://github.com/zimfw/git if -no additional module configuration is provided. +For example, the `utility` module is installed from +https://github.com/zimfw/utility.git if no additional module configuration is provided. ### Module customization -To configure a module, use the following format (where the style name is the -module name): +To configure a module, use the following format, where the style name is the +module name: zstyle ':zim:module' ['frozen' yes] ['url' ] ['branch' |'tag' ] -If `frozen` is set to `yes`, then the module will not be cleaned, installed or -updated. - -You can provide a custom `url` with the following equivalent formats: - * `module` - * `zimfw/module` - * `https://github.com/zimfw/module.git` - -If no `branch` or `tag` name is given, then the default is `branch` `master`. +| Key | Description | Default value | +| --- | ----------- | ------------- | +| frozen | If set to yes, then module will not be cleaned, installed or updated. It can still be freely enabled or disabled with the modules style. | no | +| url | Repository URL or path. The following formats are equivalent: *module*, zimfw/*module*, https://github.com/zimfw/module.git | *module* | +| branch | Repository branch. | master | +| tag | Repository tag. Overrides branch, if one was specified. | | Choose the module name wisely. The first file found in the module root directory, -in the following order, will be sourced (where `module` is the module name): - 1. `init.zsh` - 2. `module.zsh` - 3. `module.plugin.zsh` - 4. `module.zsh.theme` - 5. `module.sh` +in the following order, will be sourced: +init.zsh, *module*.zsh, *module*.plugin.zsh, *module*.zsh.theme, *module*.sh -For example, https://github.com/mafredri/zsh-async must be configured as: +For example, [mafredi/zsh-async](https://github.com/mafredri/zsh-async) must be +configured as a module called `async`: zstyle ':zim:module' async 'url' 'mafredri/zsh-async' -because it has a `async.zsh` initialization file, then enabled as `async` in the -`modules` style. +because it has an async.zsh initialization file. Then to be enabled, `async` must +be added to the modules style. ### Prompt theme Prompt themes are enabled in one of two different ways, depending on how the specific theme you want works: - 1. If it has a `prompt_module_setup` file (where `module` is the module name): - it is enabled with Zim's `prompt` module. See [the instructions - here](https://github.com/zimfw/prompt/blob/master/README.md#settings). The - advantage of these themes is that you can customize them with additional - parameters. All [Zim themes](https://github.com/zimfw/zimfw/wiki/Themes) - work this way. + 1. If it has a prompt_module_setup file: it is enabled with Zim's + `prompt` module. See [the instructions + here](https://github.com/zimfw/prompt/blob/master/README.md#settings). All + [Zim themes](https://github.com/zimfw/zimfw/wiki/Themes) work this way. + The advantage of these themes is that you can customize them with + additional parameters. 2. If it has one of the initialization files listed above: it is enabled when - it's sourced, not with Zim's `prompt` module. + it's sourced, not with Zim's `prompt` module. The last sourced prompt + overrides any previous ones. Updating -------- From 536d7b7890b7aebd6231c77c0539e4438a04d73f Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 12 Jan 2019 15:56:00 -0500 Subject: [PATCH 03/26] Allow modules that are not repos so going into their ${ZIM_HOME}/modules/foo directory would be like still being inside the Zim repo, in ${ZIM_HOME}. Don't try to update them in this case. This was supposed to be working before, but my ${ZIM_HOME} was not a repo when I was still developing this locally. --- tools/update.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/update.zsh b/tools/update.zsh index 99ed4b9..027bc18 100644 --- a/tools/update.zsh +++ b/tools/update.zsh @@ -9,8 +9,8 @@ if ! cd ${DIR} 2>/dev/null; then print -P "%F{red}✗ ${MODULE}: Not installed%f" return 1 fi -if ! command git rev-parse --is-inside-work-tree &>/dev/null; then - # Not a git repository. Will not try to update. +if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then + # Not in repo root. Will not try to update. return 0 fi if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then From 27508e363c1f792077dcbcc30c58dd9b14d3786e Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 19 Jan 2019 19:43:37 -0500 Subject: [PATCH 04/26] Stop supporting themes that require prompinit Only 5% (18/342) of the themes listed under [unixorn/awesome-zsh-plugins] are actually compatible with prompinit. Of these, [clean] also allows being sourced directly. On the other hand, 3 others are prezto themes. promptinit would be useful for who wants to try many themes without the need to restart their shell session. And must be many many, so "brute-force" starting a new shell to experiment each new theme would be a burden! Even the cleanup feature of promptinit is still incomplete, so you eventually get a messy prompt after trying many with it. And that's not even a everyday use case of the average Zsh user. So prompinit it not widely supported out there, and also not very useful for the everyday let-me-use-my-beloved-and-carefully-customized-prompt-during-the-whole-shell-session-pleasee scenario. It's also faster and simpler to directly just source the prompt theme to be used, not even having to autoload promptinit and let it scan all the others themes in fpath that won't be used. And the Zim "philosophy" is to use fast and simple solutions. So here we go. Fixes #325 [unixorn/awesome-zsh-plugins]: https://github.com/unixorn/awesome-zsh-plugins/blob/e226f3de041a707acbdc361356bb0eb6ff20bd57/README.md#themes [clean]: https://github.com/BrandonRoehl/zsh-clean --- README.md | 15 --------------- init.zsh | 10 ++++------ templates/zimrc | 14 ++++---------- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index d0082ca..f042651 100644 --- a/README.md +++ b/README.md @@ -89,21 +89,6 @@ configured as a module called `async`: because it has an async.zsh initialization file. Then to be enabled, `async` must be added to the modules style. -### Prompt theme - -Prompt themes are enabled in one of two different ways, depending on how the -specific theme you want works: - - 1. If it has a prompt_module_setup file: it is enabled with Zim's - `prompt` module. See [the instructions - here](https://github.com/zimfw/prompt/blob/master/README.md#settings). All - [Zim themes](https://github.com/zimfw/zimfw/wiki/Themes) work this way. - The advantage of these themes is that you can customize them with - additional parameters. - 2. If it has one of the initialization files listed above: it is enabled when - it's sourced, not with Zim's `prompt` module. The last sourced prompt - overrides any previous ones. - Updating -------- diff --git a/init.zsh b/init.zsh index 43583ce..0b924dd 100644 --- a/init.zsh +++ b/init.zsh @@ -1,5 +1,5 @@ autoload -Uz is-at-least && if ! is-at-least 5.2; then - print "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." >&2 + print -u2 "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." return 1 fi @@ -38,11 +38,9 @@ fi for zmodule in ${zmodules}; do zdir=${ZIM_HOME}/modules/${zmodule} if [[ ! -d ${zdir} ]]; then - print "init: module ${zmodule} not installed" >&2 - elif [[ -f ${zdir}/prompt_${zmodule}_setup ]]; then - fpath=(${zdir} ${fpath}) # Will be loaded by promptinit + print -u2 "init: module ${zmodule} not installed" else - for zfile in ${zdir}/init.zsh ${zdir}/${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}; do + for zfile in ${zdir}/{init.zsh,${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}}; do if [[ -f ${zfile} ]]; then source ${zfile} break @@ -74,7 +72,7 @@ _zimfw_compile() { done # Compile enabled modules' scripts - for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#{*.zsh{,-theme},prompt_*_setup}(.NLk+1); do + for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do zrecompile -p ${1} ${zfile} done diff --git a/templates/zimrc b/templates/zimrc index b86ec39..a0cb805 100644 --- a/templates/zimrc +++ b/templates/zimrc @@ -8,11 +8,12 @@ # Select what modules you would like enabled. Modules are sourced in the order given. zstyle ':zim' modules \ directory environment git git-info history input utility \ - eriner gitster magicmace s1ck94 steeef prompt \ - zsh-completions completion zsh-autosuggestions zsh-syntax-highlighting history-substring-search + steeef \ + zsh-completions completion \ + zsh-autosuggestions zsh-syntax-highlighting history-substring-search # Modules setup configuration. -# See ... +# See https://github.com/zimfw/zimfw/blob/develop/README.md#module-customization zstyle ':zim:module' zsh-completions 'url' 'zsh-users/zsh-completions' zstyle ':zim:module' zsh-autosuggestions 'url' 'zsh-users/zsh-autosuggestions' zstyle ':zim:module' zsh-syntax-highlighting 'url' 'zsh-users/zsh-syntax-highlighting' @@ -66,13 +67,6 @@ zstyle ':zim:module' zsh-syntax-highlighting 'url' 'zsh-users/zsh-syntax-highlig # Load any helper scripts as defined here. #zstyle ':zim:pacman' helpers 'aur' -# -# prompt -# - -# Set your desired prompt theme. -zstyle ':zim:prompt' theme 'steeef' - # # ssh # From 1980ca091dc35ce6ae5a0844b7257b03a9bebba1 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 22 Jan 2019 19:40:43 -0500 Subject: [PATCH 05/26] Zim script in a single file \o/ Also moved the templates out of this repository, and into the zimfw/install repo. This is a second big change after introducing the plugin mechanism. This makes installation and upgrading of Zim straightforward. Maybe the most important aspect of having the script in a single file is not having to manage "git repos inside git repos" (see #297), since the single file exists by itself and is not version-controlled (with git). I've implemented a two-stage sourcing of the file, so most of the file is only sourced when needed (namely when calling `zimfw` with any action other than `login-init`). The two-stage process is designed to avoid compromising the startup speed, which is our top priority. In an effort to help making the script maintainable, I've broken it into small ERB templates. This also adds the ability to pre-process the Zsh code with Ruby code. To build the script, use `make`. --- Makefile | 4 + README.md | 32 +- init.zsh | 120 ------ login_init.zsh | 1 - src/stage1/20_guard.zsh.erb | 4 + src/stage1/30_init.zsh.erb | 46 +++ src/stage1/50_zimfw_compile.zsh.erb | 35 ++ src/stage1/80_zimfw.zsh.erb | 9 + src/stage2/30_zimfw_modules.zsh.erb | 27 ++ src/stage2/49_zimfw_clean_modules.zsh.erb | 21 ++ src/stage2/50_zimfw_clean_compiled.zsh.erb | 13 + src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 10 + src/stage2/50_zimfw_info.zsh.erb | 5 + src/stage2/50_zimfw_upgrade.zsh.erb | 20 + src/stage2/80_zimfw.zsh.erb | 57 +++ .../install.zsh => src/tools/install.zsh.erb | 10 +- tools/update.zsh => src/tools/update.zsh.erb | 28 +- src/zimfw.zsh.erb | 40 ++ templates/zimrc | 107 ------ templates/zlogin | 7 - templates/zshrc | 10 - tools/clean-compiled.zsh | 11 - tools/clean-dumpfile.zsh | 8 - tools/clean-modules.zsh | 19 - tools/info.zsh | 3 - tools/modules.zsh | 25 -- tools/usage.zsh | 13 - zimfw.zsh | 350 ++++++++++++++++++ 28 files changed, 681 insertions(+), 354 deletions(-) create mode 100644 Makefile delete mode 100644 init.zsh delete mode 100644 login_init.zsh create mode 100644 src/stage1/20_guard.zsh.erb create mode 100644 src/stage1/30_init.zsh.erb create mode 100644 src/stage1/50_zimfw_compile.zsh.erb create mode 100644 src/stage1/80_zimfw.zsh.erb create mode 100644 src/stage2/30_zimfw_modules.zsh.erb create mode 100644 src/stage2/49_zimfw_clean_modules.zsh.erb create mode 100644 src/stage2/50_zimfw_clean_compiled.zsh.erb create mode 100644 src/stage2/50_zimfw_clean_dumpfile.zsh.erb create mode 100644 src/stage2/50_zimfw_info.zsh.erb create mode 100644 src/stage2/50_zimfw_upgrade.zsh.erb create mode 100644 src/stage2/80_zimfw.zsh.erb rename tools/install.zsh => src/tools/install.zsh.erb (51%) rename tools/update.zsh => src/tools/update.zsh.erb (57%) create mode 100644 src/zimfw.zsh.erb delete mode 100644 templates/zimrc delete mode 100644 templates/zlogin delete mode 100644 templates/zshrc delete mode 100644 tools/clean-compiled.zsh delete mode 100644 tools/clean-dumpfile.zsh delete mode 100644 tools/clean-modules.zsh delete mode 100644 tools/info.zsh delete mode 100644 tools/modules.zsh delete mode 100644 tools/usage.zsh create mode 100644 zimfw.zsh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5f43035 --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +srcfiles := src/zimfw.zsh.erb $(wildcard src/*/*.erb) + +zimfw.zsh: $(srcfiles) + erb $< >| $@ diff --git a/README.md b/README.md index f042651..9e56b48 100644 --- a/README.md +++ b/README.md @@ -9,28 +9,28 @@ Zsh IMproved FrameWork What is Zim? ------------ -Zim is a Zsh configuration framework with [blazing speed][speed] and modular extensions. +Zim is a Zsh configuration framework with [blazing speed] and modular extensions. Zim is very easy to customize, and comes with a rich set of modules and features without compromising on speed or functionality! What does Zim offer? ----------------- -If you're here, it means you want to see the cool shit Zim can do. Check out the [available modules][modules]! +If you're here, it means you want to see the cool shit Zim can do. Check out the [available modules]! Below is a brief showcase of Zim's features. ### Speed -For a speed comparison between Zim and other frameworks, see [this wiki entry][speed]. +For a speed comparison between Zim and other frameworks, see [this wiki entry][blazing speed]. ### Themes -To preview some of the available themes, check the [themes wiki page][themes]. +To preview some of the available themes, check the [themes wiki page]. ### Fish-shell history navigation -![history-substring-search][fish_shell] +![history-substring-search] ### Syntax highlighting -![syntax-highlighting][syntax_highlighting] +![syntax-highlighting] ### And much more! Zim has many modules! Enable as many or as few as you'd like. @@ -39,10 +39,16 @@ Installation ------------ Installing Zim is easy: - curl -s --proto -all,+https https://raw.githubusercontent.com/zimfw/install/develop/install.zsh | zsh + * With curl: + + curl -fsSL https://raw.githubusercontent.com/zimfw/install/develop/install.zsh | zsh + + * With wget: + + wget -nv -O - https://raw.githubusercontent.com/zimfw/install/develop/install.zsh | zsh Open a new terminal and you're done! Enjoy your Zsh IMproved! Take some time to -read about the [available modules][modules] and tweak your `.zshrc` file. +read about the [available modules] and tweak your `.zshrc` file. If you have a different shell framework installed (like oh-my-zsh or prezto), *uninstall those first to prevent conflicts*. @@ -108,8 +114,8 @@ Uninstalling The best way to remove Zim is to manually delete `~/.zim`, `~/.zimrc`, and remove the initialization lines from your `~/.zshrc` and `~/.zlogin`. -[fish_shell]: https://i.eriner.me/zim_history-substring-search.gif -[syntax_highlighting]: https://i.eriner.me/zim_syntax-highlighting.gif -[speed]: https://github.com/zimfw/zimfw/wiki/Speed -[modules]: https://github.com/zimfw/zimfw/wiki/Modules -[themes]: https://github.com/zimfw/zimfw/wiki/Themes +[history-substring-search]: https://i.eriner.me/zim_history-substring-search.gif +[syntax-highlighting]: https://i.eriner.me/zim_syntax-highlighting.gif +[blazing speed]: https://github.com/zimfw/zimfw/wiki/Speed +[available modules]: https://github.com/zimfw/zimfw/wiki/Modules +[themes wiki page]: https://github.com/zimfw/zimfw/wiki/Themes diff --git a/init.zsh b/init.zsh deleted file mode 100644 index 0b924dd..0000000 --- a/init.zsh +++ /dev/null @@ -1,120 +0,0 @@ -autoload -Uz is-at-least && if ! is-at-least 5.2; then - print -u2 "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." - return 1 -fi - -# Define Zim location -: ${ZIM_HOME=${0:h}} - -# Source user configuration -[[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc - -# Set input mode before loading modules -if zstyle -t ':zim:input' mode 'vi'; then - bindkey -v -else - bindkey -e -fi - -# Autoload enabled modules' functions -() { - local zfunction - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - setopt LOCAL_OPTIONS EXTENDED_GLOB - fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath}) - for zfunction in ${ZIM_HOME}/modules/${^zmodules}/functions/^(_*|*.*|prompt_*_setup)(-.N:t); do - autoload -Uz ${zfunction} - done -} - -# Source enabled modules' init scripts -() { - local zmodule zdir zfile - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - for zmodule in ${zmodules}; do - zdir=${ZIM_HOME}/modules/${zmodule} - if [[ ! -d ${zdir} ]]; then - print -u2 "init: module ${zmodule} not installed" - else - for zfile in ${zdir}/{init.zsh,${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}}; do - if [[ -f ${zfile} ]]; then - source ${zfile} - break - fi - done - fi - done -} - -_zimfw_compile() { - setopt LOCAL_OPTIONS EXTENDED_GLOB - autoload -U zrecompile - - local zdir zfile - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - # Compile the completion cache; significant speedup - local zdumpfile - zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" - [[ -f ${zdumpfile} ]] && zrecompile -p ${1} ${zdumpfile} - - # Compile .zshrc - zrecompile -p ${1} ${ZDOTDIR:-${HOME}}/.zshrc - - # Compile enabled modules' autoloaded functions - for zdir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do - zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(_*|*.*|prompt_*_setup)(-.N) - done - - # Compile enabled modules' scripts - for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do - zrecompile -p ${1} ${zfile} - done - - # Compile this script - zrecompile -p ${1} ${ZIM_HOME}/init.zsh - - if [[ ${1} != -q ]]; then - print -P '%F{green}✓%f Done with compile.' - fi -} - -zimfw() { - if [[ ${#} -ne 1 && ${2} != -q ]]; then - source ${ZIM_HOME}/tools/usage.zsh - return 1 - fi - - case ${1} in - clean) - source ${ZIM_HOME}/tools/clean-modules.zsh ${2} && \ - source ${ZIM_HOME}/tools/clean-compiled.zsh ${2} && \ - source ${ZIM_HOME}/tools/clean-dumpfile.zsh ${2} - ;; - clean-modules) source ${ZIM_HOME}/tools/clean-modules.zsh ${2} ;; - clean-compiled) source ${ZIM_HOME}/tools/clean-compiled.zsh ${2} ;; - clean-dumpfile) source ${ZIM_HOME}/tools/clean-dumpfile.zsh ${2} ;; - compile|login-init) _zimfw_compile ${2} ;; - info) source ${ZIM_HOME}/tools/info.zsh ${2} ;; - install|update) - # Source .zimrc to refresh zmodules - [[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc - source ${ZIM_HOME}/tools/modules.zsh ${2} | xargs -L1 -P10 zsh ${ZIM_HOME}/tools/${1}.zsh && \ - if [[ ${2} != -q ]]; then - print -P "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." - fi - ;; - upgrade) - zsh ${ZIM_HOME}/tools/update.zsh 'https://github.com/zimfw/zimfw.git' ${ZIM_HOME} branch develop ${2} - ;; - *) - source ${ZIM_HOME}/tools/usage.zsh - return 1 - ;; - esac -} diff --git a/login_init.zsh b/login_init.zsh deleted file mode 100644 index 5f3d1f6..0000000 --- a/login_init.zsh +++ /dev/null @@ -1 +0,0 @@ -zimfw login-init -q &! diff --git a/src/stage1/20_guard.zsh.erb b/src/stage1/20_guard.zsh.erb new file mode 100644 index 0000000..b368d0e --- /dev/null +++ b/src/stage1/20_guard.zsh.erb @@ -0,0 +1,4 @@ +autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then + print -u2 "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < <%= min_zsh_version %> are not supported. Update your Zsh." + return 1 +fi diff --git a/src/stage1/30_init.zsh.erb b/src/stage1/30_init.zsh.erb new file mode 100644 index 0000000..4f791a0 --- /dev/null +++ b/src/stage1/30_init.zsh.erb @@ -0,0 +1,46 @@ +# Define Zim location +: ${ZIM_HOME=${0:h}} + +# Source user configuration +[[ -f <%= home %>/.zimrc ]] && source <%= home %>/.zimrc + +# Set input mode before loading modules +if zstyle -t ':zim:input' mode 'vi'; then + bindkey -v +else + bindkey -e +fi + +# Autoload enabled modules' functions +() { + local zfunction + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + setopt LOCAL_OPTIONS EXTENDED_GLOB + fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath}) + for zfunction in ${ZIM_HOME}/modules/${^zmodules}/functions/<%= functions_glob %>(-.N:t); do + autoload -Uz ${zfunction} + done +} + +# Source enabled modules' init scripts +() { + local zmodule zdir zfile + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + for zmodule in ${zmodules}; do + zdir=${ZIM_HOME}/modules/${zmodule} + if [[ ! -d ${zdir} ]]; then + print -u2 "init: module ${zmodule} not installed" + else + for zfile in ${zdir}/{init.zsh,${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}}; do + if [[ -f ${zfile} ]]; then + source ${zfile} + break + fi + done + fi + done +} diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb new file mode 100644 index 0000000..c2982a1 --- /dev/null +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -0,0 +1,35 @@ +_zimfw_compile() { + setopt LOCAL_OPTIONS EXTENDED_GLOB + autoload -U zrecompile + + local zdir zfile + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + # Compile the completion cache; significant speedup + local zdumpfile + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="<%= home %>/.zcompdump" + if [[ -f ${zdumpfile} ]]; then + zrecompile -p ${1} ${zdumpfile} || return 1 + fi + + # Compile .zshrc + zrecompile -p ${1} <%= home %>/.zshrc || return 1 + + # Compile enabled modules' autoloaded functions + for zdir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do + zrecompile -p ${1} ${zdir}.zwc ${zdir}/<%= functions_glob %>(-.N) || return 1 + done + + # Compile enabled modules' scripts + for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do + zrecompile -p ${1} ${zfile} || return 1 + done + + # Compile this script + zrecompile -p ${1} ${ZIM_HOME}/<%= script_filename %> || return 1 + + if [[ ${1} != -q ]]; then + print -P '%F{green}✓%f Done with compile.' + fi +} diff --git a/src/stage1/80_zimfw.zsh.erb b/src/stage1/80_zimfw.zsh.erb new file mode 100644 index 0000000..f3647ba --- /dev/null +++ b/src/stage1/80_zimfw.zsh.erb @@ -0,0 +1,9 @@ +zimfw() { + case ${1} in + compile|login-init) _zimfw_compile ${2} ;; + *) + source ${ZIM_HOME}/<%= script_filename %> <%= second_stage_guard %> + zimfw "${@}" + ;; + esac +} diff --git a/src/stage2/30_zimfw_modules.zsh.erb b/src/stage2/30_zimfw_modules.zsh.erb new file mode 100644 index 0000000..60611ac --- /dev/null +++ b/src/stage2/30_zimfw_modules.zsh.erb @@ -0,0 +1,27 @@ +_zimfw_modules() { + local zmodule zurl ztype zrev + local -a zmodules + local -A zoptions + zstyle -a ':zim' modules 'zmodules' + for zmodule in ${zmodules}; do + zstyle -a ':zim:module' ${zmodule} 'zoptions' + [[ ${zoptions[frozen]} == yes ]] && continue + zurl=${zoptions[url]:-${zmodule}} + if [[ ${zurl} != /* && ${zurl} != *@*:* ]]; then + # Count number of slashes + case ${#zurl//[^\/]/} in + 0) zurl="https://github.com/zimfw/${zurl}.git" ;; + 1) zurl="https://github.com/${zurl}.git" ;; + esac + fi + if [[ -n ${zoptions[tag]} ]]; then + ztype=tag + zrev=${zoptions[tag]} + else + ztype=branch + zrev=${zoptions[branch]:-master} + fi + # Cannot have an empty space at the EOL because this is read by xargs -L1 + print "'${ZIM_HOME}/modules/${zmodule}' '${zurl}' '${ztype}' '${zrev}'${1:+ ${1}}" + done +} diff --git a/src/stage2/49_zimfw_clean_modules.zsh.erb b/src/stage2/49_zimfw_clean_modules.zsh.erb new file mode 100644 index 0000000..21b0c6b --- /dev/null +++ b/src/stage2/49_zimfw_clean_modules.zsh.erb @@ -0,0 +1,21 @@ +_zimfw_clean_modules() { + local zdir zmodule + local -a zmodules + local -A zoptions + # Source .zimrc to refresh zmodules + [[ -f <%= home %>/.zimrc ]] && source <%= home %>/.zimrc + zstyle -a ':zim' modules 'zmodules' + for zdir in ${ZIM_HOME}/modules/*(/N); do + zmodule=${zdir:t} + # If zmodules does not contain the zmodule + if (( ! ${zmodules[(I)${zmodule}]} )); then + zstyle -a ':zim:module' ${zmodule} 'zoptions' + [[ ${zoptions[frozen]} == yes ]] && continue + command rm -rf ${zdir} || return 1 + [[ ${1} != -q ]] && print ${zdir} + fi + done + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with clean-modules." + fi +} diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb new file mode 100644 index 0000000..622fafc --- /dev/null +++ b/src/stage2/50_zimfw_clean_compiled.zsh.erb @@ -0,0 +1,13 @@ +_zimfw_clean_compiled() { + setopt LOCAL_OPTIONS PIPE_FAIL + local find_opt rm_opt + if [[ ${1} != -q ]]; then + find_opt='-print' + rm_opt='-v' + fi + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${find_opt} || return 1 + command rm -f ${rm_opt} <%= home %>/.zshrc.zwc{,.old} || return 1 + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile." + fi +} diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb new file mode 100644 index 0000000..a34f77f --- /dev/null +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -0,0 +1,10 @@ +_zimfw_clean_dumpfile() { + setopt LOCAL_OPTIONS PIPE_FAIL + local zdumpfile zout zopt + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="<%= home %>/.zcompdump" + [[ ${1} != -q ]] && zopt='-v' + command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration." + fi +} diff --git a/src/stage2/50_zimfw_info.zsh.erb b/src/stage2/50_zimfw_info.zsh.erb new file mode 100644 index 0000000..e52fd3f --- /dev/null +++ b/src/stage2/50_zimfw_info.zsh.erb @@ -0,0 +1,5 @@ +_zimfw_info() { + print 'Zim version: <%= version %> (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)' + print "Zsh version: ${ZSH_VERSION}" + print "System info: $(command uname -a)" +} diff --git a/src/stage2/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb new file mode 100644 index 0000000..f2a6d7b --- /dev/null +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -0,0 +1,20 @@ +_zimfw_upgrade() { + local zscript=${ZIM_HOME}/<%= script_filename %> + local zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/<%= script_filename %> + if (( ${+commands[wget]} )); then + command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 + else + command curl -fsSL -o ${zscript}.new ${zurl} || return 1 + fi + if command cmp -s ${zscript}{,.new}; then + command rm ${zscript}.new && \ + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f <%= script_filename %>: Already up to date." + fi + else + command mv ${zscript}{,.old} && command mv ${zscript}{.new,} && \ + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f <%= script_filename %>: upgraded. Restart your terminal for changes to take effect." + fi + fi +} diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb new file mode 100644 index 0000000..4b163d9 --- /dev/null +++ b/src/stage2/80_zimfw.zsh.erb @@ -0,0 +1,57 @@ +unfunction zimfw +zimfw() { + local zusage="usage: ${0} [-q] +actions: + clean Clean all (see below). + clean-modules Clean unused modules. + clean-compiled Clean Zsh compiled files. + clean-dumpfile Clean completion dump file. + compile Compile Zsh files. + info Print Zim and system info. + install Install new modules. + update Update current modules. + upgrade Upgrade Zim. +options: + -q Quiet, only outputs errors." + + if [[ ${#} -ne 1 && ${2} != -q ]]; then + print -u2 ${zusage} + return 1 + fi + + local ztool + case ${1} in + install) + ztool="<%= render_escaped("src/tools/install.zsh.erb") %>" + ;; + update) + ztool="<%= render_escaped("src/tools/update.zsh.erb") %>" + ;; + esac + + case ${1} in + clean) + _zimfw_clean_modules ${2} && \ + _zimfw_clean_compiled ${2} && \ + _zimfw_clean_dumpfile ${2} + ;; + clean-modules) _zimfw_clean_modules ${2} ;; + clean-compiled) _zimfw_clean_compiled ${2} ;; + clean-dumpfile) _zimfw_clean_dumpfile ${2} ;; + compile|login-init) _zimfw_compile ${2} ;; + info) _zimfw_info ${2} ;; + install|update) + # Source .zimrc to refresh zmodules + [[ -f <%= home %>/.zimrc ]] && source <%= home %>/.zimrc + _zimfw_modules ${2} | xargs -L1 -P10 zsh -c ${ztool} ${1} && \ + if [[ ${2} != -q ]]; then + print -P "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + fi + ;; + upgrade) _zimfw_upgrade ${2} ;; + *) + print -u2 ${zusage} + return 1 + ;; + esac +} diff --git a/tools/install.zsh b/src/tools/install.zsh.erb similarity index 51% rename from tools/install.zsh rename to src/tools/install.zsh.erb index 02dcde7..dff4a3c 100644 --- a/tools/install.zsh +++ b/src/tools/install.zsh.erb @@ -1,18 +1,20 @@ # This runs in a new shell -URL=${1} -DIR=${2} +DIR=${1} +URL=${2} REV=${4} OPT=${5} MODULE=${DIR:t} +CLEAR_LINE="\033[2K\r" if [[ -e ${DIR} ]]; then # Already exists return 0 fi +[[ ${OPT} != -q ]] && print -n "${CLEAR_LINE}Installing ${MODULE} …" if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then if [[ ${OPT} != -q ]]; then - print -P "%F{green}✓%f ${MODULE}: Installed" + print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: Installed" fi else - print -P "%F{red}✗ ${MODULE}: Error%f\n${ERR}" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error%f\n${ERR}" return 1 fi diff --git a/tools/update.zsh b/src/tools/update.zsh.erb similarity index 57% rename from tools/update.zsh rename to src/tools/update.zsh.erb index 027bc18..eec93d2 100644 --- a/tools/update.zsh +++ b/src/tools/update.zsh.erb @@ -1,12 +1,14 @@ # This runs in a new shell -URL=${1} -DIR=${2} +DIR=${1} +URL=${2} TYPE=${3} REV=${4} OPT=${5} MODULE=${DIR:t} +CLEAR_LINE="\033[2K\r" +[[ ${OPT} != -q ]] && print -n "${CLEAR_LINE}Updating ${MODULE} …" if ! cd ${DIR} 2>/dev/null; then - print -P "%F{red}✗ ${MODULE}: Not installed%f" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Not installed%f" return 1 fi if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then @@ -14,32 +16,32 @@ if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then return 0 fi if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then - print -P "%F{red}✗ ${MODULE}: URL does not match. Expected ${URL}. Will not try to update.%f" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: URL does not match. Expected ${URL}. Will not try to update.%f" return 1 fi -if [[ ${TYPE} == 'tag' ]]; then +if [[ ${TYPE} == tag ]]; then if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then - [[ ${OPT} != -q ]] && print -P "%F{green}✓%f ${MODULE}: Already up to date" + [[ ${OPT} != -q ]] && print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: Already up to date" return 0 fi fi if ! ERR=$(command git fetch -pq origin ${REV} 2>&1); then - print -P "%F{red}✗ ${MODULE}: Error (1)%f\n${ERR}" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (1)%f\n${ERR}" return 1 fi -if [[ ${TYPE} == 'branch' ]]; then +if [[ ${TYPE} == branch ]]; then LOG_REV="${REV}@{u}" else LOG_REV=${REV} fi LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null) if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then - print -P "%F{red}✗ ${MODULE}: Error (2)%f\n${ERR}" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (2)%f\n${ERR}" return 1 fi -if [[ ${TYPE} == 'branch' ]]; then +if [[ ${TYPE} == branch ]]; then if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then - print -P "%F{red}✗ ${MODULE}: Error (3)%f\n${OUT}" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (3)%f\n${OUT}" return 1 fi # keep just first line of OUT @@ -50,9 +52,9 @@ fi [[ -n ${LOG} ]] && OUT="${OUT}\n${LOG}" if ERR=$(command git submodule update --init --recursive -q 2>&1); then if [[ ${OPT} != -q ]]; then - print -P "%F{green}✓%f ${MODULE}: ${OUT}" + print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: ${OUT}" fi else - print -P "%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}" + print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}" return 1 fi diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb new file mode 100644 index 0000000..bd8d969 --- /dev/null +++ b/src/zimfw.zsh.erb @@ -0,0 +1,40 @@ +<%# coding: UTF-8 %><% +class Zim + attr_reader :functions_glob, :home, :min_zsh_version, :script_filename, :second_stage_guard, :version + + def initialize + @functions_glob = "^(_*|*.*|prompt_*_setup)" + @home = "${ZDOTDIR:-${HOME}}" + @min_zsh_version = "5.2" + @script_filename = "zimfw.zsh" + @second_stage_guard = 2 + @version = "1.0.0-SNAPSHOT" + end + + def render(filename) + ERB.new(File.read(filename)).result(binding) + end + + def render_all(pattern) + Dir[pattern].sort.map { |filename| render(filename) }.join("\n") + end + + def render_escaped(filename) + render(filename).gsub(/(\$[^']|")/, "\\\\\\1") + end +end +zim = Zim.new +%># AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. +# DO NOT DIRECTLY EDIT THIS FILE! + +if (( ! # )); then + +# Stage 1 of sourcing this script +<%= zim.render_all("src/stage1/*.erb") %># Stage 1 done + +elif [[ ${1} == <%= zim.second_stage_guard %> ]]; then + +# Stage 2 of sourcing this script. Should only be done internally by zimfw. +<%= zim.render_all("src/stage2/*.erb") %># Stage 2 done + +fi diff --git a/templates/zimrc b/templates/zimrc deleted file mode 100644 index a0cb805..0000000 --- a/templates/zimrc +++ /dev/null @@ -1,107 +0,0 @@ -################ -# ZIM SETTINGS # -################ - -# Set input mode to 'emacs' (default) or 'vi'. -#zstyle ':zim:input' mode 'vi' - -# Select what modules you would like enabled. Modules are sourced in the order given. -zstyle ':zim' modules \ - directory environment git git-info history input utility \ - steeef \ - zsh-completions completion \ - zsh-autosuggestions zsh-syntax-highlighting history-substring-search - -# Modules setup configuration. -# See https://github.com/zimfw/zimfw/blob/develop/README.md#module-customization -zstyle ':zim:module' zsh-completions 'url' 'zsh-users/zsh-completions' -zstyle ':zim:module' zsh-autosuggestions 'url' 'zsh-users/zsh-autosuggestions' -zstyle ':zim:module' zsh-syntax-highlighting 'url' 'zsh-users/zsh-syntax-highlighting' - -################### -# MODULE SETTINGS # -################### - -# -# completion -# - -# Set a custom path for the completion dump file. -# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zcompdump is used. -#zstyle ':zim:completion' dumpfile "${ZDOTDIR:-${HOME}}/.zcompdump-${ZSH_VERSION}" - -# -# environment -# - -# Set the string below to the desired terminal title format string. -# The terminal title is redrawn upon directory change, however, variables like -# ${PWD} are only evaluated once. Use prompt expansion strings for dynamic data. -# See http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes -# For example, '%n@%m: %1~' corresponds to 'username@host: /current/directory'. -#zstyle ':zim:environment' termtitle '%n@%m: %1~' - -# -# history -# - -# Save the history in a custom file path. -# If none is provided, the default ${ZDOTDIR:-${HOME}}/.zhistory is used. -#HISTFILE=${ZDOTDIR:-${HOME}}/.zsh_history - -# -# input -# - -# Enable double-dot expansion. -# This appends '../' to your input for each '.' you type after an initial '..' -#zstyle ':zim:input' double-dot-expand yes - -# -# pacman -# - -# Set an optional pacman frontend. -#zstyle ':zim:pacman' frontend 'powerpill' - -# Load any helper scripts as defined here. -#zstyle ':zim:pacman' helpers 'aur' - -# -# ssh -# - -# Load these ssh identities with the ssh module. -#zstyle ':zim:ssh' ids 'id_rsa' - -# -# utility -# - -# Enable spelling correction prompts. -# See http://zsh.sourceforge.net/Doc/Release/Options.html#index-CORRECT -#setopt CORRECT - -# Set a custom spelling correction prompt. -#SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? ' - -# -# zsh-autosuggestions -# - -# Customize the style that the suggestions are shown with. -# See https://github.com/zsh-users/zsh-autosuggestions/blob/master/README.md#suggestion-highlight-style -#ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=10' - -# -# zsh-syntax-highlighting -# - -# Set what highlighters will be used. -# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters.md -ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets) - -# Customize the main highlighter styles. -# See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/docs/highlighters/main.md#how-to-tweak-it -#typeset -A ZSH_HIGHLIGHT_STYLES -#ZSH_HIGHLIGHT_STYLES[comment]='fg=10' diff --git a/templates/zlogin b/templates/zlogin deleted file mode 100644 index 231607b..0000000 --- a/templates/zlogin +++ /dev/null @@ -1,7 +0,0 @@ -# -# User configuration sourced by login shells -# - -# Initialize Zim -[[ -s ${ZIM_HOME}/login_init.zsh ]] && source ${ZIM_HOME}/login_init.zsh - diff --git a/templates/zshrc b/templates/zshrc deleted file mode 100644 index 159c7ee..0000000 --- a/templates/zshrc +++ /dev/null @@ -1,10 +0,0 @@ -# -# User configuration sourced by interactive shells -# - -# Define Zim location -ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim - -# Start Zim -[[ -s ${ZIM_HOME}/init.zsh ]] && source ${ZIM_HOME}/init.zsh - diff --git a/tools/clean-compiled.zsh b/tools/clean-compiled.zsh deleted file mode 100644 index 56e96db..0000000 --- a/tools/clean-compiled.zsh +++ /dev/null @@ -1,11 +0,0 @@ -setopt LOCAL_OPTIONS PIPE_FAIL -local find_opt rm_opt -if [[ ${1} != -q ]]; then - find_opt='-print' - rm_opt='-v' -fi -command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${find_opt} || return 1 -command rm -f ${rm_opt} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 -if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with ${0:t:r}. Run %Bzimfw compile%b to re-compile." -fi diff --git a/tools/clean-dumpfile.zsh b/tools/clean-dumpfile.zsh deleted file mode 100644 index 25e25ef..0000000 --- a/tools/clean-dumpfile.zsh +++ /dev/null @@ -1,8 +0,0 @@ -setopt LOCAL_OPTIONS PIPE_FAIL -local zdumpfile zout zopt -zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" -[[ ${1} != -q ]] && zopt='-v' -command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 -if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with ${0:t:r}. Restart your terminal to dump an updated configuration." -fi diff --git a/tools/clean-modules.zsh b/tools/clean-modules.zsh deleted file mode 100644 index c192d9b..0000000 --- a/tools/clean-modules.zsh +++ /dev/null @@ -1,19 +0,0 @@ -local zdir zmodule -local -a zmodules -local -A zoptions -# Source .zimrc to refresh zmodules -[[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc -zstyle -a ':zim' modules 'zmodules' -for zdir in ${ZIM_HOME}/modules/*(/N); do - zmodule=${zdir:t} - # If zmodules does not contain the zmodule - if (( ! ${zmodules[(I)${zmodule}]} )); then - zstyle -a ':zim:module' ${zmodule} 'zoptions' - [[ ${zoptions[frozen]} == yes ]] && continue - command rm -rf ${zdir} || return 1 - [[ ${1} != -q ]] && print ${zdir} - fi -done -if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with ${0:t:r}." -fi diff --git a/tools/info.zsh b/tools/info.zsh deleted file mode 100644 index 5263168..0000000 --- a/tools/info.zsh +++ /dev/null @@ -1,3 +0,0 @@ -print "Zim commit ref: $(builtin cd ${ZIM_HOME} && command git rev-parse --short HEAD)" -print "Zsh version: ${ZSH_VERSION}" -print "System info: $(command uname -a)" diff --git a/tools/modules.zsh b/tools/modules.zsh deleted file mode 100644 index 3f5572b..0000000 --- a/tools/modules.zsh +++ /dev/null @@ -1,25 +0,0 @@ -local zmodule zurl ztype zrev -local -a zmodules -local -A zoptions -zstyle -a ':zim' modules 'zmodules' -for zmodule in ${zmodules}; do - zstyle -a ':zim:module' ${zmodule} 'zoptions' - [[ ${zoptions[frozen]} == yes ]] && continue - zurl=${zoptions[url]:-${zmodule}} - if [[ ${zurl} != /* && ${zurl} != *@*:* ]]; then - # Count number of slashes - case ${#zurl//[^\/]/} in - 0) zurl="https://github.com/zimfw/${zurl}.git" ;; - 1) zurl="https://github.com/${zurl}.git" ;; - esac - fi - if [[ -n ${zoptions[tag]} ]]; then - ztype=tag - zrev=${zoptions[tag]} - else - ztype=branch - zrev=${zoptions[branch]:-master} - fi - # Cannot have an empty space at the EOL because this is read by xargs -L1 - print "${zurl} ${ZIM_HOME}/modules/${zmodule} ${ztype} ${zrev}${1:+ ${1}}" -done diff --git a/tools/usage.zsh b/tools/usage.zsh deleted file mode 100644 index 5228efd..0000000 --- a/tools/usage.zsh +++ /dev/null @@ -1,13 +0,0 @@ -print 'usage: zimfw [-q] -actions: - clean Clean all (see below). - clean-modules Clean unused modules. - clean-compiled Clean Zsh compiled files. - clean-dumpfile Clean completion dump file. - compile Compile Zsh files. - info Print Zim and system info. - install Install new modules. - update Update current modules. - upgrade Upgrade Zim. -options: - -q Quiet, only outputs errors.' diff --git a/zimfw.zsh b/zimfw.zsh new file mode 100644 index 0000000..571f61e --- /dev/null +++ b/zimfw.zsh @@ -0,0 +1,350 @@ +# AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. +# DO NOT DIRECTLY EDIT THIS FILE! + +if (( ! # )); then + +# Stage 1 of sourcing this script +autoload -Uz is-at-least && if ! is-at-least 5.2; then + print -u2 "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." + return 1 +fi + +# Define Zim location +: ${ZIM_HOME=${0:h}} + +# Source user configuration +[[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc + +# Set input mode before loading modules +if zstyle -t ':zim:input' mode 'vi'; then + bindkey -v +else + bindkey -e +fi + +# Autoload enabled modules' functions +() { + local zfunction + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + setopt LOCAL_OPTIONS EXTENDED_GLOB + fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath}) + for zfunction in ${ZIM_HOME}/modules/${^zmodules}/functions/^(_*|*.*|prompt_*_setup)(-.N:t); do + autoload -Uz ${zfunction} + done +} + +# Source enabled modules' init scripts +() { + local zmodule zdir zfile + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + for zmodule in ${zmodules}; do + zdir=${ZIM_HOME}/modules/${zmodule} + if [[ ! -d ${zdir} ]]; then + print -u2 "init: module ${zmodule} not installed" + else + for zfile in ${zdir}/{init.zsh,${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}}; do + if [[ -f ${zfile} ]]; then + source ${zfile} + break + fi + done + fi + done +} + +_zimfw_compile() { + setopt LOCAL_OPTIONS EXTENDED_GLOB + autoload -U zrecompile + + local zdir zfile + local -a zmodules + zstyle -a ':zim' modules 'zmodules' + + # Compile the completion cache; significant speedup + local zdumpfile + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" + if [[ -f ${zdumpfile} ]]; then + zrecompile -p ${1} ${zdumpfile} || return 1 + fi + + # Compile .zshrc + zrecompile -p ${1} ${ZDOTDIR:-${HOME}}/.zshrc || return 1 + + # Compile enabled modules' autoloaded functions + for zdir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do + zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(_*|*.*|prompt_*_setup)(-.N) || return 1 + done + + # Compile enabled modules' scripts + for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do + zrecompile -p ${1} ${zfile} || return 1 + done + + # Compile this script + zrecompile -p ${1} ${ZIM_HOME}/zimfw.zsh || return 1 + + if [[ ${1} != -q ]]; then + print -P '%F{green}✓%f Done with compile.' + fi +} + +zimfw() { + case ${1} in + compile|login-init) _zimfw_compile ${2} ;; + *) + source ${ZIM_HOME}/zimfw.zsh 2 + zimfw "${@}" + ;; + esac +} +# Stage 1 done + +elif [[ ${1} == 2 ]]; then + +# Stage 2 of sourcing this script. Should only be done internally by zimfw. +_zimfw_modules() { + local zmodule zurl ztype zrev + local -a zmodules + local -A zoptions + zstyle -a ':zim' modules 'zmodules' + for zmodule in ${zmodules}; do + zstyle -a ':zim:module' ${zmodule} 'zoptions' + [[ ${zoptions[frozen]} == yes ]] && continue + zurl=${zoptions[url]:-${zmodule}} + if [[ ${zurl} != /* && ${zurl} != *@*:* ]]; then + # Count number of slashes + case ${#zurl//[^\/]/} in + 0) zurl="https://github.com/zimfw/${zurl}.git" ;; + 1) zurl="https://github.com/${zurl}.git" ;; + esac + fi + if [[ -n ${zoptions[tag]} ]]; then + ztype=tag + zrev=${zoptions[tag]} + else + ztype=branch + zrev=${zoptions[branch]:-master} + fi + # Cannot have an empty space at the EOL because this is read by xargs -L1 + print "'${ZIM_HOME}/modules/${zmodule}' '${zurl}' '${ztype}' '${zrev}'${1:+ ${1}}" + done +} + +_zimfw_clean_modules() { + local zdir zmodule + local -a zmodules + local -A zoptions + # Source .zimrc to refresh zmodules + [[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc + zstyle -a ':zim' modules 'zmodules' + for zdir in ${ZIM_HOME}/modules/*(/N); do + zmodule=${zdir:t} + # If zmodules does not contain the zmodule + if (( ! ${zmodules[(I)${zmodule}]} )); then + zstyle -a ':zim:module' ${zmodule} 'zoptions' + [[ ${zoptions[frozen]} == yes ]] && continue + command rm -rf ${zdir} || return 1 + [[ ${1} != -q ]] && print ${zdir} + fi + done + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with clean-modules." + fi +} + +_zimfw_clean_compiled() { + setopt LOCAL_OPTIONS PIPE_FAIL + local find_opt rm_opt + if [[ ${1} != -q ]]; then + find_opt='-print' + rm_opt='-v' + fi + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${find_opt} || return 1 + command rm -f ${rm_opt} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile." + fi +} + +_zimfw_clean_dumpfile() { + setopt LOCAL_OPTIONS PIPE_FAIL + local zdumpfile zout zopt + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" + [[ ${1} != -q ]] && zopt='-v' + command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration." + fi +} + +_zimfw_info() { + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is a1291c5)' + print "Zsh version: ${ZSH_VERSION}" + print "System info: $(command uname -a)" +} + +_zimfw_upgrade() { + local zscript=${ZIM_HOME}/zimfw.zsh + local zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh + if (( ${+commands[wget]} )); then + command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 + else + command curl -fsSL -o ${zscript}.new ${zurl} || return 1 + fi + if command cmp -s ${zscript}{,.new}; then + command rm ${zscript}.new && \ + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f zimfw.zsh: Already up to date." + fi + else + command mv ${zscript}{,.old} && command mv ${zscript}{.new,} && \ + if [[ ${1} != -q ]]; then + print -P "%F{green}✓%f zimfw.zsh: upgraded. Restart your terminal for changes to take effect." + fi + fi +} + +unfunction zimfw +zimfw() { + local zusage="usage: ${0} [-q] +actions: + clean Clean all (see below). + clean-modules Clean unused modules. + clean-compiled Clean Zsh compiled files. + clean-dumpfile Clean completion dump file. + compile Compile Zsh files. + info Print Zim and system info. + install Install new modules. + update Update current modules. + upgrade Upgrade Zim. +options: + -q Quiet, only outputs errors." + + if [[ ${#} -ne 1 && ${2} != -q ]]; then + print -u2 ${zusage} + return 1 + fi + + local ztool + case ${1} in + install) + ztool="# This runs in a new shell +DIR=\${1} +URL=\${2} +REV=\${4} +OPT=\${5} +MODULE=\${DIR:t} +CLEAR_LINE=\"\033[2K\r\" +if [[ -e \${DIR} ]]; then + # Already exists + return 0 +fi +[[ \${OPT} != -q ]] && print -n \"\${CLEAR_LINE}Installing \${MODULE} …\" +if ERR=\$(command git clone -b \${REV} -q --recursive \${URL} \${DIR} 2>&1); then + if [[ \${OPT} != -q ]]; then + print -P \"\${CLEAR_LINE}%F{green}✓%f \${MODULE}: Installed\" + fi +else + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error%f\n\${ERR}\" + return 1 +fi +" + ;; + update) + ztool="# This runs in a new shell +DIR=\${1} +URL=\${2} +TYPE=\${3} +REV=\${4} +OPT=\${5} +MODULE=\${DIR:t} +CLEAR_LINE=\"\033[2K\r\" +[[ \${OPT} != -q ]] && print -n \"\${CLEAR_LINE}Updating \${MODULE} …\" +if ! cd \${DIR} 2>/dev/null; then + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Not installed%f\" + return 1 +fi +if [[ \${PWD} != \$(command git rev-parse --show-toplevel 2>/dev/null) ]]; then + # Not in repo root. Will not try to update. + return 0 +fi +if [[ \${URL} != \$(command git config --get remote.origin.url) ]]; then + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: URL does not match. Expected \${URL}. Will not try to update.%f\" + return 1 +fi +if [[ \${TYPE} == tag ]]; then + if [[ \${REV} == \$(command git describe --tags --exact-match 2>/dev/null) ]]; then + [[ \${OPT} != -q ]] && print -P \"\${CLEAR_LINE}%F{green}✓%f \${MODULE}: Already up to date\" + return 0 + fi +fi +if ! ERR=\$(command git fetch -pq origin \${REV} 2>&1); then + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (1)%f\n\${ERR}\" + return 1 +fi +if [[ \${TYPE} == branch ]]; then + LOG_REV=\"\${REV}@{u}\" +else + LOG_REV=\${REV} +fi +LOG=\$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..\${LOG_REV} 2>/dev/null) +if ! ERR=\$(command git checkout -q \${REV} -- 2>&1); then + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (2)%f\n\${ERR}\" + return 1 +fi +if [[ \${TYPE} == branch ]]; then + if ! OUT=\$(command git merge --ff-only --no-progress -n 2>&1); then + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (3)%f\n\${OUT}\" + return 1 + fi + # keep just first line of OUT + OUT=\${OUT%%($'\n'|$'\r')*} +else + OUT=\"Updating to \${TYPE} \${REV}\" +fi +[[ -n \${LOG} ]] && OUT=\"\${OUT}\n\${LOG}\" +if ERR=\$(command git submodule update --init --recursive -q 2>&1); then + if [[ \${OPT} != -q ]]; then + print -P \"\${CLEAR_LINE}%F{green}✓%f \${MODULE}: \${OUT}\" + fi +else + print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (4)%f\n\${ERR}\" + return 1 +fi +" + ;; + esac + + case ${1} in + clean) + _zimfw_clean_modules ${2} && \ + _zimfw_clean_compiled ${2} && \ + _zimfw_clean_dumpfile ${2} + ;; + clean-modules) _zimfw_clean_modules ${2} ;; + clean-compiled) _zimfw_clean_compiled ${2} ;; + clean-dumpfile) _zimfw_clean_dumpfile ${2} ;; + compile|login-init) _zimfw_compile ${2} ;; + info) _zimfw_info ${2} ;; + install|update) + # Source .zimrc to refresh zmodules + [[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc + _zimfw_modules ${2} | xargs -L1 -P10 zsh -c ${ztool} ${1} && \ + if [[ ${2} != -q ]]; then + print -P "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + fi + ;; + upgrade) _zimfw_upgrade ${2} ;; + *) + print -u2 ${zusage} + return 1 + ;; + esac +} +# Stage 2 done + +fi From e7ba68511a4baf343c7f711a5b31ee42b7e47bb1 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 1 Aug 2019 18:19:39 -0500 Subject: [PATCH 06/26] Fix git log in zimfw update not showing backtick because it was being processed as the beginning of a escape sequence. Using `print -R` fixes that. Probably a good idea to use it when printing other messages that contain externally-generated output. --- src/tools/update.zsh.erb | 5 +++-- zimfw.zsh | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index eec93d2..1140a64 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -49,10 +49,11 @@ if [[ ${TYPE} == branch ]]; then else OUT="Updating to ${TYPE} ${REV}" fi -[[ -n ${LOG} ]] && OUT="${OUT}\n${LOG}" +[[ -n ${LOG} ]] && OUT="${OUT} +${LOG}" if ERR=$(command git submodule update --init --recursive -q 2>&1); then if [[ ${OPT} != -q ]]; then - print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: ${OUT}" + print -R "$(print -P "${CLEAR_LINE}%F{green}✓%f") ${MODULE}: ${OUT}" fi else print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}" diff --git a/zimfw.zsh b/zimfw.zsh index 571f61e..27595a1 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -182,7 +182,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is a1291c5)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 3af566d)' print "Zsh version: ${ZSH_VERSION}" print "System info: $(command uname -a)" } @@ -306,10 +306,11 @@ if [[ \${TYPE} == branch ]]; then else OUT=\"Updating to \${TYPE} \${REV}\" fi -[[ -n \${LOG} ]] && OUT=\"\${OUT}\n\${LOG}\" +[[ -n \${LOG} ]] && OUT=\"\${OUT} +\${LOG}\" if ERR=\$(command git submodule update --init --recursive -q 2>&1); then if [[ \${OPT} != -q ]]; then - print -P \"\${CLEAR_LINE}%F{green}✓%f \${MODULE}: \${OUT}\" + print -R \"\$(print -P \"\${CLEAR_LINE}%F{green}✓%f\") \${MODULE}: \${OUT}\" fi else print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (4)%f\n\${ERR}\" From 109279fc596cb2344e7047a027712d83ccb3f79e Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 31 Oct 2019 22:48:45 -0500 Subject: [PATCH 07/26] Indent git log in zimfw update --- src/tools/update.zsh.erb | 7 +++++-- zimfw.zsh | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 1140a64..7bb023f 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -49,8 +49,11 @@ if [[ ${TYPE} == branch ]]; then else OUT="Updating to ${TYPE} ${REV}" fi -[[ -n ${LOG} ]] && OUT="${OUT} -${LOG}" +if [[ -n ${LOG} ]]; then + LOG_LINES=(' '${(f)^LOG}) + OUT="${OUT} +${(F)LOG_LINES}" +fi if ERR=$(command git submodule update --init --recursive -q 2>&1); then if [[ ${OPT} != -q ]]; then print -R "$(print -P "${CLEAR_LINE}%F{green}✓%f") ${MODULE}: ${OUT}" diff --git a/zimfw.zsh b/zimfw.zsh index 27595a1..68483e0 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -182,7 +182,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 3af566d)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 601941f)' print "Zsh version: ${ZSH_VERSION}" print "System info: $(command uname -a)" } @@ -306,8 +306,11 @@ if [[ \${TYPE} == branch ]]; then else OUT=\"Updating to \${TYPE} \${REV}\" fi -[[ -n \${LOG} ]] && OUT=\"\${OUT} -\${LOG}\" +if [[ -n \${LOG} ]]; then + LOG_LINES=(' '\${(f)^LOG}) + OUT=\"\${OUT} +\${(F)LOG_LINES}\" +fi if ERR=\$(command git submodule update --init --recursive -q 2>&1); then if [[ \${OPT} != -q ]]; then print -R \"\$(print -P \"\${CLEAR_LINE}%F{green}✓%f\") \${MODULE}: \${OUT}\" From dfe35e1bfa1f062adc136a050bf3fd96f6bcb1af Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sun, 1 Dec 2019 16:00:47 -0500 Subject: [PATCH 08/26] Generate static init.zsh script \o/ to autoloads the functions and sources the scripts, instead of executing zimfw during startup, and having it always figuring out what do to on the fly. This takes out the worry about zimfw interfering with the startup time, and allows room to add more features to it. So, zstyle was replaced by a custom zmodule function to define the modules, with the extra ability of allowing users to set custom fpath paths, autoloaded functions and sourced scripts per module. --- README.md | 60 +-- src/stage1/20_guard.zsh.erb | 2 +- src/stage1/30_init.zsh.erb | 46 +- src/stage1/50_zimfw_compile.zsh.erb | 22 +- src/stage1/80_zimfw.zsh.erb | 13 +- src/stage2/30_zimfw_build.zsh.erb | 26 ++ src/stage2/30_zimfw_modules.zsh.erb | 27 -- src/stage2/30_zmodule.zsh.erb | 119 +++++ src/stage2/31_zimfw_source_zimrc.zsh.erb | 7 + src/stage2/49_zimfw_clean_modules.zsh.erb | 23 +- src/stage2/50_zimfw_clean_compiled.zsh.erb | 23 +- src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 9 +- src/stage2/50_zimfw_info.zsh.erb | 4 +- src/stage2/50_zimfw_upgrade.zsh.erb | 42 +- src/stage2/80_zimfw.zsh.erb | 83 ++-- src/tools/install.zsh.erb | 20 +- src/tools/update.zsh.erb | 44 +- src/zimfw.zsh.erb | 20 +- zimfw.zsh | 516 ++++++++++++--------- 19 files changed, 626 insertions(+), 480 deletions(-) create mode 100644 src/stage2/30_zimfw_build.zsh.erb delete mode 100644 src/stage2/30_zimfw_modules.zsh.erb create mode 100644 src/stage2/30_zmodule.zsh.erb create mode 100644 src/stage2/31_zimfw_source_zimrc.zsh.erb diff --git a/README.md b/README.md index 9e56b48..e6499d1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Zsh IMproved FrameWork @@ -53,50 +53,40 @@ read about the [available modules] and tweak your `.zshrc` file. If you have a different shell framework installed (like oh-my-zsh or prezto), *uninstall those first to prevent conflicts*. -Settings --------- +Usage +----- -### Enabled modules +### zmodule -Use the following zstyle to select the modules you would like enabled: +Add `zmodule` calls to your `.zimrc` file to define the modules to be loaded. +The modules are loaded in the same order they are defined. Add: - zstyle ':zim' modules 'first-module' 'second-module' 'third-module' + zmodule [-n|--name ] [options] -You can provide as many module names as you want. Modules are sourced in the -order given. +where <url> is the required repository URL or path. The following formats +are equivalent: *name*, zimfw/*name*, https://github.com/zimfw/name.git -By default, a module is installed from the Zim repository with the same name. -For example, the `utility` module is installed from -https://github.com/zimfw/utility.git if no additional module configuration is provided. +By default, the module name is the last component in the <url>. Use the +`-n`|`--name` <module_name> option to set a custom module name. -### Module customization +#### Repository options -To configure a module, use the following format, where the style name is the -module name: +* `-b`|`--branch` <branch_name>: Use specified branch when installing and updating the module. Overrides the tag option. Default: `master` +* `-t`|`--tag` <tag_name>: Use specified tag when installing and updating the module. Overrides the branch option. +* `-z`|`--frozen`: Don't install or update the module - zstyle ':zim:module' ['frozen' yes] ['url' ] ['branch' |'tag' ] +#### Startup options -| Key | Description | Default value | -| --- | ----------- | ------------- | -| frozen | If set to yes, then module will not be cleaned, installed or updated. It can still be freely enabled or disabled with the modules style. | no | -| url | Repository URL or path. The following formats are equivalent: *module*, zimfw/*module*, https://github.com/zimfw/module.git | *module* | -| branch | Repository branch. | master | -| tag | Repository tag. Overrides branch, if one was specified. | | +* `-f`|`--fpath` <path>: Add specified path to `fpath`. The path is relative to the module root directory. Default: `functions`, if the subdirectory exists +* `-a`|`--autoload` <function_name>: Autoload specified function. Default: all valid names inside all the module specified `fpath` paths +* `-s`|`--source` <file_path>: Source specified file. The file path is relative to the module root directory. Default: the file with largest size matching `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists +* `-d`|`--disabled`: Don't use or clean the module -Choose the module name wisely. The first file found in the module root directory, -in the following order, will be sourced: -init.zsh, *module*.zsh, *module*.plugin.zsh, *module*.zsh.theme, *module*.sh +### zimfw -For example, [mafredi/zsh-async](https://github.com/mafredri/zsh-async) must be -configured as a module called `async`: +To install new defined modules, run: - zstyle ':zim:module' async 'url' 'mafredri/zsh-async' - -because it has an async.zsh initialization file. Then to be enabled, `async` must -be added to the modules style. - -Updating --------- + zimfw install To update your modules, run: @@ -114,8 +104,8 @@ Uninstalling The best way to remove Zim is to manually delete `~/.zim`, `~/.zimrc`, and remove the initialization lines from your `~/.zshrc` and `~/.zlogin`. -[history-substring-search]: https://i.eriner.me/zim_history-substring-search.gif -[syntax-highlighting]: https://i.eriner.me/zim_syntax-highlighting.gif +[history-substring-search]: https://zimfw.github.io/images/zim_history-substring-search.gif +[syntax-highlighting]: https://zimfw.github.io/images/zim_syntax-highlighting.gif [blazing speed]: https://github.com/zimfw/zimfw/wiki/Speed [available modules]: https://github.com/zimfw/zimfw/wiki/Modules [themes wiki page]: https://github.com/zimfw/zimfw/wiki/Themes diff --git a/src/stage1/20_guard.zsh.erb b/src/stage1/20_guard.zsh.erb index b368d0e..d46518d 100644 --- a/src/stage1/20_guard.zsh.erb +++ b/src/stage1/20_guard.zsh.erb @@ -1,4 +1,4 @@ autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then - print -u2 "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < <%= min_zsh_version %> are not supported. Update your Zsh." + print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < <%= min_zsh_version %> are not supported. Update your Zsh." return 1 fi diff --git a/src/stage1/30_init.zsh.erb b/src/stage1/30_init.zsh.erb index 4f791a0..0e62c46 100644 --- a/src/stage1/30_init.zsh.erb +++ b/src/stage1/30_init.zsh.erb @@ -1,46 +1,2 @@ # Define Zim location -: ${ZIM_HOME=${0:h}} - -# Source user configuration -[[ -f <%= home %>/.zimrc ]] && source <%= home %>/.zimrc - -# Set input mode before loading modules -if zstyle -t ':zim:input' mode 'vi'; then - bindkey -v -else - bindkey -e -fi - -# Autoload enabled modules' functions -() { - local zfunction - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - setopt LOCAL_OPTIONS EXTENDED_GLOB - fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath}) - for zfunction in ${ZIM_HOME}/modules/${^zmodules}/functions/<%= functions_glob %>(-.N:t); do - autoload -Uz ${zfunction} - done -} - -# Source enabled modules' init scripts -() { - local zmodule zdir zfile - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - for zmodule in ${zmodules}; do - zdir=${ZIM_HOME}/modules/${zmodule} - if [[ ! -d ${zdir} ]]; then - print -u2 "init: module ${zmodule} not installed" - else - for zfile in ${zdir}/{init.zsh,${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}}; do - if [[ -f ${zfile} ]]; then - source ${zfile} - break - fi - done - fi - done -} +: ${ZIM_HOME=${0:A:h}} diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb index c2982a1..523d4e4 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -1,13 +1,9 @@ _zimfw_compile() { setopt LOCAL_OPTIONS EXTENDED_GLOB autoload -U zrecompile - - local zdir zfile - local -a zmodules - zstyle -a ':zim' modules 'zmodules' + local zdumpfile zdir zfile # Compile the completion cache; significant speedup - local zdumpfile zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="<%= home %>/.zcompdump" if [[ -f ${zdumpfile} ]]; then zrecompile -p ${1} ${zdumpfile} || return 1 @@ -16,19 +12,19 @@ _zimfw_compile() { # Compile .zshrc zrecompile -p ${1} <%= home %>/.zshrc || return 1 - # Compile enabled modules' autoloaded functions - for zdir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do - zrecompile -p ${1} ${zdir}.zwc ${zdir}/<%= functions_glob %>(-.N) || return 1 + # Compile autoloaded functions + for zdir in ${fpath}; do + [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue + if [[ -w ${zdir:h} ]]; then + zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(*.*)(N-.) || return 1 + fi done - # Compile enabled modules' scripts - for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do + # Compile scripts + for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do zrecompile -p ${1} ${zfile} || return 1 done - # Compile this script - zrecompile -p ${1} ${ZIM_HOME}/<%= script_filename %> || return 1 - if [[ ${1} != -q ]]; then print -P '%F{green}✓%f Done with compile.' fi diff --git a/src/stage1/80_zimfw.zsh.erb b/src/stage1/80_zimfw.zsh.erb index f3647ba..64ea658 100644 --- a/src/stage1/80_zimfw.zsh.erb +++ b/src/stage1/80_zimfw.zsh.erb @@ -1,9 +1,4 @@ -zimfw() { - case ${1} in - compile|login-init) _zimfw_compile ${2} ;; - *) - source ${ZIM_HOME}/<%= script_filename %> <%= second_stage_guard %> - zimfw "${@}" - ;; - esac -} +if [[ ${1} == (compile|login-init) && ${2} == (|-q) ]]; then + _zimfw_compile ${2} + return +fi diff --git a/src/stage2/30_zimfw_build.zsh.erb b/src/stage2/30_zimfw_build.zsh.erb new file mode 100644 index 0000000..0b93951 --- /dev/null +++ b/src/stage2/30_zimfw_build.zsh.erb @@ -0,0 +1,26 @@ +_zimfw_build() { + () { + local -r ztarget=${ZIM_HOME}/init.zsh + if command cmp -s ${ztarget} ${1}; then + if (( ! _zquiet )); then + print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" + fi + else + if [[ -e ${ztarget} ]]; then + command mv -f ${ztarget}{,.old} || return 1 + fi + command mv -f ${1} ${ztarget} && \ + if (( ! _zquiet )); then + print -PR "%F{green}✓%f %B${ztarget}:%b Updated. Restart your terminal for changes to take effect." + fi + fi + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with build.' + fi + } =( + print -R "zimfw() { source ${ZIM_HOME}/<%= script_filename %> \"\${@}\" }" + (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:P}' ${fpath})' + (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} + print -Rn ${(F):-source ${^_zscripts:P}} + ) +} diff --git a/src/stage2/30_zimfw_modules.zsh.erb b/src/stage2/30_zimfw_modules.zsh.erb deleted file mode 100644 index 60611ac..0000000 --- a/src/stage2/30_zimfw_modules.zsh.erb +++ /dev/null @@ -1,27 +0,0 @@ -_zimfw_modules() { - local zmodule zurl ztype zrev - local -a zmodules - local -A zoptions - zstyle -a ':zim' modules 'zmodules' - for zmodule in ${zmodules}; do - zstyle -a ':zim:module' ${zmodule} 'zoptions' - [[ ${zoptions[frozen]} == yes ]] && continue - zurl=${zoptions[url]:-${zmodule}} - if [[ ${zurl} != /* && ${zurl} != *@*:* ]]; then - # Count number of slashes - case ${#zurl//[^\/]/} in - 0) zurl="https://github.com/zimfw/${zurl}.git" ;; - 1) zurl="https://github.com/${zurl}.git" ;; - esac - fi - if [[ -n ${zoptions[tag]} ]]; then - ztype=tag - zrev=${zoptions[tag]} - else - ztype=branch - zrev=${zoptions[branch]:-master} - fi - # Cannot have an empty space at the EOL because this is read by xargs -L1 - print "'${ZIM_HOME}/modules/${zmodule}' '${zurl}' '${ztype}' '${zrev}'${1:+ ${1}}" - done -} diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb new file mode 100644 index 0000000..51506bf --- /dev/null +++ b/src/stage2/30_zmodule.zsh.erb @@ -0,0 +1,119 @@ +zmodule() { + local -r zusage=" +Usage: %B${0}%b [%B-n%b|%B--name%b ] [options] + +Repository options: + %B-b%b|%B--branch%b Use specified branch when installing and updating the module + %B-t%b|%B--tag%b Use specified tag when installing and updating the module + %B-z%b|%B--frozen%b Don't install or update the module + +Startup options: + %B-f%b|%B--fpath%b Add specified path to fpath + %B-a%b|%B--autoload%b Autoload specified function + %B-s%b|%B--source%b Source specified file + %B-d%b|%B--disabled%b Don't use or clean the module +" + if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then + print -u2 -PR "%F{red}${0}: Must be called from <%= home %>/.zimrc%f"$'\n'${zusage} + return 1 + fi + if (( ! # )); then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}: Missing zmodule url%f" + _zfailed=1 + return 1 + fi + setopt LOCAL_OPTIONS EXTENDED_GLOB + local zmodule=${1:t} zurl=${1} + local ztype=branch zrev=master + local -i zdisabled=0 zfrozen=0 + local -a zfpaths zfunctions zscripts + local zarg + if [[ ${zurl} =~ ^[^:/]+: ]]; then + zmodule=${zmodule%.git} + elif [[ ${zurl} != /* ]]; then + # Count number of slashes + case ${#zurl//[^\/]/} in + 0) zurl="https://github.com/zimfw/${zurl}.git" ;; + 1) zurl="https://github.com/${zurl}.git" ;; + esac + fi + shift + if [[ ${1} == (-n|--name) ]]; then + if (( # < 2 )); then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + _zfailed=1 + return 1 + fi + shift + zmodule=${1} + shift + fi + local -r zdir=${ZIM_HOME}/modules/${zmodule} + while (( # > 0 )); do + case ${1} in + -b|--branch|-t|--tag|-f|--fpath|-a|--autoload|-s|--source) + if (( # < 2 )); then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + _zfailed=1 + return 1 + fi + ;; + esac + case ${1} in + -b|--branch) + shift + ztype=branch + zrev=${1} + ;; + -t|--tag) + shift + ztype=tag + zrev=${1} + ;; + -z|--frozen) zfrozen=1 ;; + -f|--fpath) + shift + zarg=${1} + [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + zfpaths+=(${zarg}) + ;; + -a|--autoload) + shift + zfunctions+=(${1}) + ;; + -s|--source) + shift + zarg=${1} + [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + zscripts+=(${zarg}) + ;; + -d|--disabled) zdisabled=1 ;; + *) + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f" + _zfailed=1 + return 1 + ;; + esac + shift + done + if (( zdisabled )); then + _zdisableds+=(${zmodule}) + else + (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) + if (( ! ${#zfunctions} )); then + # _* functions are autoloaded by compinit + # prompt_*_setup functions are autoloaded by promptinit + zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + fi + if (( ! ${#zscripts} )); then + zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) + fi + _zfpaths+=(${zfpaths}) + _zfunctions+=(${zfunctions}) + _zscripts+=(${zscripts}) + _zmodules+=(${zmodule}) + fi + if (( ! zfrozen )); then + _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' + fi +} diff --git a/src/stage2/31_zimfw_source_zimrc.zsh.erb b/src/stage2/31_zimfw_source_zimrc.zsh.erb new file mode 100644 index 0000000..7232db2 --- /dev/null +++ b/src/stage2/31_zimfw_source_zimrc.zsh.erb @@ -0,0 +1,7 @@ +_zimfw_source_zimrc() { + local -i _zfailed=0 + if ! source <%= home %>/.zimrc || (( _zfailed )); then + print -u2 -PR "%F{red}✗ Failed to source <%= home %>/.zimrc%f" + return 1 + fi +} diff --git a/src/stage2/49_zimfw_clean_modules.zsh.erb b/src/stage2/49_zimfw_clean_modules.zsh.erb index 21b0c6b..a90c8c5 100644 --- a/src/stage2/49_zimfw_clean_modules.zsh.erb +++ b/src/stage2/49_zimfw_clean_modules.zsh.erb @@ -1,21 +1,14 @@ _zimfw_clean_modules() { - local zdir zmodule - local -a zmodules - local -A zoptions - # Source .zimrc to refresh zmodules - [[ -f <%= home %>/.zimrc ]] && source <%= home %>/.zimrc - zstyle -a ':zim' modules 'zmodules' - for zdir in ${ZIM_HOME}/modules/*(/N); do + local zopt zdir zmodule + (( ! _zquiet )) && zopt='-v' + for zdir in ${ZIM_HOME}/modules/*(N/); do zmodule=${zdir:t} - # If zmodules does not contain the zmodule - if (( ! ${zmodules[(I)${zmodule}]} )); then - zstyle -a ':zim:module' ${zmodule} 'zoptions' - [[ ${zoptions[frozen]} == yes ]] && continue - command rm -rf ${zdir} || return 1 - [[ ${1} != -q ]] && print ${zdir} + # If _zmodules and _zdisableds do not contain the zmodule + if (( ! ${_zmodules[(I)${zmodule}]} && ! ${_zdisableds[(I)${zmodule}]} )); then + command rm -rf ${zopt} ${zdir} || return 1 fi done - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with clean-modules." + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with clean-modules.' fi } diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb index 622fafc..84dcdf6 100644 --- a/src/stage2/50_zimfw_clean_compiled.zsh.erb +++ b/src/stage2/50_zimfw_clean_compiled.zsh.erb @@ -1,13 +1,18 @@ _zimfw_clean_compiled() { - setopt LOCAL_OPTIONS PIPE_FAIL - local find_opt rm_opt - if [[ ${1} != -q ]]; then - find_opt='-print' - rm_opt='-v' + local zopt_find zopt_rm zdir + if (( ! _zquiet )); then + zopt_find='-print' + zopt_rm='-v' fi - command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${find_opt} || return 1 - command rm -f ${rm_opt} <%= home %>/.zshrc.zwc{,.old} || return 1 - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile." + for zdir in ${fpath}; do + [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue + if [[ -w ${zdir:h} ]]; then + command rm -f ${zopt_rm} ${zdir}.zwc{,.old} || return 1 + fi + done + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 + command rm -f ${zopt_rm} <%= home %>/.zshrc.zwc{,.old} || return 1 + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi } diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb index a34f77f..12c2fba 100644 --- a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -1,10 +1,9 @@ _zimfw_clean_dumpfile() { - setopt LOCAL_OPTIONS PIPE_FAIL - local zdumpfile zout zopt + local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="<%= home %>/.zcompdump" - [[ ${1} != -q ]] && zopt='-v' + (( ! _zquiet )) && zopt='-v' command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration." + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi } diff --git a/src/stage2/50_zimfw_info.zsh.erb b/src/stage2/50_zimfw_info.zsh.erb index e52fd3f..6a8bf34 100644 --- a/src/stage2/50_zimfw_info.zsh.erb +++ b/src/stage2/50_zimfw_info.zsh.erb @@ -1,5 +1,5 @@ _zimfw_info() { print 'Zim version: <%= version %> (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)' - print "Zsh version: ${ZSH_VERSION}" - print "System info: $(command uname -a)" + print -R "Zsh version: ${ZSH_VERSION}" + print -R "System info: $(command uname -a)" } diff --git a/src/stage2/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb index f2a6d7b..4b1611c 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -1,20 +1,26 @@ _zimfw_upgrade() { - local zscript=${ZIM_HOME}/<%= script_filename %> - local zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/<%= script_filename %> - if (( ${+commands[wget]} )); then - command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 - else - command curl -fsSL -o ${zscript}.new ${zurl} || return 1 - fi - if command cmp -s ${zscript}{,.new}; then - command rm ${zscript}.new && \ - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f <%= script_filename %>: Already up to date." - fi - else - command mv ${zscript}{,.old} && command mv ${zscript}{.new,} && \ - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f <%= script_filename %>: upgraded. Restart your terminal for changes to take effect." - fi - fi + local -r zscript=${ZIM_HOME}/<%= script_filename %> + local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/<%= script_filename %> + { + if (( ${+commands[wget]} )); then + command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 + else + command curl -fsSL -o ${zscript}.new ${zurl} || return 1 + fi + if command cmp -s ${zscript}{,.new}; then + if (( ! _zquiet )); then + print -P '%F{green}✓%f %B<%= script_filename %>:%b Already up to date' + fi + else + command mv -f ${zscript}{,.old} && command mv -f ${zscript}{.new,} && \ + if (( ! _zquiet )); then + print -P '%F{green}✓%f %B<%= script_filename %>:%b Upgraded. Restart your terminal for changes to take effect.' + fi + fi + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with upgrade.' + fi + } always { + command rm -f ${zscript}.new + } } diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 4b163d9..0b08c98 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -1,25 +1,38 @@ -unfunction zimfw zimfw() { - local zusage="usage: ${0} [-q] -actions: - clean Clean all (see below). - clean-modules Clean unused modules. - clean-compiled Clean Zsh compiled files. - clean-dumpfile Clean completion dump file. - compile Compile Zsh files. - info Print Zim and system info. - install Install new modules. - update Update current modules. - upgrade Upgrade Zim. -options: - -q Quiet, only outputs errors." + local -r zusage=" +Usage: %B${0}%b [%B-q%b] - if [[ ${#} -ne 1 && ${2} != -q ]]; then - print -u2 ${zusage} - return 1 +Actions: + %Bbuild%b Build init script + %Bclean%b Clean all (see below) + %Bclean-modules%b Clean unused modules + %Bclean-compiled%b Clean Zsh compiled files + %Bclean-dumpfile%b Clean completion dump file + %Bcompile%b Compile Zsh files + %Binfo%b Print Zim and system info + %Binstall%b Install new modules + %Bupdate%b Update current modules + %Bupgrade%b Upgrade Zim + +Options: + %B-q%b Quiet, only outputs errors +" + local ztool _zmodules_xargs + local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts + local -i _zquiet=0 + if (( # > 2 )); then + print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} + return 1 + elif (( # > 1 )); then + case ${2} in + -q) _zquiet=1 ;; + *) + print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} + return 1 + ;; + esac fi - local ztool case ${1} in install) ztool="<%= render_escaped("src/tools/install.zsh.erb") %>" @@ -30,27 +43,29 @@ options: esac case ${1} in + build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; clean) - _zimfw_clean_modules ${2} && \ - _zimfw_clean_compiled ${2} && \ - _zimfw_clean_dumpfile ${2} + _zimfw_source_zimrc && \ + _zimfw_clean_modules && \ + _zimfw_clean_compiled && \ + _zimfw_clean_dumpfile ;; - clean-modules) _zimfw_clean_modules ${2} ;; - clean-compiled) _zimfw_clean_compiled ${2} ;; - clean-dumpfile) _zimfw_clean_dumpfile ${2} ;; - compile|login-init) _zimfw_compile ${2} ;; - info) _zimfw_info ${2} ;; + clean-modules) _zimfw_source_zimrc && _zimfw_clean_modules ;; + clean-compiled) _zimfw_clean_compiled ;; + clean-dumpfile) _zimfw_clean_dumpfile ;; + compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; + info) _zimfw_info ;; install|update) - # Source .zimrc to refresh zmodules - [[ -f <%= home %>/.zimrc ]] && source <%= home %>/.zimrc - _zimfw_modules ${2} | xargs -L1 -P10 zsh -c ${ztool} ${1} && \ - if [[ ${2} != -q ]]; then - print -P "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." - fi + _zimfw_source_zimrc || return 1 + print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ + if (( ! _zquiet )); then + print -PR "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + fi && \ + _zimfw_build && _zimfw_compile ${2} ;; - upgrade) _zimfw_upgrade ${2} ;; + upgrade) _zimfw_upgrade ;; *) - print -u2 ${zusage} + print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 ;; esac diff --git a/src/tools/install.zsh.erb b/src/tools/install.zsh.erb index dff4a3c..e915d2a 100644 --- a/src/tools/install.zsh.erb +++ b/src/tools/install.zsh.erb @@ -1,20 +1,20 @@ # This runs in a new shell -DIR=${1} -URL=${2} -REV=${4} -OPT=${5} -MODULE=${DIR:t} -CLEAR_LINE="\033[2K\r" +readonly MODULE=${1} +readonly DIR=${2} +readonly URL=${3} +readonly REV=${5} +readonly -i QUIET=${6} +readonly CLEAR_LINE=$'\E[2K\r' if [[ -e ${DIR} ]]; then # Already exists return 0 fi -[[ ${OPT} != -q ]] && print -n "${CLEAR_LINE}Installing ${MODULE} …" +(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Installing ${MODULE} …" if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then - if [[ ${OPT} != -q ]]; then - print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: Installed" + if (( ! QUIET )); then + print -PR ${CLEAR_LINE}"%F{green}✓%f %B${MODULE}:%b Installed" fi else - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error%f\n${ERR}" + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git clone%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 7bb023f..14a3e3a 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -1,14 +1,14 @@ # This runs in a new shell -DIR=${1} -URL=${2} -TYPE=${3} -REV=${4} -OPT=${5} -MODULE=${DIR:t} -CLEAR_LINE="\033[2K\r" -[[ ${OPT} != -q ]] && print -n "${CLEAR_LINE}Updating ${MODULE} …" -if ! cd ${DIR} 2>/dev/null; then - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Not installed%f" +readonly MODULE=${1} +readonly DIR=${2} +readonly URL=${3} +readonly TYPE=${4} +readonly REV=${5} +readonly -i QUIET=${6} +readonly CLEAR_LINE=$'\E[2K\r' +(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Updating ${MODULE} …" +if ! builtin cd ${DIR} 2>/dev/null; then + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Not installed%f" return 1 fi if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then @@ -16,32 +16,32 @@ if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then return 0 fi if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: URL does not match. Expected ${URL}. Will not try to update.%f" + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b URL does not match. Expected ${URL}. Will not try to update.%f" return 1 fi if [[ ${TYPE} == tag ]]; then if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then - [[ ${OPT} != -q ]] && print -P "${CLEAR_LINE}%F{green}✓%f ${MODULE}: Already up to date" + (( ! QUIET )) && print -PR ${CLEAR_LINE}"%F{green}✓%f %B${MODULE}:%b Already up to date" return 0 fi fi if ! ERR=$(command git fetch -pq origin ${REV} 2>&1); then - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (1)%f\n${ERR}" + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git fetch%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi if [[ ${TYPE} == branch ]]; then - LOG_REV="${REV}@{u}" + LOG_REV=${REV}@{u} else LOG_REV=${REV} fi LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null) if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (2)%f\n${ERR}" + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git checkout%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi if [[ ${TYPE} == branch ]]; then if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (3)%f\n${OUT}" + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git merge%f"$'\n'${(F):- ${(f)^OUT}} return 1 fi # keep just first line of OUT @@ -49,16 +49,12 @@ if [[ ${TYPE} == branch ]]; then else OUT="Updating to ${TYPE} ${REV}" fi -if [[ -n ${LOG} ]]; then - LOG_LINES=(' '${(f)^LOG}) - OUT="${OUT} -${(F)LOG_LINES}" -fi if ERR=$(command git submodule update --init --recursive -q 2>&1); then - if [[ ${OPT} != -q ]]; then - print -R "$(print -P "${CLEAR_LINE}%F{green}✓%f") ${MODULE}: ${OUT}" + if (( ! QUIET )); then + [[ -n ${LOG} ]] && OUT=${OUT}$'\n'${(F):- ${(f)^LOG}} + print -PR ${CLEAR_LINE}"%F{green}✓%f %B${MODULE}:%b ${OUT}" fi else - print -P "${CLEAR_LINE}%F{red}✗ ${MODULE}: Error (4)%f\n${ERR}" + print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git submodule update%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index bd8d969..981ecd3 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -1,13 +1,11 @@ <%# coding: UTF-8 %><% class Zim - attr_reader :functions_glob, :home, :min_zsh_version, :script_filename, :second_stage_guard, :version + attr_reader :home, :min_zsh_version, :script_filename, :second_stage_guard, :version def initialize - @functions_glob = "^(_*|*.*|prompt_*_setup)" @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" @script_filename = "zimfw.zsh" - @second_stage_guard = 2 @version = "1.0.0-SNAPSHOT" end @@ -20,21 +18,13 @@ class Zim end def render_escaped(filename) - render(filename).gsub(/(\$[^']|")/, "\\\\\\1") + render(filename).gsub(/(\$[^']|"|`)/, "\\\\\\1") end end zim = Zim.new %># AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. # DO NOT DIRECTLY EDIT THIS FILE! -if (( ! # )); then - -# Stage 1 of sourcing this script -<%= zim.render_all("src/stage1/*.erb") %># Stage 1 done - -elif [[ ${1} == <%= zim.second_stage_guard %> ]]; then - -# Stage 2 of sourcing this script. Should only be done internally by zimfw. -<%= zim.render_all("src/stage2/*.erb") %># Stage 2 done - -fi +<%= zim.render_all("src/stage1/*.erb") %> +<%= zim.render_all("src/stage2/*.erb") %> +zimfw "${@}" diff --git a/zimfw.zsh b/zimfw.zsh index 68483e0..5afee7e 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -1,71 +1,20 @@ # AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. # DO NOT DIRECTLY EDIT THIS FILE! -if (( ! # )); then - -# Stage 1 of sourcing this script autoload -Uz is-at-least && if ! is-at-least 5.2; then - print -u2 "init: error starting Zim: You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." + print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." return 1 fi # Define Zim location -: ${ZIM_HOME=${0:h}} - -# Source user configuration -[[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc - -# Set input mode before loading modules -if zstyle -t ':zim:input' mode 'vi'; then - bindkey -v -else - bindkey -e -fi - -# Autoload enabled modules' functions -() { - local zfunction - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - setopt LOCAL_OPTIONS EXTENDED_GLOB - fpath=(${ZIM_HOME}/modules/${^zmodules}/functions(/FN) ${fpath}) - for zfunction in ${ZIM_HOME}/modules/${^zmodules}/functions/^(_*|*.*|prompt_*_setup)(-.N:t); do - autoload -Uz ${zfunction} - done -} - -# Source enabled modules' init scripts -() { - local zmodule zdir zfile - local -a zmodules - zstyle -a ':zim' modules 'zmodules' - - for zmodule in ${zmodules}; do - zdir=${ZIM_HOME}/modules/${zmodule} - if [[ ! -d ${zdir} ]]; then - print -u2 "init: module ${zmodule} not installed" - else - for zfile in ${zdir}/{init.zsh,${zmodule}.{zsh,plugin.zsh,zsh-theme,sh}}; do - if [[ -f ${zfile} ]]; then - source ${zfile} - break - fi - done - fi - done -} +: ${ZIM_HOME=${0:A:h}} _zimfw_compile() { setopt LOCAL_OPTIONS EXTENDED_GLOB autoload -U zrecompile - - local zdir zfile - local -a zmodules - zstyle -a ':zim' modules 'zmodules' + local zdumpfile zdir zfile # Compile the completion cache; significant speedup - local zdumpfile zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" if [[ -f ${zdumpfile} ]]; then zrecompile -p ${1} ${zdumpfile} || return 1 @@ -74,198 +23,332 @@ _zimfw_compile() { # Compile .zshrc zrecompile -p ${1} ${ZDOTDIR:-${HOME}}/.zshrc || return 1 - # Compile enabled modules' autoloaded functions - for zdir in ${ZIM_HOME}/modules/${^zmodules}/functions(/FN); do - zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(_*|*.*|prompt_*_setup)(-.N) || return 1 + # Compile autoloaded functions + for zdir in ${fpath}; do + [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue + if [[ -w ${zdir:h} ]]; then + zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(*.*)(N-.) || return 1 + fi done - # Compile enabled modules' scripts - for zfile in ${ZIM_HOME}/modules/${^zmodules}/(^*test*/)#*.zsh{,-theme}(.NLk+1); do + # Compile scripts + for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do zrecompile -p ${1} ${zfile} || return 1 done - # Compile this script - zrecompile -p ${1} ${ZIM_HOME}/zimfw.zsh || return 1 - if [[ ${1} != -q ]]; then print -P '%F{green}✓%f Done with compile.' fi } -zimfw() { - case ${1} in - compile|login-init) _zimfw_compile ${2} ;; - *) - source ${ZIM_HOME}/zimfw.zsh 2 - zimfw "${@}" - ;; - esac -} -# Stage 1 done +if [[ ${1} == (compile|login-init) && ${2} == (|-q) ]]; then + _zimfw_compile ${2} + return +fi -elif [[ ${1} == 2 ]]; then - -# Stage 2 of sourcing this script. Should only be done internally by zimfw. -_zimfw_modules() { - local zmodule zurl ztype zrev - local -a zmodules - local -A zoptions - zstyle -a ':zim' modules 'zmodules' - for zmodule in ${zmodules}; do - zstyle -a ':zim:module' ${zmodule} 'zoptions' - [[ ${zoptions[frozen]} == yes ]] && continue - zurl=${zoptions[url]:-${zmodule}} - if [[ ${zurl} != /* && ${zurl} != *@*:* ]]; then - # Count number of slashes - case ${#zurl//[^\/]/} in - 0) zurl="https://github.com/zimfw/${zurl}.git" ;; - 1) zurl="https://github.com/${zurl}.git" ;; - esac - fi - if [[ -n ${zoptions[tag]} ]]; then - ztype=tag - zrev=${zoptions[tag]} +_zimfw_build() { + () { + local -r ztarget=${ZIM_HOME}/init.zsh + if command cmp -s ${ztarget} ${1}; then + if (( ! _zquiet )); then + print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" + fi else - ztype=branch - zrev=${zoptions[branch]:-master} + if [[ -e ${ztarget} ]]; then + command mv -f ${ztarget}{,.old} || return 1 + fi + command mv -f ${1} ${ztarget} && \ + if (( ! _zquiet )); then + print -PR "%F{green}✓%f %B${ztarget}:%b Updated. Restart your terminal for changes to take effect." + fi fi - # Cannot have an empty space at the EOL because this is read by xargs -L1 - print "'${ZIM_HOME}/modules/${zmodule}' '${zurl}' '${ztype}' '${zrev}'${1:+ ${1}}" + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with build.' + fi + } =( + print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" + (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:P}' ${fpath})' + (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} + print -Rn ${(F):-source ${^_zscripts:P}} + ) +} + +zmodule() { + local -r zusage=" +Usage: %B${0}%b [%B-n%b|%B--name%b ] [options] + +Repository options: + %B-b%b|%B--branch%b Use specified branch when installing and updating the module + %B-t%b|%B--tag%b Use specified tag when installing and updating the module + %B-z%b|%B--frozen%b Don't install or update the module + +Startup options: + %B-f%b|%B--fpath%b Add specified path to fpath + %B-a%b|%B--autoload%b Autoload specified function + %B-s%b|%B--source%b Source specified file + %B-d%b|%B--disabled%b Don't use or clean the module +" + if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then + print -u2 -PR "%F{red}${0}: Must be called from ${ZDOTDIR:-${HOME}}/.zimrc%f"$'\n'${zusage} + return 1 + fi + if (( ! # )); then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}: Missing zmodule url%f" + _zfailed=1 + return 1 + fi + setopt LOCAL_OPTIONS EXTENDED_GLOB + local zmodule=${1:t} zurl=${1} + local ztype=branch zrev=master + local -i zdisabled=0 zfrozen=0 + local -a zfpaths zfunctions zscripts + local zarg + if [[ ${zurl} =~ ^[^:/]+: ]]; then + zmodule=${zmodule%.git} + elif [[ ${zurl} != /* ]]; then + # Count number of slashes + case ${#zurl//[^\/]/} in + 0) zurl="https://github.com/zimfw/${zurl}.git" ;; + 1) zurl="https://github.com/${zurl}.git" ;; + esac + fi + shift + if [[ ${1} == (-n|--name) ]]; then + if (( # < 2 )); then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + _zfailed=1 + return 1 + fi + shift + zmodule=${1} + shift + fi + local -r zdir=${ZIM_HOME}/modules/${zmodule} + while (( # > 0 )); do + case ${1} in + -b|--branch|-t|--tag|-f|--fpath|-a|--autoload|-s|--source) + if (( # < 2 )); then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + _zfailed=1 + return 1 + fi + ;; + esac + case ${1} in + -b|--branch) + shift + ztype=branch + zrev=${1} + ;; + -t|--tag) + shift + ztype=tag + zrev=${1} + ;; + -z|--frozen) zfrozen=1 ;; + -f|--fpath) + shift + zarg=${1} + [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + zfpaths+=(${zarg}) + ;; + -a|--autoload) + shift + zfunctions+=(${1}) + ;; + -s|--source) + shift + zarg=${1} + [[ ${zarg} != /* ]] && zarg=${zdir}/${zarg} + zscripts+=(${zarg}) + ;; + -d|--disabled) zdisabled=1 ;; + *) + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f" + _zfailed=1 + return 1 + ;; + esac + shift done + if (( zdisabled )); then + _zdisableds+=(${zmodule}) + else + (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) + if (( ! ${#zfunctions} )); then + # _* functions are autoloaded by compinit + # prompt_*_setup functions are autoloaded by promptinit + zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + fi + if (( ! ${#zscripts} )); then + zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) + fi + _zfpaths+=(${zfpaths}) + _zfunctions+=(${zfunctions}) + _zscripts+=(${zscripts}) + _zmodules+=(${zmodule}) + fi + if (( ! zfrozen )); then + _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' + fi +} + +_zimfw_source_zimrc() { + local -i _zfailed=0 + if ! source ${ZDOTDIR:-${HOME}}/.zimrc || (( _zfailed )); then + print -u2 -PR "%F{red}✗ Failed to source ${ZDOTDIR:-${HOME}}/.zimrc%f" + return 1 + fi } _zimfw_clean_modules() { - local zdir zmodule - local -a zmodules - local -A zoptions - # Source .zimrc to refresh zmodules - [[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc - zstyle -a ':zim' modules 'zmodules' - for zdir in ${ZIM_HOME}/modules/*(/N); do + local zopt zdir zmodule + (( ! _zquiet )) && zopt='-v' + for zdir in ${ZIM_HOME}/modules/*(N/); do zmodule=${zdir:t} - # If zmodules does not contain the zmodule - if (( ! ${zmodules[(I)${zmodule}]} )); then - zstyle -a ':zim:module' ${zmodule} 'zoptions' - [[ ${zoptions[frozen]} == yes ]] && continue - command rm -rf ${zdir} || return 1 - [[ ${1} != -q ]] && print ${zdir} + # If _zmodules and _zdisableds do not contain the zmodule + if (( ! ${_zmodules[(I)${zmodule}]} && ! ${_zdisableds[(I)${zmodule}]} )); then + command rm -rf ${zopt} ${zdir} || return 1 fi done - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with clean-modules." + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with clean-modules.' fi } _zimfw_clean_compiled() { - setopt LOCAL_OPTIONS PIPE_FAIL - local find_opt rm_opt - if [[ ${1} != -q ]]; then - find_opt='-print' - rm_opt='-v' + local zopt_find zopt_rm zdir + if (( ! _zquiet )); then + zopt_find='-print' + zopt_rm='-v' fi - command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${find_opt} || return 1 - command rm -f ${rm_opt} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile." + for zdir in ${fpath}; do + [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue + if [[ -w ${zdir:h} ]]; then + command rm -f ${zopt_rm} ${zdir}.zwc{,.old} || return 1 + fi + done + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 + command rm -f ${zopt_rm} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi } _zimfw_clean_dumpfile() { - setopt LOCAL_OPTIONS PIPE_FAIL - local zdumpfile zout zopt + local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" - [[ ${1} != -q ]] && zopt='-v' + (( ! _zquiet )) && zopt='-v' command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration." + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 601941f)' - print "Zsh version: ${ZSH_VERSION}" - print "System info: $(command uname -a)" + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is e81c1d1)' + print -R "Zsh version: ${ZSH_VERSION}" + print -R "System info: $(command uname -a)" } _zimfw_upgrade() { - local zscript=${ZIM_HOME}/zimfw.zsh - local zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh - if (( ${+commands[wget]} )); then - command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 - else - command curl -fsSL -o ${zscript}.new ${zurl} || return 1 - fi - if command cmp -s ${zscript}{,.new}; then - command rm ${zscript}.new && \ - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f zimfw.zsh: Already up to date." - fi - else - command mv ${zscript}{,.old} && command mv ${zscript}{.new,} && \ - if [[ ${1} != -q ]]; then - print -P "%F{green}✓%f zimfw.zsh: upgraded. Restart your terminal for changes to take effect." - fi - fi + local -r zscript=${ZIM_HOME}/zimfw.zsh + local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh + { + if (( ${+commands[wget]} )); then + command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 + else + command curl -fsSL -o ${zscript}.new ${zurl} || return 1 + fi + if command cmp -s ${zscript}{,.new}; then + if (( ! _zquiet )); then + print -P '%F{green}✓%f %Bzimfw.zsh:%b Already up to date' + fi + else + command mv -f ${zscript}{,.old} && command mv -f ${zscript}{.new,} && \ + if (( ! _zquiet )); then + print -P '%F{green}✓%f %Bzimfw.zsh:%b Upgraded. Restart your terminal for changes to take effect.' + fi + fi + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with upgrade.' + fi + } always { + command rm -f ${zscript}.new + } } -unfunction zimfw zimfw() { - local zusage="usage: ${0} [-q] -actions: - clean Clean all (see below). - clean-modules Clean unused modules. - clean-compiled Clean Zsh compiled files. - clean-dumpfile Clean completion dump file. - compile Compile Zsh files. - info Print Zim and system info. - install Install new modules. - update Update current modules. - upgrade Upgrade Zim. -options: - -q Quiet, only outputs errors." + local -r zusage=" +Usage: %B${0}%b [%B-q%b] - if [[ ${#} -ne 1 && ${2} != -q ]]; then - print -u2 ${zusage} - return 1 +Actions: + %Bbuild%b Build init script + %Bclean%b Clean all (see below) + %Bclean-modules%b Clean unused modules + %Bclean-compiled%b Clean Zsh compiled files + %Bclean-dumpfile%b Clean completion dump file + %Bcompile%b Compile Zsh files + %Binfo%b Print Zim and system info + %Binstall%b Install new modules + %Bupdate%b Update current modules + %Bupgrade%b Upgrade Zim + +Options: + %B-q%b Quiet, only outputs errors +" + local ztool _zmodules_xargs + local -a _zdisableds _zmodules _zfpaths _zfunctions _zscripts + local -i _zquiet=0 + if (( # > 2 )); then + print -u2 -PR "%F{red}${0}: Too many options%f"$'\n'${zusage} + return 1 + elif (( # > 1 )); then + case ${2} in + -q) _zquiet=1 ;; + *) + print -u2 -PR "%F{red}${0}: Unknown option ${2}%f"$'\n'${zusage} + return 1 + ;; + esac fi - local ztool case ${1} in install) ztool="# This runs in a new shell -DIR=\${1} -URL=\${2} -REV=\${4} -OPT=\${5} -MODULE=\${DIR:t} -CLEAR_LINE=\"\033[2K\r\" +readonly MODULE=\${1} +readonly DIR=\${2} +readonly URL=\${3} +readonly REV=\${5} +readonly -i QUIET=\${6} +readonly CLEAR_LINE=$'\E[2K\r' if [[ -e \${DIR} ]]; then # Already exists return 0 fi -[[ \${OPT} != -q ]] && print -n \"\${CLEAR_LINE}Installing \${MODULE} …\" +(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Installing \${MODULE} …\" if ERR=\$(command git clone -b \${REV} -q --recursive \${URL} \${DIR} 2>&1); then - if [[ \${OPT} != -q ]]; then - print -P \"\${CLEAR_LINE}%F{green}✓%f \${MODULE}: Installed\" + if (( ! QUIET )); then + print -PR \${CLEAR_LINE}\"%F{green}✓%f %B\${MODULE}:%b Installed\" fi else - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error%f\n\${ERR}\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git clone%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi " ;; update) ztool="# This runs in a new shell -DIR=\${1} -URL=\${2} -TYPE=\${3} -REV=\${4} -OPT=\${5} -MODULE=\${DIR:t} -CLEAR_LINE=\"\033[2K\r\" -[[ \${OPT} != -q ]] && print -n \"\${CLEAR_LINE}Updating \${MODULE} …\" -if ! cd \${DIR} 2>/dev/null; then - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Not installed%f\" +readonly MODULE=\${1} +readonly DIR=\${2} +readonly URL=\${3} +readonly TYPE=\${4} +readonly REV=\${5} +readonly -i QUIET=\${6} +readonly CLEAR_LINE=$'\E[2K\r' +(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Updating \${MODULE} …\" +if ! builtin cd \${DIR} 2>/dev/null; then + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Not installed%f\" return 1 fi if [[ \${PWD} != \$(command git rev-parse --show-toplevel 2>/dev/null) ]]; then @@ -273,32 +356,32 @@ if [[ \${PWD} != \$(command git rev-parse --show-toplevel 2>/dev/null) ]]; then return 0 fi if [[ \${URL} != \$(command git config --get remote.origin.url) ]]; then - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: URL does not match. Expected \${URL}. Will not try to update.%f\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b URL does not match. Expected \${URL}. Will not try to update.%f\" return 1 fi if [[ \${TYPE} == tag ]]; then if [[ \${REV} == \$(command git describe --tags --exact-match 2>/dev/null) ]]; then - [[ \${OPT} != -q ]] && print -P \"\${CLEAR_LINE}%F{green}✓%f \${MODULE}: Already up to date\" + (( ! QUIET )) && print -PR \${CLEAR_LINE}\"%F{green}✓%f %B\${MODULE}:%b Already up to date\" return 0 fi fi if ! ERR=\$(command git fetch -pq origin \${REV} 2>&1); then - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (1)%f\n\${ERR}\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git fetch%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi if [[ \${TYPE} == branch ]]; then - LOG_REV=\"\${REV}@{u}\" + LOG_REV=\${REV}@{u} else LOG_REV=\${REV} fi LOG=\$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..\${LOG_REV} 2>/dev/null) if ! ERR=\$(command git checkout -q \${REV} -- 2>&1); then - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (2)%f\n\${ERR}\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git checkout%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi if [[ \${TYPE} == branch ]]; then if ! OUT=\$(command git merge --ff-only --no-progress -n 2>&1); then - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (3)%f\n\${OUT}\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git merge%f\"$'\n'\${(F):- \${(f)^OUT}} return 1 fi # keep just first line of OUT @@ -306,17 +389,13 @@ if [[ \${TYPE} == branch ]]; then else OUT=\"Updating to \${TYPE} \${REV}\" fi -if [[ -n \${LOG} ]]; then - LOG_LINES=(' '\${(f)^LOG}) - OUT=\"\${OUT} -\${(F)LOG_LINES}\" -fi if ERR=\$(command git submodule update --init --recursive -q 2>&1); then - if [[ \${OPT} != -q ]]; then - print -R \"\$(print -P \"\${CLEAR_LINE}%F{green}✓%f\") \${MODULE}: \${OUT}\" + if (( ! QUIET )); then + [[ -n \${LOG} ]] && OUT=\${OUT}$'\n'\${(F):- \${(f)^LOG}} + print -PR \${CLEAR_LINE}\"%F{green}✓%f %B\${MODULE}:%b \${OUT}\" fi else - print -P \"\${CLEAR_LINE}%F{red}✗ \${MODULE}: Error (4)%f\n\${ERR}\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git submodule update%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi " @@ -324,31 +403,32 @@ fi esac case ${1} in + build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; clean) - _zimfw_clean_modules ${2} && \ - _zimfw_clean_compiled ${2} && \ - _zimfw_clean_dumpfile ${2} + _zimfw_source_zimrc && \ + _zimfw_clean_modules && \ + _zimfw_clean_compiled && \ + _zimfw_clean_dumpfile ;; - clean-modules) _zimfw_clean_modules ${2} ;; - clean-compiled) _zimfw_clean_compiled ${2} ;; - clean-dumpfile) _zimfw_clean_dumpfile ${2} ;; - compile|login-init) _zimfw_compile ${2} ;; - info) _zimfw_info ${2} ;; + clean-modules) _zimfw_source_zimrc && _zimfw_clean_modules ;; + clean-compiled) _zimfw_clean_compiled ;; + clean-dumpfile) _zimfw_clean_dumpfile ;; + compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; + info) _zimfw_info ;; install|update) - # Source .zimrc to refresh zmodules - [[ -f ${ZDOTDIR:-${HOME}}/.zimrc ]] && source ${ZDOTDIR:-${HOME}}/.zimrc - _zimfw_modules ${2} | xargs -L1 -P10 zsh -c ${ztool} ${1} && \ - if [[ ${2} != -q ]]; then - print -P "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." - fi + _zimfw_source_zimrc || return 1 + print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ + if (( ! _zquiet )); then + print -PR "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + fi && \ + _zimfw_build && _zimfw_compile ${2} ;; - upgrade) _zimfw_upgrade ${2} ;; + upgrade) _zimfw_upgrade ;; *) - print -u2 ${zusage} + print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 ;; esac } -# Stage 2 done -fi +zimfw "${@}" From a227f134a5d0746e099c9895be758b2f1e0b439b Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 3 Dec 2019 07:07:59 -0500 Subject: [PATCH 09/26] Source .zimrc twice when installing/updating Once before installing/updating to prepare _zmodule_xargs, and once after modules are updated, so functions and scripts can be found inside them. Installation of Zim from scratch was failing because all modules are empty at first. --- src/stage2/30_zmodule.zsh.erb | 37 +++++++++++---------- src/stage2/31_zimfw_source_zimrc.zsh.erb | 1 + src/stage2/80_zimfw.zsh.erb | 4 +-- zimfw.zsh | 42 +++++++++++++----------- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 51506bf..190786b 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -96,24 +96,27 @@ Startup options: esac shift done - if (( zdisabled )); then - _zdisableds+=(${zmodule}) + if (( _zprepare_xargs )); then + if (( ! zfrozen )); then + _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' + fi else - (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) - if (( ! ${#zfunctions} )); then - # _* functions are autoloaded by compinit - # prompt_*_setup functions are autoloaded by promptinit - zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + if (( zdisabled )); then + _zdisableds+=(${zmodule}) + else + (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) + if (( ! ${#zfunctions} )); then + # _* functions are autoloaded by compinit + # prompt_*_setup functions are autoloaded by promptinit + zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + fi + if (( ! ${#zscripts} )); then + zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) + fi + _zfpaths+=(${zfpaths}) + _zfunctions+=(${zfunctions}) + _zscripts+=(${zscripts}) + _zmodules+=(${zmodule}) fi - if (( ! ${#zscripts} )); then - zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) - fi - _zfpaths+=(${zfpaths}) - _zfunctions+=(${zfunctions}) - _zscripts+=(${zscripts}) - _zmodules+=(${zmodule}) - fi - if (( ! zfrozen )); then - _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' fi } diff --git a/src/stage2/31_zimfw_source_zimrc.zsh.erb b/src/stage2/31_zimfw_source_zimrc.zsh.erb index 7232db2..1a331ab 100644 --- a/src/stage2/31_zimfw_source_zimrc.zsh.erb +++ b/src/stage2/31_zimfw_source_zimrc.zsh.erb @@ -1,4 +1,5 @@ _zimfw_source_zimrc() { + local -ri _zprepare_xargs=${1} local -i _zfailed=0 if ! source <%= home %>/.zimrc || (( _zfailed )); then print -u2 -PR "%F{red}✗ Failed to source <%= home %>/.zimrc%f" diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 0b08c98..fe801e1 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -56,12 +56,12 @@ Options: compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; info) _zimfw_info ;; install|update) - _zimfw_source_zimrc || return 1 + _zimfw_source_zimrc 1 || return 1 print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ if (( ! _zquiet )); then print -PR "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." fi && \ - _zimfw_build && _zimfw_compile ${2} + _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; upgrade) _zimfw_upgrade ;; *) diff --git a/zimfw.zsh b/zimfw.zsh index 5afee7e..38584da 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -171,29 +171,33 @@ Startup options: esac shift done - if (( zdisabled )); then - _zdisableds+=(${zmodule}) + if (( _zprepare_xargs )); then + if (( ! zfrozen )); then + _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' + fi else - (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) - if (( ! ${#zfunctions} )); then - # _* functions are autoloaded by compinit - # prompt_*_setup functions are autoloaded by promptinit - zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + if (( zdisabled )); then + _zdisableds+=(${zmodule}) + else + (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) + if (( ! ${#zfunctions} )); then + # _* functions are autoloaded by compinit + # prompt_*_setup functions are autoloaded by promptinit + zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + fi + if (( ! ${#zscripts} )); then + zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) + fi + _zfpaths+=(${zfpaths}) + _zfunctions+=(${zfunctions}) + _zscripts+=(${zscripts}) + _zmodules+=(${zmodule}) fi - if (( ! ${#zscripts} )); then - zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) - fi - _zfpaths+=(${zfpaths}) - _zfunctions+=(${zfunctions}) - _zscripts+=(${zscripts}) - _zmodules+=(${zmodule}) - fi - if (( ! zfrozen )); then - _zmodules_xargs+=${zmodule}$'\0'${zdir}$'\0'${zurl}$'\0'${ztype}$'\0'${zrev}$'\0'${_zquiet}$'\0' fi } _zimfw_source_zimrc() { + local -ri _zprepare_xargs=${1} local -i _zfailed=0 if ! source ${ZDOTDIR:-${HOME}}/.zimrc || (( _zfailed )); then print -u2 -PR "%F{red}✗ Failed to source ${ZDOTDIR:-${HOME}}/.zimrc%f" @@ -416,12 +420,12 @@ fi compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; info) _zimfw_info ;; install|update) - _zimfw_source_zimrc || return 1 + _zimfw_source_zimrc 1 || return 1 print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ if (( ! _zquiet )); then print -PR "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." fi && \ - _zimfw_build && _zimfw_compile ${2} + _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; upgrade) _zimfw_upgrade ;; *) From 8c7d0081b18fc4b76003c0ff42a286b302f2f6dd Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Wed, 4 Dec 2019 07:22:17 -0500 Subject: [PATCH 10/26] Add manual installation to README.md --- README.md | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e6499d1..8aa885f 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,29 @@ read about the [available modules] and tweak your `.zshrc` file. If you have a different shell framework installed (like oh-my-zsh or prezto), *uninstall those first to prevent conflicts*. +### Manual installation + +1. Set Zsh as the default shell: + + chsh -s =zsh + +2. Start a Zsh shell + + zsh + +3. Copy https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh to + `${ZDOTDIR:-${HOME}}/.zim/zimfw.zsh`. + +4. Add the lines in the following templates to the respective dot files in the + `${ZDOTDIR:-${HOME}}` directory: + * [.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) + * [.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) + * [.zshrc](https://github.com/zimfw/install/blob/develop/src/templates/zshrc) + +5. Install the modules defined in `.zimrc` and build the static `init.zsh` script: + + source ${ZDOTDIR:-${HOME}}/.zim/zimfw.zsh install + Usage ----- @@ -64,23 +87,29 @@ The modules are loaded in the same order they are defined. Add: zmodule [-n|--name ] [options] where <url> is the required repository URL or path. The following formats -are equivalent: *name*, zimfw/*name*, https://github.com/zimfw/name.git +are equivalent: `name`, `zimfw/name`, `https://github.com/zimfw/name.git`. By default, the module name is the last component in the <url>. Use the -`-n`|`--name` <module_name> option to set a custom module name. +`-n`|`--name` <module_name> option to set a custom module name. #### Repository options -* `-b`|`--branch` <branch_name>: Use specified branch when installing and updating the module. Overrides the tag option. Default: `master` -* `-t`|`--tag` <tag_name>: Use specified tag when installing and updating the module. Overrides the branch option. -* `-z`|`--frozen`: Don't install or update the module +* `-b`|`--branch` <branch_name>: Use specified branch when installing and + updating the module. Overrides the tag option. Default: `master`. +* `-t`|`--tag` <tag_name>: Use specified tag when installing and updating the + module. Overrides the branch option. +* `-z`|`--frozen`: Don't install or update the module. #### Startup options -* `-f`|`--fpath` <path>: Add specified path to `fpath`. The path is relative to the module root directory. Default: `functions`, if the subdirectory exists -* `-a`|`--autoload` <function_name>: Autoload specified function. Default: all valid names inside all the module specified `fpath` paths -* `-s`|`--source` <file_path>: Source specified file. The file path is relative to the module root directory. Default: the file with largest size matching `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists -* `-d`|`--disabled`: Don't use or clean the module +* `-f`|`--fpath` <path>: Add specified path to `fpath`. The path is relative to + the module root directory. Default: `functions`, if the subdirectory exists. +* `-a`|`--autoload` <function_name>: Autoload specified function. Default: all + valid names inside all the module specified `fpath` paths. +* `-s`|`--source` <file_path>: Source specified file. The file path is relative + to the module root directory. Default: the file with largest size matching + `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists. +* `-d`|`--disabled`: Don't use or clean the module. ### zimfw From c47c4fc08b813eaf0eb2cbf68407f00564d66b05 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 5 Dec 2019 13:51:34 -0500 Subject: [PATCH 11/26] Compile also after upgrade, add ZIM_HOME to info We want to recompile zimfw.zsh if it changes. ZIM_HOME is not required to be set beforehand anymore, so let's give the users the variable info back. --- src/stage2/50_zimfw_info.zsh.erb | 5 +++-- src/stage2/80_zimfw.zsh.erb | 6 +++--- zimfw.zsh | 13 +++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/stage2/50_zimfw_info.zsh.erb b/src/stage2/50_zimfw_info.zsh.erb index 6a8bf34..8c068b1 100644 --- a/src/stage2/50_zimfw_info.zsh.erb +++ b/src/stage2/50_zimfw_info.zsh.erb @@ -1,5 +1,6 @@ _zimfw_info() { print 'Zim version: <%= version %> (previous commit is <%= `git rev-parse --short HEAD | tr -d '\r\n'` %>)' - print -R "Zsh version: ${ZSH_VERSION}" - print -R "System info: $(command uname -a)" + print -R 'ZIM_HOME: '${ZIM_HOME} + print -R 'Zsh version: '${ZSH_VERSION} + print -R 'System info: '$(command uname -a) } diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index fe801e1..e00bdde 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -3,7 +3,7 @@ zimfw() { Usage: %B${0}%b [%B-q%b] Actions: - %Bbuild%b Build init script + %Bbuild%b Build init.zsh %Bclean%b Clean all (see below) %Bclean-modules%b Clean unused modules %Bclean-compiled%b Clean Zsh compiled files @@ -12,7 +12,7 @@ Actions: %Binfo%b Print Zim and system info %Binstall%b Install new modules %Bupdate%b Update current modules - %Bupgrade%b Upgrade Zim + %Bupgrade%b Upgrade <%= script_filename %> Options: %B-q%b Quiet, only outputs errors @@ -63,7 +63,7 @@ Options: fi && \ _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; - upgrade) _zimfw_upgrade ;; + upgrade) _zimfw_upgrade && _zimfw_compile ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 diff --git a/zimfw.zsh b/zimfw.zsh index 38584da..c16c9e2 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -250,9 +250,10 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is e81c1d1)' - print -R "Zsh version: ${ZSH_VERSION}" - print -R "System info: $(command uname -a)" + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is bccb1fc)' + print -R 'ZIM_HOME: '${ZIM_HOME} + print -R 'Zsh version: '${ZSH_VERSION} + print -R 'System info: '$(command uname -a) } _zimfw_upgrade() { @@ -287,7 +288,7 @@ zimfw() { Usage: %B${0}%b [%B-q%b] Actions: - %Bbuild%b Build init script + %Bbuild%b Build init.zsh %Bclean%b Clean all (see below) %Bclean-modules%b Clean unused modules %Bclean-compiled%b Clean Zsh compiled files @@ -296,7 +297,7 @@ Actions: %Binfo%b Print Zim and system info %Binstall%b Install new modules %Bupdate%b Update current modules - %Bupgrade%b Upgrade Zim + %Bupgrade%b Upgrade zimfw.zsh Options: %B-q%b Quiet, only outputs errors @@ -427,7 +428,7 @@ fi fi && \ _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; - upgrade) _zimfw_upgrade ;; + upgrade) _zimfw_upgrade && _zimfw_compile ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 From cec82ea0e55d245a08d6626cf55491b6523c7952 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 7 Dec 2019 21:17:40 -0500 Subject: [PATCH 12/26] Add zimfw init action for a quick build Having to manually do `zimfw build` every time after you edit your .zimrc file is boring. So by having the following in .zshrc before sourcing init.zsh will do a quick build automatically when needed: if [[ ~/.zim/init.zsh -ot ~/.zimrc ]]; then source ~/.zim/zimfw.zsh init -q fi --- README.md | 63 ++++++++++++++++--------------- src/stage2/30_zimfw_build.zsh.erb | 2 +- src/stage2/30_zmodule.zsh.erb | 5 +++ src/stage2/80_zimfw.zsh.erb | 1 + zimfw.zsh | 10 ++++- 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 8aa885f..9223bc7 100644 --- a/README.md +++ b/README.md @@ -55,73 +55,76 @@ If you have a different shell framework installed (like oh-my-zsh or prezto), ### Manual installation -1. Set Zsh as the default shell: - - chsh -s =zsh - -2. Start a Zsh shell +1. Start a Zsh shell zsh +2. Set Zsh as the default shell: + + chsh -s =zsh + 3. Copy https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh to - `${ZDOTDIR:-${HOME}}/.zim/zimfw.zsh`. + `~/.zim/zimfw.zsh`. -4. Add the lines in the following templates to the respective dot files in the - `${ZDOTDIR:-${HOME}}` directory: - * [.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) - * [.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) - * [.zshrc](https://github.com/zimfw/install/blob/develop/src/templates/zshrc) +4. Add the lines in the following templates to the respective dot files: + * [~/.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) + * [~/.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) + * [~/.zshrc](https://github.com/zimfw/install/blob/develop/src/templates/zshrc) -5. Install the modules defined in `.zimrc` and build the static `init.zsh` script: +5. Install the modules defined in `~/.zimrc` and build the static initialization script: - source ${ZDOTDIR:-${HOME}}/.zim/zimfw.zsh install + source ~/.zim/zimfw.zsh install Usage ----- ### zmodule -Add `zmodule` calls to your `.zimrc` file to define the modules to be loaded. -The modules are loaded in the same order they are defined. Add: +Add `zmodule` calls to your `~/.zimrc` file to define the modules to be initialized. +The modules are initialized in the same order they are defined. Add: zmodule [-n|--name ] [options] -where <url> is the required repository URL or path. The following formats +where `` is the required repository URL or path. The following formats are equivalent: `name`, `zimfw/name`, `https://github.com/zimfw/name.git`. -By default, the module name is the last component in the <url>. Use the -`-n`|`--name` <module_name> option to set a custom module name. +By default, the module name is the last component in the ``. Use the +`-n|--name ` option to set a custom module name. #### Repository options -* `-b`|`--branch` <branch_name>: Use specified branch when installing and +* `-b|--branch `: Use specified branch when installing and updating the module. Overrides the tag option. Default: `master`. -* `-t`|`--tag` <tag_name>: Use specified tag when installing and updating the +* `-t|--tag `: Use specified tag when installing and updating the module. Overrides the branch option. -* `-z`|`--frozen`: Don't install or update the module. +* `-z|--frozen`: Don't install or update the module. -#### Startup options +#### Initialization options -* `-f`|`--fpath` <path>: Add specified path to `fpath`. The path is relative to +* `-f|--fpath `: Add specified path to `fpath`. The path is relative to the module root directory. Default: `functions`, if the subdirectory exists. -* `-a`|`--autoload` <function_name>: Autoload specified function. Default: all - valid names inside all the module specified `fpath` paths. -* `-s`|`--source` <file_path>: Source specified file. The file path is relative +* `-a|--autoload `: Autoload specified function. Default: all + valid names inside the module's specified `fpath` paths. +* `-s|--source `: Source specified file. The file path is relative to the module root directory. Default: the file with largest size matching `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists. -* `-d`|`--disabled`: Don't use or clean the module. +* `-d|--disabled`: Don't use or clean the module. ### zimfw -To install new defined modules, run: +Added new modules to `~/.zimrc`? Run: zimfw install -To update your modules, run: +Removed modules from `~/.zimrc`? Run: + + zimfw clean-modules + +Want to update your modules to their latest revisions? Run: zimfw update -To upgrade Zim, run: +Want to upgrade `~/.zim/zimfw.zsh` to the latest version? zimfw upgrade diff --git a/src/stage2/30_zimfw_build.zsh.erb b/src/stage2/30_zimfw_build.zsh.erb index 0b93951..14f7dd2 100644 --- a/src/stage2/30_zimfw_build.zsh.erb +++ b/src/stage2/30_zimfw_build.zsh.erb @@ -1,7 +1,7 @@ _zimfw_build() { () { local -r ztarget=${ZIM_HOME}/init.zsh - if command cmp -s ${ztarget} ${1}; then + if [[ ${ztarget} -nt <%= home %>/.zimrc ]] && command cmp -s ${ztarget} ${1}; then if (( ! _zquiet )); then print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" fi diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 190786b..682519b 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -104,6 +104,11 @@ Startup options: if (( zdisabled )); then _zdisableds+=(${zmodule}) else + if [[ ! -d ${zdir} ]]; then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" + _zfailed=1 + return 1 + fi (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index e00bdde..9eec1cc 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -44,6 +44,7 @@ Options: case ${1} in build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_source_zimrc && \ _zimfw_clean_modules && \ diff --git a/zimfw.zsh b/zimfw.zsh index c16c9e2..ad701e8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -49,7 +49,7 @@ fi _zimfw_build() { () { local -r ztarget=${ZIM_HOME}/init.zsh - if command cmp -s ${ztarget} ${1}; then + if [[ ${ztarget} -nt ${ZDOTDIR:-${HOME}}/.zimrc ]] && command cmp -s ${ztarget} ${1}; then if (( ! _zquiet )); then print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" fi @@ -179,6 +179,11 @@ Startup options: if (( zdisabled )); then _zdisableds+=(${zmodule}) else + if [[ ! -d ${zdir} ]]; then + print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" + _zfailed=1 + return 1 + fi (( ! ${#zfpaths} )) && zfpaths+=(${zdir}/functions(NF)) if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit @@ -250,7 +255,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is bccb1fc)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is c330f61)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -409,6 +414,7 @@ fi case ${1} in build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_source_zimrc && \ _zimfw_clean_modules && \ From 3ec1772ef240ad1d95f015351ce19cbc8ff42c2a Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sun, 8 Dec 2019 20:03:45 -0500 Subject: [PATCH 13/26] Add LICENSE to zimfw.zsh --- LICENSE | 22 ++++++++++++++++++++++ LICENSE.md | 25 ------------------------- src/zimfw.zsh.erb | 5 +++++ zimfw.zsh | 25 ++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 26 deletions(-) create mode 100644 LICENSE delete mode 100644 LICENSE.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..abf9ce6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2015-2016 Matt Hamilton and contributors +Copyright (c) 2016-2019 Eric Nielsen, Matt Hamilton and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 0589535..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,25 +0,0 @@ -The MIT License (MIT) -===================== - -Copyright (c) `2015-2016` `Matt Hamilton and contributors` - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the “Software”), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index 981ecd3..eb439f0 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -20,11 +20,16 @@ class Zim def render_escaped(filename) render(filename).gsub(/(\$[^']|"|`)/, "\\\\\\1") end + + def render_commented(filename) + render(filename).gsub(/^(?=.)/, "# ").gsub(/^$/, "#") + end end zim = Zim.new %># AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. # DO NOT DIRECTLY EDIT THIS FILE! +<%= zim.render_commented("LICENSE") %> <%= zim.render_all("src/stage1/*.erb") %> <%= zim.render_all("src/stage2/*.erb") %> zimfw "${@}" diff --git a/zimfw.zsh b/zimfw.zsh index ad701e8..cdbf283 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -1,6 +1,29 @@ # AUTOMATICALLY GENERATED FILE. EDIT ONLY THE SOURCE FILES AND THEN COMPILE. # DO NOT DIRECTLY EDIT THIS FILE! +# MIT License +# +# Copyright (c) 2015-2016 Matt Hamilton and contributors +# Copyright (c) 2016-2019 Eric Nielsen, Matt Hamilton and contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + autoload -Uz is-at-least && if ! is-at-least 5.2; then print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < 5.2 are not supported. Update your Zsh." return 1 @@ -255,7 +278,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is c330f61)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 106335e)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) From 196a0585f757ed9f36e1250372ca7e5470e0e63c Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Mon, 9 Dec 2019 21:34:12 -0500 Subject: [PATCH 14/26] Don't fail zimfw compile on empty fpath dir otherwise it would fail with, for example zrecompile:zcompile:133: can't open file /usr/local/share/zsh/site-functions --- src/stage1/50_zimfw_compile.zsh.erb | 5 +++-- zimfw.zsh | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb index 523d4e4..5da66fa 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -15,8 +15,9 @@ _zimfw_compile() { # Compile autoloaded functions for zdir in ${fpath}; do [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - if [[ -w ${zdir:h} ]]; then - zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(*.*)(N-.) || return 1 + zfile=(${zdir}/^(*.*)(N-.)) + if [[ -w ${zdir:h} && -n ${zfile} ]]; then + zrecompile -p ${1} ${zdir}.zwc ${zfile} || return 1 fi done diff --git a/zimfw.zsh b/zimfw.zsh index cdbf283..4795413 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -49,8 +49,9 @@ _zimfw_compile() { # Compile autoloaded functions for zdir in ${fpath}; do [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - if [[ -w ${zdir:h} ]]; then - zrecompile -p ${1} ${zdir}.zwc ${zdir}/^(*.*)(N-.) || return 1 + zfile=(${zdir}/^(*.*)(N-.)) + if [[ -w ${zdir:h} && -n ${zfile} ]]; then + zrecompile -p ${1} ${zdir}.zwc ${zfile} || return 1 fi done @@ -278,7 +279,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 106335e)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 74404e6)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) From 7139771ec6c91bdecd8b1508224b396b7dac3f54 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 10 Dec 2019 18:19:01 -0500 Subject: [PATCH 15/26] Rename zimfw action clean-modules to uninstall and have `zimfw clean` only do `clean-compiled` and `clean-dumpfile`. Semantically, it makes much more sense because we will be then cleaning temporary files that are later compiled/generated again, which is not the case for a module (which we'll be uninstalling now instead of cleaning). --- ...les.zsh.erb => 50_zimfw_uninstall.zsh.erb} | 4 +- src/stage2/80_zimfw.zsh.erb | 5 +-- zimfw.zsh | 37 +++++++++---------- 3 files changed, 22 insertions(+), 24 deletions(-) rename src/stage2/{49_zimfw_clean_modules.zsh.erb => 50_zimfw_uninstall.zsh.erb} (82%) diff --git a/src/stage2/49_zimfw_clean_modules.zsh.erb b/src/stage2/50_zimfw_uninstall.zsh.erb similarity index 82% rename from src/stage2/49_zimfw_clean_modules.zsh.erb rename to src/stage2/50_zimfw_uninstall.zsh.erb index a90c8c5..b470243 100644 --- a/src/stage2/49_zimfw_clean_modules.zsh.erb +++ b/src/stage2/50_zimfw_uninstall.zsh.erb @@ -1,4 +1,4 @@ -_zimfw_clean_modules() { +_zimfw_uninstall() { local zopt zdir zmodule (( ! _zquiet )) && zopt='-v' for zdir in ${ZIM_HOME}/modules/*(N/); do @@ -9,6 +9,6 @@ _zimfw_clean_modules() { fi done if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with clean-modules.' + print -P '%F{green}✓%f Done with uninstall.' fi } diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 9eec1cc..a7b0bef 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -5,12 +5,12 @@ Usage: %B${0}%b [%B-q%b] Actions: %Bbuild%b Build init.zsh %Bclean%b Clean all (see below) - %Bclean-modules%b Clean unused modules %Bclean-compiled%b Clean Zsh compiled files %Bclean-dumpfile%b Clean completion dump file %Bcompile%b Compile Zsh files %Binfo%b Print Zim and system info %Binstall%b Install new modules + %Buninstall%b Delete unused modules %Bupdate%b Update current modules %Bupgrade%b Upgrade <%= script_filename %> @@ -47,11 +47,9 @@ Options: init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_source_zimrc && \ - _zimfw_clean_modules && \ _zimfw_clean_compiled && \ _zimfw_clean_dumpfile ;; - clean-modules) _zimfw_source_zimrc && _zimfw_clean_modules ;; clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; @@ -64,6 +62,7 @@ Options: fi && \ _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;; upgrade) _zimfw_upgrade && _zimfw_compile ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} diff --git a/zimfw.zsh b/zimfw.zsh index 4795413..40b0a96 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -234,21 +234,6 @@ _zimfw_source_zimrc() { fi } -_zimfw_clean_modules() { - local zopt zdir zmodule - (( ! _zquiet )) && zopt='-v' - for zdir in ${ZIM_HOME}/modules/*(N/); do - zmodule=${zdir:t} - # If _zmodules and _zdisableds do not contain the zmodule - if (( ! ${_zmodules[(I)${zmodule}]} && ! ${_zdisableds[(I)${zmodule}]} )); then - command rm -rf ${zopt} ${zdir} || return 1 - fi - done - if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with clean-modules.' - fi -} - _zimfw_clean_compiled() { local zopt_find zopt_rm zdir if (( ! _zquiet )); then @@ -279,12 +264,27 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 74404e6)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 69d609d)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) } +_zimfw_uninstall() { + local zopt zdir zmodule + (( ! _zquiet )) && zopt='-v' + for zdir in ${ZIM_HOME}/modules/*(N/); do + zmodule=${zdir:t} + # If _zmodules and _zdisableds do not contain the zmodule + if (( ! ${_zmodules[(I)${zmodule}]} && ! ${_zdisableds[(I)${zmodule}]} )); then + command rm -rf ${zopt} ${zdir} || return 1 + fi + done + if (( ! _zquiet )); then + print -P '%F{green}✓%f Done with uninstall.' + fi +} + _zimfw_upgrade() { local -r zscript=${ZIM_HOME}/zimfw.zsh local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh @@ -319,12 +319,12 @@ Usage: %B${0}%b [%B-q%b] Actions: %Bbuild%b Build init.zsh %Bclean%b Clean all (see below) - %Bclean-modules%b Clean unused modules %Bclean-compiled%b Clean Zsh compiled files %Bclean-dumpfile%b Clean completion dump file %Bcompile%b Compile Zsh files %Binfo%b Print Zim and system info %Binstall%b Install new modules + %Buninstall%b Delete unused modules %Bupdate%b Update current modules %Bupgrade%b Upgrade zimfw.zsh @@ -441,11 +441,9 @@ fi init) _zimfw_source_zimrc && _zimfw_build ;; clean) _zimfw_source_zimrc && \ - _zimfw_clean_modules && \ _zimfw_clean_compiled && \ _zimfw_clean_dumpfile ;; - clean-modules) _zimfw_source_zimrc && _zimfw_clean_modules ;; clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; @@ -458,6 +456,7 @@ fi fi && \ _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; + uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;; upgrade) _zimfw_upgrade && _zimfw_compile ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} From e2e2cfc22c62da2397407e90b254692c8aeb119c Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 10 Dec 2019 18:59:46 -0500 Subject: [PATCH 16/26] Rename clean-modules to uninstall in README.md too --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9223bc7..ed6463f 100644 --- a/README.md +++ b/README.md @@ -118,13 +118,13 @@ Added new modules to `~/.zimrc`? Run: Removed modules from `~/.zimrc`? Run: - zimfw clean-modules + zimfw uninstall Want to update your modules to their latest revisions? Run: zimfw update -Want to upgrade `~/.zim/zimfw.zsh` to the latest version? +Want to upgrade `~/.zim/zimfw.zsh` to the latest version? Run: zimfw upgrade From eaebf1731cdc64ea95644438924a875c1e9b7003 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Tue, 10 Dec 2019 19:28:00 -0500 Subject: [PATCH 17/26] Give credit to zrecompile doc in zshcontrib(1) and make code closer to the one in the manual pages (unless for our code style). Why reinvent the wheel? This last change makes the arguments to zrecompile shorter (passing relative paths instead of full paths to each function file). The number of arguments can be huge. There are 1143 of them currently for /usr/local/Cellar/zsh/5.7.1/share/zsh/functions! --- src/stage1/50_zimfw_compile.zsh.erb | 5 +++-- zimfw.zsh | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb index 5da66fa..b9ba0f6 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -12,12 +12,13 @@ _zimfw_compile() { # Compile .zshrc zrecompile -p ${1} <%= home %>/.zshrc || return 1 - # Compile autoloaded functions + # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) for zdir in ${fpath}; do [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue zfile=(${zdir}/^(*.*)(N-.)) if [[ -w ${zdir:h} && -n ${zfile} ]]; then - zrecompile -p ${1} ${zdir}.zwc ${zfile} || return 1 + zfile=(${${(M)zfile%/*/*}#/}) + (cd ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 fi done diff --git a/zimfw.zsh b/zimfw.zsh index 40b0a96..80679b7 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -46,12 +46,13 @@ _zimfw_compile() { # Compile .zshrc zrecompile -p ${1} ${ZDOTDIR:-${HOME}}/.zshrc || return 1 - # Compile autoloaded functions + # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) for zdir in ${fpath}; do [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue zfile=(${zdir}/^(*.*)(N-.)) if [[ -w ${zdir:h} && -n ${zfile} ]]; then - zrecompile -p ${1} ${zdir}.zwc ${zfile} || return 1 + zfile=(${${(M)zfile%/*/*}#/}) + (cd ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 fi done @@ -264,7 +265,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 69d609d)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 660b8cd)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) From 3ae4fec895e44945c94585e93543eaad6ae3cfee Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 12 Dec 2019 08:46:27 -0500 Subject: [PATCH 18/26] Use builtin cd -q to bypass aliases and to avoid calling any chpwd hook functions. --- src/stage1/50_zimfw_compile.zsh.erb | 2 +- src/tools/update.zsh.erb | 2 +- zimfw.zsh | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb index b9ba0f6..01ae6b8 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -18,7 +18,7 @@ _zimfw_compile() { zfile=(${zdir}/^(*.*)(N-.)) if [[ -w ${zdir:h} && -n ${zfile} ]]; then zfile=(${${(M)zfile%/*/*}#/}) - (cd ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 + (builtin cd -q ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 fi done diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 14a3e3a..53876df 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -7,7 +7,7 @@ readonly REV=${5} readonly -i QUIET=${6} readonly CLEAR_LINE=$'\E[2K\r' (( ! QUIET )) && print -Rn ${CLEAR_LINE}"Updating ${MODULE} …" -if ! builtin cd ${DIR} 2>/dev/null; then +if ! builtin cd -q ${DIR} 2>/dev/null; then print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Not installed%f" return 1 fi diff --git a/zimfw.zsh b/zimfw.zsh index 80679b7..70c226b 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -52,7 +52,7 @@ _zimfw_compile() { zfile=(${zdir}/^(*.*)(N-.)) if [[ -w ${zdir:h} && -n ${zfile} ]]; then zfile=(${${(M)zfile%/*/*}#/}) - (cd ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 + (builtin cd -q ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 fi done @@ -265,7 +265,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 660b8cd)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is bd8ae83)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -382,7 +382,7 @@ readonly REV=\${5} readonly -i QUIET=\${6} readonly CLEAR_LINE=$'\E[2K\r' (( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Updating \${MODULE} …\" -if ! builtin cd \${DIR} 2>/dev/null; then +if ! builtin cd -q \${DIR} 2>/dev/null; then print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Not installed%f\" return 1 fi From 4b750cb72f3b6b72d6a835511fc1b11faac8b3cc Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 12 Dec 2019 09:00:19 -0500 Subject: [PATCH 19/26] Fix zimfw failing in termux with NO_CASE_GLOB that is set by the completion module. This is a known still unsolved issue with termux. See https://github.com/termux/termux-packages/issues/1894 --- src/stage1/50_zimfw_compile.zsh.erb | 2 +- src/stage2/30_zmodule.zsh.erb | 2 +- zimfw.zsh | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb index 01ae6b8..861dc4e 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -1,5 +1,5 @@ _zimfw_compile() { - setopt LOCAL_OPTIONS EXTENDED_GLOB + setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB autoload -U zrecompile local zdumpfile zdir zfile diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 682519b..274a3eb 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -22,7 +22,7 @@ Startup options: _zfailed=1 return 1 fi - setopt LOCAL_OPTIONS EXTENDED_GLOB + setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB local zmodule=${1:t} zurl=${1} local ztype=branch zrev=master local -i zdisabled=0 zfrozen=0 diff --git a/zimfw.zsh b/zimfw.zsh index 70c226b..36e607b 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -33,7 +33,7 @@ fi : ${ZIM_HOME=${0:A:h}} _zimfw_compile() { - setopt LOCAL_OPTIONS EXTENDED_GLOB + setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB autoload -U zrecompile local zdumpfile zdir zfile @@ -122,7 +122,7 @@ Startup options: _zfailed=1 return 1 fi - setopt LOCAL_OPTIONS EXTENDED_GLOB + setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB local zmodule=${1:t} zurl=${1} local ztype=branch zrev=master local -i zdisabled=0 zfrozen=0 @@ -265,7 +265,7 @@ _zimfw_clean_dumpfile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is bd8ae83)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 4a7ce44)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) From 93bbc356349995fdd1315f4b88259758d9ba3378 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Fri, 13 Dec 2019 07:14:10 -0500 Subject: [PATCH 20/26] Use ASCII characters only we want to be a universal Zsh framework, and send the message that "less is less"! ;- ) Don't indent done and failed messages with an indicator, at the end of actions, to differentiate them from intermediate okay and error messages. --- src/stage1/50_zimfw_compile.zsh.erb | 2 +- src/stage2/30_zimfw_build.zsh.erb | 6 +-- src/stage2/30_zmodule.zsh.erb | 10 ++-- src/stage2/31_zimfw_source_zimrc.zsh.erb | 2 +- src/stage2/50_zimfw_clean_compiled.zsh.erb | 2 +- src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 2 +- src/stage2/50_zimfw_uninstall.zsh.erb | 2 +- src/stage2/50_zimfw_upgrade.zsh.erb | 6 +-- src/stage2/80_zimfw.zsh.erb | 2 +- src/tools/install.zsh.erb | 6 +-- src/tools/update.zsh.erb | 18 +++---- src/zimfw.zsh.erb | 9 +++- zimfw.zsh | 60 +++++++++++----------- 13 files changed, 66 insertions(+), 61 deletions(-) diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/stage1/50_zimfw_compile.zsh.erb index 861dc4e..71e2384 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/stage1/50_zimfw_compile.zsh.erb @@ -28,6 +28,6 @@ _zimfw_compile() { done if [[ ${1} != -q ]]; then - print -P '%F{green}✓%f Done with compile.' + print -P '<%= done %>Done with compile.' fi } diff --git a/src/stage2/30_zimfw_build.zsh.erb b/src/stage2/30_zimfw_build.zsh.erb index 14f7dd2..12f71af 100644 --- a/src/stage2/30_zimfw_build.zsh.erb +++ b/src/stage2/30_zimfw_build.zsh.erb @@ -3,7 +3,7 @@ _zimfw_build() { local -r ztarget=${ZIM_HOME}/init.zsh if [[ ${ztarget} -nt <%= home %>/.zimrc ]] && command cmp -s ${ztarget} ${1}; then if (( ! _zquiet )); then - print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" + print -PR "<%= okay %>%B${ztarget}:%b Already up to date" fi else if [[ -e ${ztarget} ]]; then @@ -11,11 +11,11 @@ _zimfw_build() { fi command mv -f ${1} ${ztarget} && \ if (( ! _zquiet )); then - print -PR "%F{green}✓%f %B${ztarget}:%b Updated. Restart your terminal for changes to take effect." + print -PR "<%= okay %>%B${ztarget}:%b Updated. Restart your terminal for changes to take effect." fi fi if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with build.' + print -P '<%= done %>Done with build.' fi } =( print -R "zimfw() { source ${ZIM_HOME}/<%= script_filename %> \"\${@}\" }" diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 274a3eb..3cc9f2e 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -18,7 +18,7 @@ Startup options: return 1 fi if (( ! # )); then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}: Missing zmodule url%f" + print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}: Missing zmodule url%f" _zfailed=1 return 1 fi @@ -40,7 +40,7 @@ Startup options: shift if [[ ${1} == (-n|--name) ]]; then if (( # < 2 )); then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" _zfailed=1 return 1 fi @@ -53,7 +53,7 @@ Startup options: case ${1} in -b|--branch|-t|--tag|-f|--fpath|-a|--autoload|-s|--source) if (( # < 2 )); then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" _zfailed=1 return 1 fi @@ -89,7 +89,7 @@ Startup options: ;; -d|--disabled) zdisabled=1 ;; *) - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f" + print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f" _zfailed=1 return 1 ;; @@ -105,7 +105,7 @@ Startup options: _zdisableds+=(${zmodule}) else if [[ ! -d ${zdir} ]]; then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" + print -u2 -PR "%F{red}<%= error %>${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" _zfailed=1 return 1 fi diff --git a/src/stage2/31_zimfw_source_zimrc.zsh.erb b/src/stage2/31_zimfw_source_zimrc.zsh.erb index 1a331ab..c8d79b1 100644 --- a/src/stage2/31_zimfw_source_zimrc.zsh.erb +++ b/src/stage2/31_zimfw_source_zimrc.zsh.erb @@ -2,7 +2,7 @@ _zimfw_source_zimrc() { local -ri _zprepare_xargs=${1} local -i _zfailed=0 if ! source <%= home %>/.zimrc || (( _zfailed )); then - print -u2 -PR "%F{red}✗ Failed to source <%= home %>/.zimrc%f" + print -u2 -PR "%F{red}<%= failed %>Failed to source %B<%= home %>/.zimrc%b%f" return 1 fi } diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb index 84dcdf6..a711ac3 100644 --- a/src/stage2/50_zimfw_clean_compiled.zsh.erb +++ b/src/stage2/50_zimfw_clean_compiled.zsh.erb @@ -13,6 +13,6 @@ _zimfw_clean_compiled() { command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 command rm -f ${zopt_rm} <%= home %>/.zshrc.zwc{,.old} || return 1 if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' + print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi } diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb index 12c2fba..aa8d637 100644 --- a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -4,6 +4,6 @@ _zimfw_clean_dumpfile() { (( ! _zquiet )) && zopt='-v' command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' + print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi } diff --git a/src/stage2/50_zimfw_uninstall.zsh.erb b/src/stage2/50_zimfw_uninstall.zsh.erb index b470243..dcfe196 100644 --- a/src/stage2/50_zimfw_uninstall.zsh.erb +++ b/src/stage2/50_zimfw_uninstall.zsh.erb @@ -9,6 +9,6 @@ _zimfw_uninstall() { fi done if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with uninstall.' + print -P '<%= done %>Done with uninstall.' fi } diff --git a/src/stage2/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb index 4b1611c..4b14a6f 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -9,16 +9,16 @@ _zimfw_upgrade() { fi if command cmp -s ${zscript}{,.new}; then if (( ! _zquiet )); then - print -P '%F{green}✓%f %B<%= script_filename %>:%b Already up to date' + print -P '<%= okay %>%B<%= script_filename %>:%b Already up to date' fi else command mv -f ${zscript}{,.old} && command mv -f ${zscript}{.new,} && \ if (( ! _zquiet )); then - print -P '%F{green}✓%f %B<%= script_filename %>:%b Upgraded. Restart your terminal for changes to take effect.' + print -P '<%= okay %>%B<%= script_filename %>:%b Upgraded. Restart your terminal for changes to take effect.' fi fi if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with upgrade.' + print -P '<%= done %>Done with upgrade.' fi } always { command rm -f ${zscript}.new diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index a7b0bef..12a7989 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -58,7 +58,7 @@ Options: _zimfw_source_zimrc 1 || return 1 print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ if (( ! _zquiet )); then - print -PR "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + print -PR "<%= done %>Done with ${1}. Restart your terminal for any changes to take effect." fi && \ _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; diff --git a/src/tools/install.zsh.erb b/src/tools/install.zsh.erb index e915d2a..bd7251d 100644 --- a/src/tools/install.zsh.erb +++ b/src/tools/install.zsh.erb @@ -9,12 +9,12 @@ if [[ -e ${DIR} ]]; then # Already exists return 0 fi -(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Installing ${MODULE} …" +(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Installing ${MODULE}<%= ellipsis %>" if ERR=$(command git clone -b ${REV} -q --recursive ${URL} ${DIR} 2>&1); then if (( ! QUIET )); then - print -PR ${CLEAR_LINE}"%F{green}✓%f %B${MODULE}:%b Installed" + print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Installed" fi else - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git clone%f"$'\n'${(F):- ${(f)^ERR}} + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git clone%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi diff --git a/src/tools/update.zsh.erb b/src/tools/update.zsh.erb index 53876df..287b478 100644 --- a/src/tools/update.zsh.erb +++ b/src/tools/update.zsh.erb @@ -6,9 +6,9 @@ readonly TYPE=${4} readonly REV=${5} readonly -i QUIET=${6} readonly CLEAR_LINE=$'\E[2K\r' -(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Updating ${MODULE} …" +(( ! QUIET )) && print -Rn ${CLEAR_LINE}"Updating ${MODULE}<%= ellipsis %>" if ! builtin cd -q ${DIR} 2>/dev/null; then - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Not installed%f" + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Not installed%f" return 1 fi if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then @@ -16,17 +16,17 @@ if [[ ${PWD} != $(command git rev-parse --show-toplevel 2>/dev/null) ]]; then return 0 fi if [[ ${URL} != $(command git config --get remote.origin.url) ]]; then - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b URL does not match. Expected ${URL}. Will not try to update.%f" + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b URL does not match. Expected ${URL}. Will not try to update.%f" return 1 fi if [[ ${TYPE} == tag ]]; then if [[ ${REV} == $(command git describe --tags --exact-match 2>/dev/null) ]]; then - (( ! QUIET )) && print -PR ${CLEAR_LINE}"%F{green}✓%f %B${MODULE}:%b Already up to date" + (( ! QUIET )) && print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b Already up to date" return 0 fi fi if ! ERR=$(command git fetch -pq origin ${REV} 2>&1); then - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git fetch%f"$'\n'${(F):- ${(f)^ERR}} + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git fetch%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi if [[ ${TYPE} == branch ]]; then @@ -36,12 +36,12 @@ else fi LOG=$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..${LOG_REV} 2>/dev/null) if ! ERR=$(command git checkout -q ${REV} -- 2>&1); then - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git checkout%f"$'\n'${(F):- ${(f)^ERR}} + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git checkout%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi if [[ ${TYPE} == branch ]]; then if ! OUT=$(command git merge --ff-only --no-progress -n 2>&1); then - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git merge%f"$'\n'${(F):- ${(f)^OUT}} + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git merge%f"$'\n'${(F):- ${(f)^OUT}} return 1 fi # keep just first line of OUT @@ -52,9 +52,9 @@ fi if ERR=$(command git submodule update --init --recursive -q 2>&1); then if (( ! QUIET )); then [[ -n ${LOG} ]] && OUT=${OUT}$'\n'${(F):- ${(f)^LOG}} - print -PR ${CLEAR_LINE}"%F{green}✓%f %B${MODULE}:%b ${OUT}" + print -PR ${CLEAR_LINE}"<%= okay %>%B${MODULE}:%b ${OUT}" fi else - print -u2 -PR ${CLEAR_LINE}"%F{red}✗ %B${MODULE}:%b Error during git submodule update%f"$'\n'${(F):- ${(f)^ERR}} + print -u2 -PR ${CLEAR_LINE}"%F{red}<%= error %>%B${MODULE}:%b Error during git submodule update%f"$'\n'${(F):- ${(f)^ERR}} return 1 fi diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index eb439f0..29cb8d0 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -1,12 +1,17 @@ -<%# coding: UTF-8 %><% +<% class Zim - attr_reader :home, :min_zsh_version, :script_filename, :second_stage_guard, :version + attr_reader :home, :min_zsh_version, :script_filename, :version, :ellipsis, :okay, :error, :done, :failed def initialize @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" @script_filename = "zimfw.zsh" @version = "1.0.0-SNAPSHOT" + @ellipsis = " ..." + @okay = "%F{green})%f " + @error = "x " + @done = "" + @failed = "" end def render(filename) diff --git a/zimfw.zsh b/zimfw.zsh index 36e607b..565ac7e 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -62,7 +62,7 @@ _zimfw_compile() { done if [[ ${1} != -q ]]; then - print -P '%F{green}✓%f Done with compile.' + print -P 'Done with compile.' fi } @@ -76,7 +76,7 @@ _zimfw_build() { local -r ztarget=${ZIM_HOME}/init.zsh if [[ ${ztarget} -nt ${ZDOTDIR:-${HOME}}/.zimrc ]] && command cmp -s ${ztarget} ${1}; then if (( ! _zquiet )); then - print -PR "%F{green}✓%f %B${ztarget}:%b Already up to date" + print -PR "%F{green})%f %B${ztarget}:%b Already up to date" fi else if [[ -e ${ztarget} ]]; then @@ -84,11 +84,11 @@ _zimfw_build() { fi command mv -f ${1} ${ztarget} && \ if (( ! _zquiet )); then - print -PR "%F{green}✓%f %B${ztarget}:%b Updated. Restart your terminal for changes to take effect." + print -PR "%F{green})%f %B${ztarget}:%b Updated. Restart your terminal for changes to take effect." fi fi if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with build.' + print -P 'Done with build.' fi } =( print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" @@ -118,7 +118,7 @@ Startup options: return 1 fi if (( ! # )); then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}: Missing zmodule url%f" + print -u2 -PR "%F{red}x ${funcfiletrace[1]}: Missing zmodule url%f" _zfailed=1 return 1 fi @@ -140,7 +140,7 @@ Startup options: shift if [[ ${1} == (-n|--name) ]]; then if (( # < 2 )); then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" _zfailed=1 return 1 fi @@ -153,7 +153,7 @@ Startup options: case ${1} in -b|--branch|-t|--tag|-f|--fpath|-a|--autoload|-s|--source) if (( # < 2 )); then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" + print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Missing argument for zmodule option ${1}%f" _zfailed=1 return 1 fi @@ -189,7 +189,7 @@ Startup options: ;; -d|--disabled) zdisabled=1 ;; *) - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f" + print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Unknown zmodule option ${1}%f" _zfailed=1 return 1 ;; @@ -205,7 +205,7 @@ Startup options: _zdisableds+=(${zmodule}) else if [[ ! -d ${zdir} ]]; then - print -u2 -PR "%F{red}✗ ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" + print -u2 -PR "%F{red}x ${funcfiletrace[1]}:%B${zmodule}:%b Not installed%f" _zfailed=1 return 1 fi @@ -230,7 +230,7 @@ _zimfw_source_zimrc() { local -ri _zprepare_xargs=${1} local -i _zfailed=0 if ! source ${ZDOTDIR:-${HOME}}/.zimrc || (( _zfailed )); then - print -u2 -PR "%F{red}✗ Failed to source ${ZDOTDIR:-${HOME}}/.zimrc%f" + print -u2 -PR "%F{red}Failed to source %B${ZDOTDIR:-${HOME}}/.zimrc%b%f" return 1 fi } @@ -250,7 +250,7 @@ _zimfw_clean_compiled() { command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 command rm -f ${zopt_rm} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' + print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi } @@ -260,12 +260,12 @@ _zimfw_clean_dumpfile() { (( ! _zquiet )) && zopt='-v' command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' + print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 4a7ce44)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is f9dc5ea)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -282,7 +282,7 @@ _zimfw_uninstall() { fi done if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with uninstall.' + print -P 'Done with uninstall.' fi } @@ -297,16 +297,16 @@ _zimfw_upgrade() { fi if command cmp -s ${zscript}{,.new}; then if (( ! _zquiet )); then - print -P '%F{green}✓%f %Bzimfw.zsh:%b Already up to date' + print -P '%F{green})%f %Bzimfw.zsh:%b Already up to date' fi else command mv -f ${zscript}{,.old} && command mv -f ${zscript}{.new,} && \ if (( ! _zquiet )); then - print -P '%F{green}✓%f %Bzimfw.zsh:%b Upgraded. Restart your terminal for changes to take effect.' + print -P '%F{green})%f %Bzimfw.zsh:%b Upgraded. Restart your terminal for changes to take effect.' fi fi if (( ! _zquiet )); then - print -P '%F{green}✓%f Done with upgrade.' + print -P 'Done with upgrade.' fi } always { command rm -f ${zscript}.new @@ -361,13 +361,13 @@ if [[ -e \${DIR} ]]; then # Already exists return 0 fi -(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Installing \${MODULE} …\" +(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Installing \${MODULE} ...\" if ERR=\$(command git clone -b \${REV} -q --recursive \${URL} \${DIR} 2>&1); then if (( ! QUIET )); then - print -PR \${CLEAR_LINE}\"%F{green}✓%f %B\${MODULE}:%b Installed\" + print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Installed\" fi else - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git clone%f\"$'\n'\${(F):- \${(f)^ERR}} + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git clone%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi " @@ -381,9 +381,9 @@ readonly TYPE=\${4} readonly REV=\${5} readonly -i QUIET=\${6} readonly CLEAR_LINE=$'\E[2K\r' -(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Updating \${MODULE} …\" +(( ! QUIET )) && print -Rn \${CLEAR_LINE}\"Updating \${MODULE} ...\" if ! builtin cd -q \${DIR} 2>/dev/null; then - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Not installed%f\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Not installed%f\" return 1 fi if [[ \${PWD} != \$(command git rev-parse --show-toplevel 2>/dev/null) ]]; then @@ -391,17 +391,17 @@ if [[ \${PWD} != \$(command git rev-parse --show-toplevel 2>/dev/null) ]]; then return 0 fi if [[ \${URL} != \$(command git config --get remote.origin.url) ]]; then - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b URL does not match. Expected \${URL}. Will not try to update.%f\" + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b URL does not match. Expected \${URL}. Will not try to update.%f\" return 1 fi if [[ \${TYPE} == tag ]]; then if [[ \${REV} == \$(command git describe --tags --exact-match 2>/dev/null) ]]; then - (( ! QUIET )) && print -PR \${CLEAR_LINE}\"%F{green}✓%f %B\${MODULE}:%b Already up to date\" + (( ! QUIET )) && print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b Already up to date\" return 0 fi fi if ! ERR=\$(command git fetch -pq origin \${REV} 2>&1); then - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git fetch%f\"$'\n'\${(F):- \${(f)^ERR}} + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git fetch%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi if [[ \${TYPE} == branch ]]; then @@ -411,12 +411,12 @@ else fi LOG=\$(command git log --graph --color --format='%C(yellow)%h%C(reset) %s %C(cyan)(%cr)%C(reset)' ..\${LOG_REV} 2>/dev/null) if ! ERR=\$(command git checkout -q \${REV} -- 2>&1); then - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git checkout%f\"$'\n'\${(F):- \${(f)^ERR}} + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git checkout%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi if [[ \${TYPE} == branch ]]; then if ! OUT=\$(command git merge --ff-only --no-progress -n 2>&1); then - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git merge%f\"$'\n'\${(F):- \${(f)^OUT}} + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git merge%f\"$'\n'\${(F):- \${(f)^OUT}} return 1 fi # keep just first line of OUT @@ -427,10 +427,10 @@ fi if ERR=\$(command git submodule update --init --recursive -q 2>&1); then if (( ! QUIET )); then [[ -n \${LOG} ]] && OUT=\${OUT}$'\n'\${(F):- \${(f)^LOG}} - print -PR \${CLEAR_LINE}\"%F{green}✓%f %B\${MODULE}:%b \${OUT}\" + print -PR \${CLEAR_LINE}\"%F{green})%f %B\${MODULE}:%b \${OUT}\" fi else - print -u2 -PR \${CLEAR_LINE}\"%F{red}✗ %B\${MODULE}:%b Error during git submodule update%f\"$'\n'\${(F):- \${(f)^ERR}} + print -u2 -PR \${CLEAR_LINE}\"%F{red}x %B\${MODULE}:%b Error during git submodule update%f\"$'\n'\${(F):- \${(f)^ERR}} return 1 fi " @@ -453,7 +453,7 @@ fi _zimfw_source_zimrc 1 || return 1 print -Rn ${_zmodules_xargs} | xargs -0 -n6 -P10 zsh -c ${ztool} ${1} && \ if (( ! _zquiet )); then - print -PR "%F{green}✓%f Done with ${1}. Restart your terminal for any changes to take effect." + print -PR "Done with ${1}. Restart your terminal for any changes to take effect." fi && \ _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; From aade4704b151fb0653ae1fa13aaab6cf8c27f3b9 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 14 Dec 2019 22:21:34 -0500 Subject: [PATCH 21/26] Generate login_init.zsh file So we can have the following code in the zlogin template: source ${ZIM_HOME}/login_init.zsh -q &! instead of depending on the zimfw function there. This allows fixing the issue were a non-interactive login shell currently yields: command not found: zimfw. To fully fix the issue, we also need a new zshenv template containing: ZIM_HOME=${ZDOTDIR:-${HOME}}/.zim Templates will be updated in the install script. --- src/stage1/30_init.zsh.erb | 2 - src/stage1/80_zimfw.zsh.erb | 4 - src/{stage1 => stage2}/20_guard.zsh.erb | 3 + src/stage2/28_zimfw_mv.zsh.erb | 15 ++ src/stage2/29_zimfw_build_init.zsh.erb | 13 ++ src/stage2/29_zimfw_build_login_init.zsh.erb | 6 + src/stage2/30_zimfw_build.zsh.erb | 24 +--- src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 2 +- src/stage2/50_zimfw_compile.zsh.erb | 3 + src/stage2/50_zimfw_upgrade.zsh.erb | 25 ++-- src/stage2/80_zimfw.zsh.erb | 10 +- .../login_init.zsh.erb} | 6 +- src/zimfw.zsh.erb | 1 - zimfw.zsh | 136 +++++++++--------- 14 files changed, 126 insertions(+), 124 deletions(-) delete mode 100644 src/stage1/30_init.zsh.erb delete mode 100644 src/stage1/80_zimfw.zsh.erb rename src/{stage1 => stage2}/20_guard.zsh.erb (84%) create mode 100644 src/stage2/28_zimfw_mv.zsh.erb create mode 100644 src/stage2/29_zimfw_build_init.zsh.erb create mode 100644 src/stage2/29_zimfw_build_login_init.zsh.erb create mode 100644 src/stage2/50_zimfw_compile.zsh.erb rename src/{stage1/50_zimfw_compile.zsh.erb => templates/login_init.zsh.erb} (95%) diff --git a/src/stage1/30_init.zsh.erb b/src/stage1/30_init.zsh.erb deleted file mode 100644 index 0e62c46..0000000 --- a/src/stage1/30_init.zsh.erb +++ /dev/null @@ -1,2 +0,0 @@ -# Define Zim location -: ${ZIM_HOME=${0:A:h}} diff --git a/src/stage1/80_zimfw.zsh.erb b/src/stage1/80_zimfw.zsh.erb deleted file mode 100644 index 64ea658..0000000 --- a/src/stage1/80_zimfw.zsh.erb +++ /dev/null @@ -1,4 +0,0 @@ -if [[ ${1} == (compile|login-init) && ${2} == (|-q) ]]; then - _zimfw_compile ${2} - return -fi diff --git a/src/stage1/20_guard.zsh.erb b/src/stage2/20_guard.zsh.erb similarity index 84% rename from src/stage1/20_guard.zsh.erb rename to src/stage2/20_guard.zsh.erb index d46518d..fff3721 100644 --- a/src/stage1/20_guard.zsh.erb +++ b/src/stage2/20_guard.zsh.erb @@ -2,3 +2,6 @@ autoload -Uz is-at-least && if ! is-at-least <%= min_zsh_version %>; then print -u2 -R "${0}: Error starting Zim. You're using Zsh version ${ZSH_VERSION} and versions < <%= min_zsh_version %> are not supported. Update your Zsh." return 1 fi + +# Define Zim location +: ${ZIM_HOME=${0:A:h}} diff --git a/src/stage2/28_zimfw_mv.zsh.erb b/src/stage2/28_zimfw_mv.zsh.erb new file mode 100644 index 0000000..8da341c --- /dev/null +++ b/src/stage2/28_zimfw_mv.zsh.erb @@ -0,0 +1,15 @@ +_zimfw_mv() { + if command cmp -s ${2} ${1}; then + if (( ! _zquiet )); then + print -PR "<%= okay %>%B${2}:%b Already up to date" + fi + else + if [[ -e ${2} ]]; then + command mv -f ${2}{,.old} || return 1 + fi + command mv -f ${1} ${2} && \ + if (( ! _zquiet )); then + print -PR "<%= okay %>%B${2}:%b Updated. Restart your terminal for changes to take effect." + fi + fi +} diff --git a/src/stage2/29_zimfw_build_init.zsh.erb b/src/stage2/29_zimfw_build_init.zsh.erb new file mode 100644 index 0000000..c3a4c7e --- /dev/null +++ b/src/stage2/29_zimfw_build_init.zsh.erb @@ -0,0 +1,13 @@ +_zimfw_build_init() { + local -r ztarget=${ZIM_HOME}/init.zsh + # Force update of init.zsh if it's older than .zimrc + if [[ ${ztarget} -ot <%= home %>/.zimrc ]]; then + command mv -f ${ztarget}{,.old} || return 1 + fi + _zimfw_mv =( + print -R "zimfw() { source ${ZIM_HOME}/<%= script_filename %> \"\${@}\" }" + (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:P}' ${fpath})' + (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} + print -Rn ${(F):-source ${^_zscripts:P}} + ) ${ztarget} +} diff --git a/src/stage2/29_zimfw_build_login_init.zsh.erb b/src/stage2/29_zimfw_build_login_init.zsh.erb new file mode 100644 index 0000000..89eb2f1 --- /dev/null +++ b/src/stage2/29_zimfw_build_login_init.zsh.erb @@ -0,0 +1,6 @@ +_zimfw_build_login_init() { + local -r ztarget=${ZIM_HOME}/login_init.zsh + _zimfw_mv =( + print -Rn "<%= render_escaped("src/templates/login_init.zsh.erb") %>" + ) ${ztarget} +} diff --git a/src/stage2/30_zimfw_build.zsh.erb b/src/stage2/30_zimfw_build.zsh.erb index 12f71af..8226784 100644 --- a/src/stage2/30_zimfw_build.zsh.erb +++ b/src/stage2/30_zimfw_build.zsh.erb @@ -1,26 +1,6 @@ _zimfw_build() { - () { - local -r ztarget=${ZIM_HOME}/init.zsh - if [[ ${ztarget} -nt <%= home %>/.zimrc ]] && command cmp -s ${ztarget} ${1}; then + _zimfw_build_init && _zimfw_build_login_init && \ if (( ! _zquiet )); then - print -PR "<%= okay %>%B${ztarget}:%b Already up to date" + print -P '<%= done %>Done with build.' fi - else - if [[ -e ${ztarget} ]]; then - command mv -f ${ztarget}{,.old} || return 1 - fi - command mv -f ${1} ${ztarget} && \ - if (( ! _zquiet )); then - print -PR "<%= okay %>%B${ztarget}:%b Updated. Restart your terminal for changes to take effect." - fi - fi - if (( ! _zquiet )); then - print -P '<%= done %>Done with build.' - fi - } =( - print -R "zimfw() { source ${ZIM_HOME}/<%= script_filename %> \"\${@}\" }" - (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:P}' ${fpath})' - (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} - print -Rn ${(F):-source ${^_zscripts:P}} - ) } diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb index aa8d637..4f7efa6 100644 --- a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -1,6 +1,6 @@ _zimfw_clean_dumpfile() { local zdumpfile zopt - zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="<%= home %>/.zcompdump" + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump (( ! _zquiet )) && zopt='-v' command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 if (( ! _zquiet )); then diff --git a/src/stage2/50_zimfw_compile.zsh.erb b/src/stage2/50_zimfw_compile.zsh.erb new file mode 100644 index 0000000..3d77b5d --- /dev/null +++ b/src/stage2/50_zimfw_compile.zsh.erb @@ -0,0 +1,3 @@ +_zimfw_compile() { + source ${ZIM_HOME}/login_init.zsh "${@}" +} diff --git a/src/stage2/50_zimfw_upgrade.zsh.erb b/src/stage2/50_zimfw_upgrade.zsh.erb index 4b14a6f..d3b1c8a 100644 --- a/src/stage2/50_zimfw_upgrade.zsh.erb +++ b/src/stage2/50_zimfw_upgrade.zsh.erb @@ -1,26 +1,17 @@ _zimfw_upgrade() { - local -r zscript=${ZIM_HOME}/<%= script_filename %> + local -r ztarget=${ZIM_HOME}/<%= script_filename %> local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/<%= script_filename %> { if (( ${+commands[wget]} )); then - command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 + command wget -nv -O ${ztarget}.new ${zurl} || return 1 else - command curl -fsSL -o ${zscript}.new ${zurl} || return 1 - fi - if command cmp -s ${zscript}{,.new}; then - if (( ! _zquiet )); then - print -P '<%= okay %>%B<%= script_filename %>:%b Already up to date' - fi - else - command mv -f ${zscript}{,.old} && command mv -f ${zscript}{.new,} && \ - if (( ! _zquiet )); then - print -P '<%= okay %>%B<%= script_filename %>:%b Upgraded. Restart your terminal for changes to take effect.' - fi - fi - if (( ! _zquiet )); then - print -P '<%= done %>Done with upgrade.' + command curl -fsSL -o ${ztarget}.new ${zurl} || return 1 fi + _zimfw_mv ${ztarget}{.new,} && \ + if (( ! _zquiet )); then + print -P '<%= done %>Done with upgrade.' + fi } always { - command rm -f ${zscript}.new + command rm -f ${ztarget}.new } } diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 12a7989..8e943c3 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -45,14 +45,10 @@ Options: case ${1} in build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; init) _zimfw_source_zimrc && _zimfw_build ;; - clean) - _zimfw_source_zimrc && \ - _zimfw_clean_compiled && \ - _zimfw_clean_dumpfile - ;; + clean) _zimfw_clean_compiled && _zimfw_clean_dumpfile ;; clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; - compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; + compile) _zimfw_build_login_init && _zimfw_compile ${2} ;; info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 @@ -63,7 +59,7 @@ Options: _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;; - upgrade) _zimfw_upgrade && _zimfw_compile ;; + upgrade) _zimfw_upgrade && _zimfw_build_login_init && _zimfw_compile ${2} ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 diff --git a/src/stage1/50_zimfw_compile.zsh.erb b/src/templates/login_init.zsh.erb similarity index 95% rename from src/stage1/50_zimfw_compile.zsh.erb rename to src/templates/login_init.zsh.erb index 71e2384..30f43a9 100644 --- a/src/stage1/50_zimfw_compile.zsh.erb +++ b/src/templates/login_init.zsh.erb @@ -1,10 +1,10 @@ -_zimfw_compile() { +() { setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB autoload -U zrecompile local zdumpfile zdir zfile # Compile the completion cache; significant speedup - zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="<%= home %>/.zcompdump" + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump if [[ -f ${zdumpfile} ]]; then zrecompile -p ${1} ${zdumpfile} || return 1 fi @@ -30,4 +30,4 @@ _zimfw_compile() { if [[ ${1} != -q ]]; then print -P '<%= done %>Done with compile.' fi -} +} "${@}" diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index 29cb8d0..3314711 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -35,6 +35,5 @@ zim = Zim.new # DO NOT DIRECTLY EDIT THIS FILE! <%= zim.render_commented("LICENSE") %> -<%= zim.render_all("src/stage1/*.erb") %> <%= zim.render_all("src/stage2/*.erb") %> zimfw "${@}" diff --git a/zimfw.zsh b/zimfw.zsh index 565ac7e..752d031 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -32,70 +32,81 @@ fi # Define Zim location : ${ZIM_HOME=${0:A:h}} -_zimfw_compile() { +_zimfw_mv() { + if command cmp -s ${2} ${1}; then + if (( ! _zquiet )); then + print -PR "%F{green})%f %B${2}:%b Already up to date" + fi + else + if [[ -e ${2} ]]; then + command mv -f ${2}{,.old} || return 1 + fi + command mv -f ${1} ${2} && \ + if (( ! _zquiet )); then + print -PR "%F{green})%f %B${2}:%b Updated. Restart your terminal for changes to take effect." + fi + fi +} + +_zimfw_build_init() { + local -r ztarget=${ZIM_HOME}/init.zsh + # Force update of init.zsh if it's older than .zimrc + if [[ ${ztarget} -ot ${ZDOTDIR:-${HOME}}/.zimrc ]]; then + command mv -f ${ztarget}{,.old} || return 1 + fi + _zimfw_mv =( + print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" + (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:P}' ${fpath})' + (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} + print -Rn ${(F):-source ${^_zscripts:P}} + ) ${ztarget} +} + +_zimfw_build_login_init() { + local -r ztarget=${ZIM_HOME}/login_init.zsh + _zimfw_mv =( + print -Rn "() { setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB autoload -U zrecompile local zdumpfile zdir zfile # Compile the completion cache; significant speedup - zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" - if [[ -f ${zdumpfile} ]]; then - zrecompile -p ${1} ${zdumpfile} || return 1 + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=\${ZDOTDIR:-\${HOME}}/.zcompdump + if [[ -f \${zdumpfile} ]]; then + zrecompile -p \${1} \${zdumpfile} || return 1 fi # Compile .zshrc - zrecompile -p ${1} ${ZDOTDIR:-${HOME}}/.zshrc || return 1 + zrecompile -p \${1} \${ZDOTDIR:-\${HOME}}/.zshrc || return 1 # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - zfile=(${zdir}/^(*.*)(N-.)) - if [[ -w ${zdir:h} && -n ${zfile} ]]; then - zfile=(${${(M)zfile%/*/*}#/}) - (builtin cd -q ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 + for zdir in \${fpath}; do + [[ \${zdir} == (.|..) || \${zdir} == (.|..)/* ]] && continue + zfile=(\${zdir}/^(*.*)(N-.)) + if [[ -w \${zdir:h} && -n \${zfile} ]]; then + zfile=(\${\${(M)zfile%/*/*}#/}) + (builtin cd -q \${zdir:h} && zrecompile -p \${1} \${zdir:t}.zwc \${zfile}) || return 1 fi done # Compile scripts - for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do - zrecompile -p ${1} ${zfile} || return 1 + for zfile in \${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do + zrecompile -p \${1} \${zfile} || return 1 done - if [[ ${1} != -q ]]; then + if [[ \${1} != -q ]]; then print -P 'Done with compile.' fi +} \"\${@}\" +" + ) ${ztarget} } -if [[ ${1} == (compile|login-init) && ${2} == (|-q) ]]; then - _zimfw_compile ${2} - return -fi - _zimfw_build() { - () { - local -r ztarget=${ZIM_HOME}/init.zsh - if [[ ${ztarget} -nt ${ZDOTDIR:-${HOME}}/.zimrc ]] && command cmp -s ${ztarget} ${1}; then + _zimfw_build_init && _zimfw_build_login_init && \ if (( ! _zquiet )); then - print -PR "%F{green})%f %B${ztarget}:%b Already up to date" + print -P 'Done with build.' fi - else - if [[ -e ${ztarget} ]]; then - command mv -f ${ztarget}{,.old} || return 1 - fi - command mv -f ${1} ${ztarget} && \ - if (( ! _zquiet )); then - print -PR "%F{green})%f %B${ztarget}:%b Updated. Restart your terminal for changes to take effect." - fi - fi - if (( ! _zquiet )); then - print -P 'Done with build.' - fi - } =( - print -R "zimfw() { source ${ZIM_HOME}/zimfw.zsh \"\${@}\" }" - (( ${#_zfpaths} )) && print -R 'fpath=('${_zfpaths:P}' ${fpath})' - (( ${#_zfunctions} )) && print -R 'autoload -Uz '${_zfunctions} - print -Rn ${(F):-source ${^_zscripts:P}} - ) } zmodule() { @@ -256,7 +267,7 @@ _zimfw_clean_compiled() { _zimfw_clean_dumpfile() { local zdumpfile zopt - zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile="${ZDOTDIR:-${HOME}}/.zcompdump" + zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump (( ! _zquiet )) && zopt='-v' command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 if (( ! _zquiet )); then @@ -264,8 +275,12 @@ _zimfw_clean_dumpfile() { fi } +_zimfw_compile() { + source ${ZIM_HOME}/login_init.zsh "${@}" +} + _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is f9dc5ea)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 86f177a)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) @@ -287,29 +302,20 @@ _zimfw_uninstall() { } _zimfw_upgrade() { - local -r zscript=${ZIM_HOME}/zimfw.zsh + local -r ztarget=${ZIM_HOME}/zimfw.zsh local -r zurl=https://raw.githubusercontent.com/zimfw/zimfw/develop/zimfw.zsh { if (( ${+commands[wget]} )); then - command wget -nv ${1} -O ${zscript}.new ${zurl} || return 1 + command wget -nv -O ${ztarget}.new ${zurl} || return 1 else - command curl -fsSL -o ${zscript}.new ${zurl} || return 1 - fi - if command cmp -s ${zscript}{,.new}; then - if (( ! _zquiet )); then - print -P '%F{green})%f %Bzimfw.zsh:%b Already up to date' - fi - else - command mv -f ${zscript}{,.old} && command mv -f ${zscript}{.new,} && \ - if (( ! _zquiet )); then - print -P '%F{green})%f %Bzimfw.zsh:%b Upgraded. Restart your terminal for changes to take effect.' - fi - fi - if (( ! _zquiet )); then - print -P 'Done with upgrade.' + command curl -fsSL -o ${ztarget}.new ${zurl} || return 1 fi + _zimfw_mv ${ztarget}{.new,} && \ + if (( ! _zquiet )); then + print -P 'Done with upgrade.' + fi } always { - command rm -f ${zscript}.new + command rm -f ${ztarget}.new } } @@ -440,14 +446,10 @@ fi case ${1} in build) _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; init) _zimfw_source_zimrc && _zimfw_build ;; - clean) - _zimfw_source_zimrc && \ - _zimfw_clean_compiled && \ - _zimfw_clean_dumpfile - ;; + clean) _zimfw_clean_compiled && _zimfw_clean_dumpfile ;; clean-compiled) _zimfw_clean_compiled ;; clean-dumpfile) _zimfw_clean_dumpfile ;; - compile|login-init) _zimfw_source_zimrc && _zimfw_compile ${2} ;; + compile) _zimfw_build_login_init && _zimfw_compile ${2} ;; info) _zimfw_info ;; install|update) _zimfw_source_zimrc 1 || return 1 @@ -458,7 +460,7 @@ fi _zimfw_source_zimrc && _zimfw_build && _zimfw_compile ${2} ;; uninstall) _zimfw_source_zimrc && _zimfw_uninstall ;; - upgrade) _zimfw_upgrade && _zimfw_compile ;; + upgrade) _zimfw_upgrade && _zimfw_build_login_init && _zimfw_compile ${2} ;; *) print -u2 -PR "%F{red}${0}: Unknown action ${1}%f"$'\n'${zusage} return 1 From c13fe60b02e6a152ce0c7f78f15e07e5b5dbd196 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Sat, 14 Dec 2019 22:41:19 -0500 Subject: [PATCH 22/26] Update README.md with new zshenv template --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ed6463f..bd10aa7 100644 --- a/README.md +++ b/README.md @@ -67,9 +67,10 @@ If you have a different shell framework installed (like oh-my-zsh or prezto), `~/.zim/zimfw.zsh`. 4. Add the lines in the following templates to the respective dot files: - * [~/.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) - * [~/.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) + * [~/.zshenv](https://github.com/zimfw/install/blob/develop/src/templates/zshenv) * [~/.zshrc](https://github.com/zimfw/install/blob/develop/src/templates/zshrc) + * [~/.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) + * [~/.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) 5. Install the modules defined in `~/.zimrc` and build the static initialization script: @@ -108,7 +109,7 @@ By default, the module name is the last component in the ``. Use the * `-s|--source `: Source specified file. The file path is relative to the module root directory. Default: the file with largest size matching `{init.zsh|module_name.{zsh|plugin.zsh|zsh-theme|sh}}`, if any exists. -* `-d|--disabled`: Don't use or clean the module. +* `-d|--disabled`: Don't use or uninstall the module. ### zimfw @@ -134,7 +135,7 @@ Uninstalling ------------ The best way to remove Zim is to manually delete `~/.zim`, `~/.zimrc`, and -remove the initialization lines from your `~/.zshrc` and `~/.zlogin`. +remove the initialization lines from your `~/.zshenv`, `~/.zshrc` and `~/.zlogin`. [history-substring-search]: https://zimfw.github.io/images/zim_history-substring-search.gif [syntax-highlighting]: https://zimfw.github.io/images/zim_syntax-highlighting.gif From ae3e71cb84a538bad400ecca881be4ef5add5f33 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Fri, 27 Dec 2019 09:51:02 -0500 Subject: [PATCH 23/26] Don't create function digest files At least until Zsh version 5.7.1, no performance improvement is observed out of using those. In some cases, the performance is even worsened, like when using autoload -w functions_digest.zwc instead of autoload func_name1 func_name2 ... --- src/stage2/50_zimfw_clean_compiled.zsh.erb | 17 ++------- src/stage2/50_zimfw_clean_dumpfile.zsh.erb | 2 +- src/templates/login_init.zsh.erb | 22 ++++------- src/zimfw.zsh.erb | 5 ++- zimfw.zsh | 43 +++++++--------------- 5 files changed, 28 insertions(+), 61 deletions(-) diff --git a/src/stage2/50_zimfw_clean_compiled.zsh.erb b/src/stage2/50_zimfw_clean_compiled.zsh.erb index a711ac3..eae355e 100644 --- a/src/stage2/50_zimfw_clean_compiled.zsh.erb +++ b/src/stage2/50_zimfw_clean_compiled.zsh.erb @@ -1,17 +1,8 @@ _zimfw_clean_compiled() { - local zopt_find zopt_rm zdir - if (( ! _zquiet )); then - zopt_find='-print' - zopt_rm='-v' - fi - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - if [[ -w ${zdir:h} ]]; then - command rm -f ${zopt_rm} ${zdir}.zwc{,.old} || return 1 - fi - done - command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 - command rm -f ${zopt_rm} <%= home %>/.zshrc.zwc{,.old} || return 1 + local zopt + (( ! _zquiet )) && zopt='-v' + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1 + command rm -f ${zopt} <%= home %>/<%= startup_files_glob %>.zwc(|.old)(N) || return 1 if (( ! _zquiet )); then print -P '<%= done %>Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi diff --git a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb index 4f7efa6..8cd2e0f 100644 --- a/src/stage2/50_zimfw_clean_dumpfile.zsh.erb +++ b/src/stage2/50_zimfw_clean_dumpfile.zsh.erb @@ -2,7 +2,7 @@ _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump (( ! _zquiet )) && zopt='-v' - command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 + command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1 if (( ! _zquiet )); then print -P '<%= done %>Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi diff --git a/src/templates/login_init.zsh.erb b/src/templates/login_init.zsh.erb index 30f43a9..3076a44 100644 --- a/src/templates/login_init.zsh.erb +++ b/src/templates/login_init.zsh.erb @@ -1,7 +1,7 @@ () { setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB - autoload -U zrecompile - local zdumpfile zdir zfile + autoload -Uz zrecompile + local zdumpfile zfile # Compile the completion cache; significant speedup zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=<%= home %>/.zcompdump @@ -9,21 +9,13 @@ zrecompile -p ${1} ${zdumpfile} || return 1 fi - # Compile .zshrc - zrecompile -p ${1} <%= home %>/.zshrc || return 1 - - # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - zfile=(${zdir}/^(*.*)(N-.)) - if [[ -w ${zdir:h} && -n ${zfile} ]]; then - zfile=(${${(M)zfile%/*/*}#/}) - (builtin cd -q ${zdir:h} && zrecompile -p ${1} ${zdir:t}.zwc ${zfile}) || return 1 - fi + # Compile Zsh startup files + for zfile in ${1} <%= home %>/<%= startup_files_glob %>(N-.); do + zrecompile -p ${1} ${zfile} || return 1 done - # Compile scripts - for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do + # Compile Zim scripts + for zfile in ${ZIM_HOME}/(^*test*/)#*.zsh(|-theme)(N-.); do zrecompile -p ${1} ${zfile} || return 1 done diff --git a/src/zimfw.zsh.erb b/src/zimfw.zsh.erb index 3314711..5061aca 100644 --- a/src/zimfw.zsh.erb +++ b/src/zimfw.zsh.erb @@ -1,11 +1,12 @@ <% class Zim - attr_reader :home, :min_zsh_version, :script_filename, :version, :ellipsis, :okay, :error, :done, :failed + attr_reader :home, :min_zsh_version, :script_filename, :startup_files_glob, :version, :ellipsis, :okay, :error, :done, :failed def initialize @home = "${ZDOTDIR:-${HOME}}" @min_zsh_version = "5.2" @script_filename = "zimfw.zsh" + @startup_files_glob = ".z(shenv|shrc|login|logout)" @version = "1.0.0-SNAPSHOT" @ellipsis = " ..." @okay = "%F{green})%f " @@ -23,7 +24,7 @@ class Zim end def render_escaped(filename) - render(filename).gsub(/(\$[^']|"|`)/, "\\\\\\1") + render(filename).gsub(/(?=\$[^']|"|`)/, "\\\\") end def render_commented(filename) diff --git a/zimfw.zsh b/zimfw.zsh index 752d031..b69f5d8 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -67,8 +67,8 @@ _zimfw_build_login_init() { _zimfw_mv =( print -Rn "() { setopt LOCAL_OPTIONS CASE_GLOB EXTENDED_GLOB - autoload -U zrecompile - local zdumpfile zdir zfile + autoload -Uz zrecompile + local zdumpfile zfile # Compile the completion cache; significant speedup zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=\${ZDOTDIR:-\${HOME}}/.zcompdump @@ -76,21 +76,13 @@ _zimfw_build_login_init() { zrecompile -p \${1} \${zdumpfile} || return 1 fi - # Compile .zshrc - zrecompile -p \${1} \${ZDOTDIR:-\${HOME}}/.zshrc || return 1 - - # Compile autoloaded functions, taken from zrecompile doc in zshcontrib(1) - for zdir in \${fpath}; do - [[ \${zdir} == (.|..) || \${zdir} == (.|..)/* ]] && continue - zfile=(\${zdir}/^(*.*)(N-.)) - if [[ -w \${zdir:h} && -n \${zfile} ]]; then - zfile=(\${\${(M)zfile%/*/*}#/}) - (builtin cd -q \${zdir:h} && zrecompile -p \${1} \${zdir:t}.zwc \${zfile}) || return 1 - fi + # Compile Zsh startup files + for zfile in \${1} \${ZDOTDIR:-\${HOME}}/.z(shenv|shrc|login|logout)(N-.); do + zrecompile -p \${1} \${zfile} || return 1 done - # Compile scripts - for zfile in \${ZIM_HOME}/(^*test*/)#*.zsh{,-theme}(N-.); do + # Compile Zim scripts + for zfile in \${ZIM_HOME}/(^*test*/)#*.zsh(|-theme)(N-.); do zrecompile -p \${1} \${zfile} || return 1 done @@ -247,19 +239,10 @@ _zimfw_source_zimrc() { } _zimfw_clean_compiled() { - local zopt_find zopt_rm zdir - if (( ! _zquiet )); then - zopt_find='-print' - zopt_rm='-v' - fi - for zdir in ${fpath}; do - [[ ${zdir} == (.|..) || ${zdir} == (.|..)/* ]] && continue - if [[ -w ${zdir:h} ]]; then - command rm -f ${zopt_rm} ${zdir}.zwc{,.old} || return 1 - fi - done - command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -delete ${zopt_find} || return 1 - command rm -f ${zopt_rm} ${ZDOTDIR:-${HOME}}/.zshrc.zwc{,.old} || return 1 + local zopt + (( ! _zquiet )) && zopt='-v' + command find ${ZIM_HOME} \( -name '*.zwc' -o -name '*.zwc.old' \) -exec rm -f ${zopt} {} \; || return 1 + command rm -f ${zopt} ${ZDOTDIR:-${HOME}}/.z(shenv|shrc|login|logout).zwc(|.old)(N) || return 1 if (( ! _zquiet )); then print -P 'Done with clean-compiled. Run %Bzimfw compile%b to re-compile.' fi @@ -269,7 +252,7 @@ _zimfw_clean_dumpfile() { local zdumpfile zopt zstyle -s ':zim:completion' dumpfile 'zdumpfile' || zdumpfile=${ZDOTDIR:-${HOME}}/.zcompdump (( ! _zquiet )) && zopt='-v' - command rm -f ${zopt} ${zdumpfile}{,.zwc{,.old}} || return 1 + command rm -f ${zopt} ${zdumpfile}(|.zwc(|.old)) || return 1 if (( ! _zquiet )); then print -P 'Done with clean-dumpfile. Restart your terminal to dump an updated configuration.' fi @@ -280,7 +263,7 @@ _zimfw_compile() { } _zimfw_info() { - print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 86f177a)' + print 'Zim version: 1.0.0-SNAPSHOT (previous commit is 94526d6)' print -R 'ZIM_HOME: '${ZIM_HOME} print -R 'Zsh version: '${ZSH_VERSION} print -R 'System info: '$(command uname -a) From 5587ea14da2088366522fc28dc60bb3d4a99fbe0 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 2 Jan 2020 12:11:51 -0500 Subject: [PATCH 24/26] Update autoload functions glob based on glob used in Prezto: https://github.com/sorin-ionescu/prezto/blob/1bc0da5f48init.zsh#L79 and in compinit: https://github.com/zsh-users/zsh/blob/b816291a17/Completion/compinit#L499 --- src/stage2/30_zmodule.zsh.erb | 2 +- zimfw.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 3cc9f2e..9c233e2 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -113,7 +113,7 @@ Startup options: if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit # prompt_*_setup functions are autoloaded by promptinit - zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + zfunctions+=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t)) fi if (( ! ${#zscripts} )); then zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) diff --git a/zimfw.zsh b/zimfw.zsh index b69f5d8..10d8918 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -216,7 +216,7 @@ Startup options: if (( ! ${#zfunctions} )); then # _* functions are autoloaded by compinit # prompt_*_setup functions are autoloaded by promptinit - zfunctions+=(${^zfpaths}/^(*.*|_*|prompt_*_setup)(N-.:t)) + zfunctions+=(${^zfpaths}/^(*~|*.zwc(|.old)|_*|prompt_*_setup)(N-.:t)) fi if (( ! ${#zscripts} )); then zscripts+=(${zdir}/(init.zsh|${zmodule:t}.(zsh|plugin.zsh|zsh-theme|sh))(NOL[1])) From 0b19b2f89acead2c294980a93acbe3148e2db255 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 2 Jan 2020 12:23:32 -0500 Subject: [PATCH 25/26] Update README.md and zimfw output due to latest changes on how Zim works. --- README.md | 2 +- src/stage2/30_zmodule.zsh.erb | 4 ++-- src/stage2/80_zimfw.zsh.erb | 2 +- zimfw.zsh | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bd10aa7..12170ae 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ If you have a different shell framework installed (like oh-my-zsh or prezto), * [~/.zlogin](https://github.com/zimfw/install/blob/develop/src/templates/zlogin) * [~/.zimrc](https://github.com/zimfw/install/blob/develop/src/templates/zimrc) -5. Install the modules defined in `~/.zimrc` and build the static initialization script: +5. Install the modules defined in `~/.zimrc` and build the initialization scripts: source ~/.zim/zimfw.zsh install diff --git a/src/stage2/30_zmodule.zsh.erb b/src/stage2/30_zmodule.zsh.erb index 9c233e2..9099c88 100644 --- a/src/stage2/30_zmodule.zsh.erb +++ b/src/stage2/30_zmodule.zsh.erb @@ -11,10 +11,10 @@ Startup options: %B-f%b|%B--fpath%b Add specified path to fpath %B-a%b|%B--autoload%b Autoload specified function %B-s%b|%B--source%b Source specified file - %B-d%b|%B--disabled%b Don't use or clean the module + %B-d%b|%B--disabled%b Don't use or uninstall the module " if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then - print -u2 -PR "%F{red}${0}: Must be called from <%= home %>/.zimrc%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Must be called from %B<%= home %>/.zimrc%b%f"$'\n'${zusage} return 1 fi if (( ! # )); then diff --git a/src/stage2/80_zimfw.zsh.erb b/src/stage2/80_zimfw.zsh.erb index 8e943c3..f276ebd 100644 --- a/src/stage2/80_zimfw.zsh.erb +++ b/src/stage2/80_zimfw.zsh.erb @@ -3,7 +3,7 @@ zimfw() { Usage: %B${0}%b [%B-q%b] Actions: - %Bbuild%b Build init.zsh + %Bbuild%b Build init.zsh and login_init.zsh %Bclean%b Clean all (see below) %Bclean-compiled%b Clean Zsh compiled files %Bclean-dumpfile%b Clean completion dump file diff --git a/zimfw.zsh b/zimfw.zsh index 10d8918..85d7f57 100644 --- a/zimfw.zsh +++ b/zimfw.zsh @@ -114,10 +114,10 @@ Startup options: %B-f%b|%B--fpath%b Add specified path to fpath %B-a%b|%B--autoload%b Autoload specified function %B-s%b|%B--source%b Source specified file - %B-d%b|%B--disabled%b Don't use or clean the module + %B-d%b|%B--disabled%b Don't use or uninstall the module " if [[ ${${funcfiletrace[1]%:*}:t} != .zimrc ]]; then - print -u2 -PR "%F{red}${0}: Must be called from ${ZDOTDIR:-${HOME}}/.zimrc%f"$'\n'${zusage} + print -u2 -PR "%F{red}${0}: Must be called from %B${ZDOTDIR:-${HOME}}/.zimrc%b%f"$'\n'${zusage} return 1 fi if (( ! # )); then @@ -307,7 +307,7 @@ zimfw() { Usage: %B${0}%b [%B-q%b] Actions: - %Bbuild%b Build init.zsh + %Bbuild%b Build init.zsh and login_init.zsh %Bclean%b Clean all (see below) %Bclean-compiled%b Clean Zsh compiled files %Bclean-dumpfile%b Clean completion dump file From d1b984aeb2214ffad30d753ae2ecb7a7a11b42a1 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Thu, 2 Jan 2020 12:25:22 -0500 Subject: [PATCH 26/26] Update .gitignore due to latest changes on how Zim works. --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 54089f6..ffc0e3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,9 @@ *.swp *.zwc *.zwc.old -custom/ +/modules/ +/init.zsh +/init.zsh.old +/login_init.zsh +/login_init.zsh.old +/zimfw.zsh.old