Skip to content

Commit

Permalink
refactor(workspace): ⚡️ Update to latest zsh plugin standart. Organiz…
Browse files Browse the repository at this point in the history
  • Loading branch information
ss-o committed Apr 8, 2022
1 parent ea10d6c commit ba5217e
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 61 deletions.
59 changes: 54 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@

# Space or Tabs?
# https://stackoverflow.com/questions/35649847/objective-reasons-for-using-spaces-instead-of-tabs-for-indentation
# https://stackoverflow.com/questions/12093748/how-to-use-tabs-instead-of-spaces-in-a-shell-script
#
# 1. What happens when I press the Tab key in my text editor?
# 2. What happens when I request my editor to indent one or more lines?
# 3. What happens when I view a file containing U+0009 HORIZONTAL TAB characters?
#
# Answers:
#
# 1. Pressing the Tab key should indent the current line (or selected lines) one additional level.
# 2. As a secondary alternative, I can also tolerate an editor that,
# like Emacs, uses this key for a context-sensitive fix-my-indentation command.
# 3. Indenting one or more lines should follow the reigning convention, if consensus is sufficiently strong; otherwise,
# I greatly prefer 2-space indentation at each level. U+0009 characters should shift subsequent characters to the next tab stop.
#
# Note: VIM users should use alternate marks [[[ and ]]] as the original ones can confuse nested substitutions, e.g.: ${${${VAR}}}
# # Space or Tabs? https://stackoverflow.com/questions/35649847/objective-reasons-for-using-spaces-instead-of-tabs-for-indentation
#
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et

root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
trim_trailing_whitespace = true

[**.{md,rst}]
[*.{md,rst}]
insert_final_newline = false
trim_trailing_whitespace = false

[*.{sh,bash,zsh,fish}]
indent_style = space
indent_size = 2
tab_width = 2

[Makefile]
indent_style = tab
indent_size = 4

[*.{css,less}]
indent_style = space
indent_size = 2

[*.{py,rb}]
indent_style = space
indent_size = 4

[*.{go,java,scala,groovy,kotlin}]
indent_style = tab
indent_size = 4

[*.{js,jsx,html,xml,sass,json,yml,yaml,toml}]
charset = utf-8
indent_style = space
indent_size = 2
max_line_length = 120

[CHANGELOG.md]
indent_style = tab
indent_size = 4
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text=auto
→za* diff=zsh
_zi* diff=zsh

docs/images/* binary -text
5 changes: 5 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"MD013": false,
"MD033": false,
"MD041": false
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"conventionalCommits.scopes": [
"workspace"
]
}
5 changes: 5 additions & 0 deletions _zi_recache
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
#
# ZI recache subcommand tab completion

typeset -a commands
commands=(recache:'Regenerate eval cache')
_arguments -C \
'1: :->command'\
'*: :->argument' && ret=0

case $state in
command)
_describe -t commands "z-a-eval subcommand" commands && ret=0
Expand Down Expand Up @@ -48,3 +51,5 @@ case $state in
esac
esac
return $ret

# vim: ft=zsh sw=2 ts=2 et
45 changes: 32 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
# ZI Annex `EVAL`

### Author: [NICHOLAS85](https://gihub.com/NICHOLAS85)

### **Wiki:** [z-a-eval](https://github.com/z-shell/zi/wiki/z-a-eval)

## Introduction

> This repository compatible with [ZI](https://github.com/z-shell/zi).
<table style="align:center;width:100%;height:auto"><tr><td align="center">
<h1 align="center">
<a href="https://github.com/z-shell/zi">
<img style="align:center;width:80px;height:auto" src="https://github.com/z-shell/zi/raw/main/docs/images/logo.svg" />
</a>❮ ZI ❯ Annex - Eval
</h1>
<h2>Allows to cache the output of arbitrarily slow initialization command to speed up shell startup time.
</h2>
<img align="center" src="images/recache.png" alt="eval preview" />
</td>
</tr>
</table>

Annex provides a completion file with the prefix _zi, the 'shim' below which will run all available zi completions and the shim is assigned as ZIs completion with a compdef call

Synopsis:

```shell
zi recache <plugin/snippet>
```

An Annex (i.e. an extension) that provides additional functionality, which allows to:
## 💡 Wiki

1. Cache the output of arbitrarily slow initialization command to speed up shell startup time.
- [annexes](https://z.digitalclouds.dev/docs/ecosystem/annexes)

## Installation

Simply load like a regular plugin, i.e.:
Simply load like a regular plugin:

```zsh
```shell
zi light z-shell/z-a-eval
```

Expand All @@ -26,3 +37,11 @@ the annex.
## How it works

The output of a slow initialization command is redirected to a file located within the plugin/snippets directory and sourced while loading. The next time the plugin/snippet is loaded, this file will be sourced skipping the need to run the initialization command.

---

> This repository compatible with [ZI](https://github.com/z-shell/zi).
## Credits

Author: [NICHOLAS85](https://gihub.com/NICHOLAS85)
Binary file added docs/images/recache.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions :za-ev-atclone-handler → functions/→za-ev-atclone-handler
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
#
# Copyright (c) 2021 Nicholas Serrano
# License MIT

Expand Down Expand Up @@ -48,3 +50,5 @@ typeset -i ZI_Z_A_EVAL_SOURCED=1" >! "$cachefile"
}
}
}

# vim: ft=zsh sw=2 ts=2 et
6 changes: 5 additions & 1 deletion :za-ev-atinit-handler → functions/→za-ev-atinit-handler
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
#
# Copyright (c) 2021 Nicholas Serrano
# License MIT

Expand All @@ -24,6 +26,8 @@ if [[ -n ${ICE[eval]} ]] {
(( ${+functions[.zi-store-ices]} )) || builtin source ${ZI[BIN_DIR]}"/lib/zsh/side.zsh"
.zi-store-ices "$dir/._zi" ICE "" "" "" ""
}
:za-ev-atclone-handler "$1" "$2" "$3" "$4" "$5" "$6"
za-ev-atclone-handler "$1" "$2" "$3" "$4" "$5" "$6"
}
}

# vim: ft=zsh sw=2 ts=2 et
19 changes: 11 additions & 8 deletions :za-ev-recache → functions/→za-ev-recache
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
#
# Copyright 2021 Nicholas Serrano
# License: MIT

Expand All @@ -6,22 +8,21 @@
#

emulate -LR zsh
setopt extended_glob warn_create_global typeset_silent \
no_short_loops rc_quotes
setopt extended_glob warn_create_global typeset_silent no_short_loops rc_quotes

(( ${+functions[.zi-compute-ice]} )) || builtin source ${ZINIT[BIN_DIR]}"/lib/zsh/side.zsh"
(( ${+functions[.zi-compute-ice]} )) || builtin source ${ZI[BIN_DIR]}"/lib/zsh/side.zsh"
local -A ICE
local -a plugins snippets
local entry dir filename is_snippet REPLY reply

if [[ -z $2 ]] {
+zi-message '{pre}eval annex: {msg2}Recaching eval output of all plugins and snippets{…}{rst}'
plugins=( "${ZINIT[PLUGINS_DIR]}"/**/evalcache.zsh(N:h:t) )
plugins=( "${ZI[PLUGINS_DIR]}"/**/evalcache.zsh(N:h:t) )
plugins=( "${plugins[@]//---//}" )
plugins=( "${plugins[@]:#_local/zi}" )
plugins=( "${plugins[@]:#custom}" )
snippets=( "${ZINIT[SNIPPETS_DIR]}"/**/evalcache.zsh(N:h) )
snippets=( ${snippets[@]#${ZINIT[SNIPPETS_DIR]}/} )
snippets=( "${ZI[SNIPPETS_DIR]}"/**/evalcache.zsh(N:h) )
snippets=( ${snippets[@]#${ZI[SNIPPETS_DIR]}/} )
snippets=( ${snippets[@]/(#b)(http|https|ftp|ftps|scp)--/${match[1]}://} )
snippets=( ${snippets[@]/--//} )
} else {
Expand All @@ -35,10 +36,12 @@ for entry in $plugins $snippets; do
[[ -e "$dir" ]] || .zi-compute-ice $entry "pack-nf" ICE dir filename is_snippet || return $?
command rm -f "$dir"/evalcache.{zsh,zsh.zwc}
((is_snippet)) && {
:za-ev-atclone-handler snippet "" "$entry" "$dir" ""
za-ev-atclone-handler snippet "" "$entry" "$dir" ""
} || {
:za-ev-atclone-handler plugin "" "" "$entry" "$dir" ""
za-ev-atclone-handler plugin "" "" "$entry" "$dir" ""
}
unset dir
ICE=()
done

# vim: ft=zsh sw=2 ts=2 et
Binary file removed images/recache.png
Binary file not shown.
72 changes: 38 additions & 34 deletions z-a-eval.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,52 +1,54 @@
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
#
# Copyright (c) 2021 Nicholas Serrano
# License MIT

# According to the Zsh Plugin Standard:
# http://zdharma.org/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html

0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
# Standardized $0 Handling
# https://z.digitalclouds.dev/community/zsh_plugin_standard#zero-handling
0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}"
0="${${(M)0:#/*}:-$PWD/$0}"

autoload :za-ev-atclone-handler :za-ev-atinit-handler :za-ev-recache
# Functions Directory
# https://z.digitalclouds.dev/community/zsh_plugin_standard#funtions-directory
if [[ $PMSPEC != *f* ]] {
fpath+=( "${0:h}/functions" )
}

autoload →za-ev-atclone-handler →za-ev-atinit-handler →za-ev-recache

# An empty stub to fill the help handler fields
:za-ev-null-handler() { :; }
za-ev-null-handler() { :; }

# Remove temporary variable
:za-ev-atload-handler() { [[ -n ${ICE[eval]} ]] && unset ZI_Z_A_EVAL_SOURCED; }

@zi-register-annex "z-a-eval" \
hook:atclone-50 \
:za-ev-atclone-handler \
:za-ev-null-handler \
"eval''" # also register new ices

@zi-register-annex "z-a-eval" \
hook:atpull-50 \
:za-ev-atclone-handler \
:za-ev-null-handler

@zi-register-annex "z-a-eval" \
hook:atload-50 \
:za-ev-atload-handler \
:za-ev-null-handler

@zi-register-annex "z-a-eval" \
hook:atinit-50 \
:za-ev-atinit-handler \
:za-ev-null-handler

@zi-register-annex "z-a-eval" \
subcommand:recache \
:za-ev-recache \
:za-ev-null-handler
→za-ev-atload-handler() { [[ -n ${ICE[eval]} ]] && unset ZI_Z_A_EVAL_SOURCED; }

@zi-register-annex "z-a-eval" hook:atclone-50 \
→za-ev-atclone-handler \
→za-ev-null-handler "eval''" # also register new ices

@zi-register-annex "z-a-eval" hook:atpull-50 \
→za-ev-atclone-handler \
→za-ev-null-handler

@zi-register-annex "z-a-eval" hook:atload-50 \
→za-ev-atload-handler \
→za-ev-null-handler

@zi-register-annex "z-a-eval" hook:atinit-50 \
→za-ev-atinit-handler \
→za-ev-null-handler

@zi-register-annex "z-a-eval" subcommand:recache \
→za-ev-recache \
→za-ev-null-handler

(( Z_A_USECOMP )) || return;

# Annex provides a completion file with the prefix _zi
# Annex provies the 'shim' below which will run all available zi completions
# Lastly the shim is assigned as zis completion with a compdef call
# Lastly the shim is assigned as ZIs completion with a compdef call
autoload -Uz _zi_recache

_zi_shim(){
unset -f $funcstack[1]
eval "
Expand All @@ -57,3 +59,5 @@ _zi_shim(){
"
}
compdef _zi_shim zi

# vim: ft=zsh sw=2 ts=2 et

0 comments on commit ba5217e

Please sign in to comment.