diff --git a/.editorconfig b/.editorconfig index 1e1705f..81edcba 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,63 @@ +# 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 diff --git a/.gitignore b/.gitignore index 3cc5d4e..7f6b961 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ ._zi .zi_lastupd -# zdharma/zshelldoc tool's files +# zdharma/zsdoc tool's files zsdoc/data # robbyrussell/oh-my-zsh/plugins/per-directory-history plugin's files diff --git a/.markdownlint.yaml b/.markdownlint.yaml new file mode 100644 index 0000000..465a928 --- /dev/null +++ b/.markdownlint.yaml @@ -0,0 +1,11 @@ +# Autoformatter friendly markdownlint config (all formatting rules disabled) +default: true +blank_lines: false +bullet: false +html: false +indentation: false +line_length: false +spaces: false +url: false +whitespace: false +MD041: false diff --git a/.trunk/.gitignore b/.trunk/.gitignore new file mode 100644 index 0000000..7feb17f --- /dev/null +++ b/.trunk/.gitignore @@ -0,0 +1 @@ +*out diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml new file mode 100644 index 0000000..396ef18 --- /dev/null +++ b/.trunk/trunk.yaml @@ -0,0 +1,8 @@ +version: 0.1 +cli: + version: 0.9.3-beta +lint: + enabled: + - gitleaks@8.3.0 + - markdownlint@0.31.1 + - prettier@2.5.1 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d0b9b2d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "conventionalCommits.scopes": ["workspace"] +} diff --git a/:za-lb-atclone-handler b/:za-lb-atclone-handler deleted file mode 100644 index 2848c27..0000000 --- a/:za-lb-atclone-handler +++ /dev/null @@ -1,117 +0,0 @@ -# Original work Copyright (c) 2019-2020 Sebastian Gniazdowski -# Modified work Copyright (c) 2020-2021 Nicholas Serrano -# License MIT - -emulate -RL zsh -setopt extendedglob warncreateglobal typesetsilent noshortloops nullglob - -if [[ "$1" = plugin ]] { - local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6" -} else { - local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5" -} - -# -# lbin'' ice – creation of links -# - -if (( ${+ICE[lbin]} )) { - (( ${+ICE[sbin]} )) && { - (( !OPTS[opt_-q,--quiet] )) && \ - +zi-message "{pre}linkbin annex: {ice}sbin{warn} ice detected, not doing anything...{rst}" - return; - } - local -a lbins srcdst - lbins=( ${(s.;.)ICE[lbin]} ) - - local lbin sym="-P" - - ( - # CD for the globbing through eval - builtin cd -q "$dir" || return - - for lbin ( $lbins "" ) { - [[ ${lbin[1]} = "!" ]] && sym="-s" - - if [[ -z $lbin && ${#lbins} -eq 0 ]] || [[ $lbin = "!" && ${#lbins} -eq 1 ]] { - local -a files - integer i=0 - while [[ ! -f $files[1] && $i -lt 9 ]]; do - ((i++)) - case $i in - 1) - files=( $dir/${id_as:t}(Nnon.) ) - ;; - 2) - [[ -n $plugin ]] && files=( $dir/$plugin(Nnon.) ) - ;; - 3) - [[ -n $url ]] && files=( $dir/${url:t}(Nnon.) ) - ;; - 4) - files=( $dir/*(*Nnon.:t) ) - ;; - 5) - files=( $dir/**/${id_as:t} ) - ;; - 6) - [[ -n $plugin ]] && files=( $dir/**/$plugin(Nnon.) ) - ;; - 7) - [[ -n $url ]] && files=( $dir/**/${url:t}(Nnon.) ) - ;; - 8) - files=( $dir/**/*(*Nnon.:t) ) - ;; - 9) - +zi-message "{pre}linkbin annex: {error}The automatic-empty {ice}lbin{error} ice didn't find any executable files{rst}" - ;; - esac - done - [[ $i -gt 8 ]] && break - lbin=$files[1] - } else { - lbin=${lbin#!} - [[ -z $lbin ]] && continue - } - srcdst=( ${(@s.->.)lbin} ) - srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) - - # Substitute the standard keywords and param''-s - @zi-substitute 'srcdst[1]' 'srcdst[2]' - - local -a fnames - local fname - eval "fnames=( ${srcdst[1]}(Nnon.) )" - - if (( !${#fnames} )) { - +zi-message "{pre}linkbin annex: {error}The {ice}lbin{error} ice (\`{glob}$lbin{error}')didn't match any files{rst}" - continue - } - - for fname ( $fnames ) { - srcdst[1]="$fname" - - local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \ - fnam="${srcdst[2]:-${srcdst[1]:t}}" - local file="$ZPFX/bin/$fnam" - - command chmod +x "$target_binary" - command ln -f "$sym" "$target_binary" "$file" - - if [[ -x $file ]]; then - (( !OPTS[opt_-q,--quiet] )) && \ - if [[ -x $target_binary ]]; then - if [[ $hook == atclone-<-> || $ZI[annex-multi-flag:pull-active] -ge 2 ]] { - +zi-message "{pre}linkbin annex: {msg}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{msg} link and set +x on the {obj}${target_binary:t}{msg} binary{rst}" - } - else - +zi-message "{pre}linkbin annex: {error}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{error} link however the {obj}${target_binary:t}{error} binary does not exist or failed to set +x on it{rst}" - fi - else - +zi-message "{pre}linkbin annex: {error}Something went wrong creating the {obj}$fnam{error} link{rst}" - fi - } - } - ) -} \ No newline at end of file diff --git a/:za-lb-atdelete-handler b/:za-lb-atdelete-handler deleted file mode 100644 index c4a095a..0000000 --- a/:za-lb-atdelete-handler +++ /dev/null @@ -1,112 +0,0 @@ -# Original work Copyright (c) 2019-2020 Sebastian Gniazdowski -# Modified work Copyright (c) 2020-2021 Nicholas Serrano -# License MIT - -emulate -RL zsh -setopt extendedglob warncreateglobal typesetsilent noshortloops nullglob - -if [[ "$1" = plugin ]] { - local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6" -} else { - local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5" -} - -# -# lbin'' ice – creation of links -# - -if (( ${+ICE[lbin]} )) { - (( ${+ICE[sbin]} )) && { - (( !OPTS[opt_-q,--quiet] )) && \ - +zi-message "{pre}linkbin annex: {ice}sbin{warn} ice detected, not doing anything...{rst}" - return; - } - local -a lbins srcdst - lbins=( ${(s.;.)ICE2[lbin]} ) - - local lbin sym="-P" - - ( - # CD for the globbing through eval - builtin cd -q "$dir" || return - - for lbin ( $lbins "" ) { - [[ ${lbin[1]} = "!" ]] && sym="-s" - - if [[ -z $lbin && ${#lbins} -eq 0 ]] || [[ $lbin = "!" && ${#lbins} -eq 1 ]] { - local -a files - integer i=0 - while [[ ! -f $files[1] && $i -lt 9 ]]; do - ((i++)) - case $i in - 1) - files=( $dir/${id_as:t}(Nnon.) ) - ;; - 2) - [[ -n $plugin ]] && files=( $dir/$plugin(Nnon.) ) - ;; - 3) - [[ -n $url ]] && files=( $dir/${url:t}(Nnon.) ) - ;; - 4) - files=( $dir/*(*Nnon.:t) ) - ;; - 5) - files=( $dir/**/${id_as:t} ) - ;; - 6) - [[ -n $plugin ]] && files=( $dir/**/$plugin(Nnon.) ) - ;; - 7) - [[ -n $url ]] && files=( $dir/**/${url:t}(Nnon.) ) - ;; - 8) - files=( $dir/**/*(*Nnon.:t) ) - ;; - 9) - +zi-message "{pre}linkbin annex: {error}The automatic-empty {ice}lbin{error} ice didn't find any executable files{rst}" - ;; - esac - done - [[ $i -gt 8 ]] && break - lbin=$files[1] - } else { - lbin=${lbin#!} - [[ -z $lbin ]] && continue - } - srcdst=( ${(@s.->.)lbin} ) - srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) - - # Substitute the standard keywords and param''-s - @zi-substitute 'srcdst[1]' 'srcdst[2]' - - local -a fnames - local fname - eval "fnames=( ${srcdst[1]}(Nnon.) )" - - if (( !${#fnames} )) { - +zi-message "{pre}linkbin annex: {error}The {ice}lbin{error} ice (\`{glob}$lbin{error}')didn't match any files{rst}" - continue - } - - for fname ( $fnames ) { - srcdst[1]="$fname" - - local fnam="${srcdst[2]:-${srcdst[1]:t}}" - local file="$ZPFX/bin/$fnam" - - if [[ -f $file ]] { - command rm "$file" - if ! [[ -f $file ]]; then - (( !OPTS[opt_-q,--quiet] )) && \ - +zi-message "{pre}linkbin annex: {msg}Removed {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{msg} link{rst}" - else - +zi-message "{pre}linkbin annex: {error}Something went wrong deleting the {obj}$fnam{error} link{rst}" - fi - } else { - +zi-message "{pre}linkbin annex: {error}The {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{error} link didn't exist in \$ZPFX/bin (or isn't a regular file){rst}" - } - } - } - ) -} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index af02b1c..9f4c602 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,24 +1,82 @@ + + + +
+

+ + + ❮ ZI ❯ Annex - Eval +

+

Run programs and scripts without adding anything to $PATH via the automated links to $ZPFX/bin +

+ eval preview +
-# ZI Annex `LINKBIN` +## Install -### Author: [NICHOLAS85](https://github.com/NICHOLAS85) +```shell +zi light z-shell/z-a-linkbin +``` -### **Wiki:** [z-a-linkbin](https://github.com/z-shell/zi/wiki/z-a-linkbin) +## 💡 Wiki +- [annexes](https://z.digitalclouds.dev/docs/ecosystem/annexes) -## Introduction +## How it works -A Zsh ZI annex (i.e. an extension) that provides functionality, which allows to: +Exposing a binary program without modifying `$PATH` – `z-a-linkbin` will automatically create a hard or soft link to the binary in `$ZPFX/bin` exposing the program to the command line as if it were being placed in `$PATH`. -1. Run programs and scripts without adding anything to `$PATH` via the automatic creation of **links** in `$ZPFX/bin` +The command can then be accessed normally – not only in the live Zsh session, but also from any Zsh script. -## Install linkbin +The ice-modifier `lbin''` provided by the annex creates `links` for binaries and scripts. -Simply load like a regular plugin, i.e.: +It creates the `link` that calls the actual binary. The link is created always under the same, standard and single `$PATH` entry: `$ZPFX/bin` -```zsh -zi light z-shell/z-a-linkbin +> The optional preceding `!` flag means create a soft link instead of a hard link. + +Example: + +```shell +zi ice from'gh-r' lbin'!fzf' +zi load junegunn/fzf ``` -After executing this command you can then use the new ice-mods provided by -the annex. +Check the output: + +```shell +ls -l $ZPFX/bin/ | awk '{print $(NF-2),$(NF-1),$NF}' +fzf --version +``` + +**The ice can contain globs**. It will expand these when searching for the binary. + +Example: + +```shell +zi ice from'gh-r' lbin'**fzf -> myfzf' +zi load junegunn/fzf +``` + +Check the output: + +```shell +ls $ZPFX/bin +myfzf --version +``` + +**The ice can be empty**. It will then try to create the link: + +- trailing component of the `id_as` ice, e.g.: `id_as'exts/git-my'` → it will check if a file `git-my` exists and if yes, create the link `git-my`, +- the plugin name, e.g.: for `paulirish/git-open` it'll check if a file `git-open` exists and if yes, create the link `git-open`, +- trailing component of the snippet URL, +- for any alphabetically first executable file. + +Above also applies if just `!` were passed. + +--- + +> This repository compatible with [ZI](https://github.com/z-shell/zi). + +## Credits + +Author: [NICHOLAS85](https://github.com/NICHOLAS85) diff --git a/docs/img/linkbin.png b/docs/img/linkbin.png new file mode 100644 index 0000000..65f8576 Binary files /dev/null and b/docs/img/linkbin.png differ diff --git "a/functions/\342\206\222za-lb-atclone-handler" "b/functions/\342\206\222za-lb-atclone-handler" new file mode 100644 index 0000000..9d6afd2 --- /dev/null +++ "b/functions/\342\206\222za-lb-atclone-handler" @@ -0,0 +1,125 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# +# Original work Copyright (c) 2019-2020 Sebastian Gniazdowski +# Modified work Copyright (c) 2020-2021 Nicholas Serrano +# Copyright (c) 2022 Salvydas Lukosius +# License MIT + +# Standard Recommended Options +# https://z.digitalclouds.dev/community/zsh_plugin_standard#standard-recommended-options +emulate -L zsh +setopt extended_glob warn_create_global typeset_silent \ + no_short_loops rc_quotes no_auto_pushd + +if [[ "$1" = plugin ]]; then + local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6" +else + local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5" +fi + +# +# lbin'' ice – creation of links +# + +if (( ${+ICE[lbin]} )); then + (( ${+ICE[sbin]} )) && { + (( !OPTS[opt_-q,--quiet] )) && \ + +zi-message "{pre}linkbin annex: {ice}sbin{warn} ice detected, not doing anything...{rst}" + return; + } + local -a lbins srcdst + lbins=( ${(s.;.)ICE[lbin]} ) + + local lbin sym="-P" + + ( + # CD for the globbing through eval + builtin cd -q "$dir" || return + + for lbin ( $lbins "" ) { + [[ ${lbin[1]} = "!" ]] && sym="-s" + + if [[ -z $lbin && ${#lbins} -eq 0 ]] || [[ $lbin = "!" && ${#lbins} -eq 1 ]] { + local -a files + integer i=0 + while [[ ! -f $files[1] && $i -lt 9 ]]; do + ((i++)) + case $i in + 1) + files=( $dir/${id_as:t}(Nnon.) ) + ;; + 2) + [[ -n $plugin ]] && files=( $dir/$plugin(Nnon.) ) + ;; + 3) + [[ -n $url ]] && files=( $dir/${url:t}(Nnon.) ) + ;; + 4) + files=( $dir/*(*Nnon.:t) ) + ;; + 5) + files=( $dir/**/${id_as:t} ) + ;; + 6) + [[ -n $plugin ]] && files=( $dir/**/$plugin(Nnon.) ) + ;; + 7) + [[ -n $url ]] && files=( $dir/**/${url:t}(Nnon.) ) + ;; + 8) + files=( $dir/**/*(*Nnon.:t) ) + ;; + 9) + +zi-message "{pre}linkbin annex: {error}The automatic-empty {ice}lbin{error} ice didn't find any executable files{rst}" + ;; + esac + done + [[ $i -gt 8 ]] && break + lbin=$files[1] + } else { + lbin=${lbin#!} + [[ -z $lbin ]] && continue + } + srcdst=( ${(@s.->.)lbin} ) + srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + + # Substitute the standard keywords and param''-s + @zi-substitute 'srcdst[1]' 'srcdst[2]' + + local -a fnames + local fname + eval "fnames=( ${srcdst[1]}(Nnon.) )" + + if (( !${#fnames} )) { + +zi-message "{pre}linkbin annex: {error}The {ice}lbin{error} ice (\`{glob}$lbin{error}')didn't match any files{rst}" + continue + } + + for fname ( $fnames ) { + srcdst[1]="$fname" + + local target_binary="${${(M)srcdst[1]:#/*}:-$dir/${srcdst[1]}}" \ + fnam="${srcdst[2]:-${srcdst[1]:t}}" + local file="$ZPFX/bin/$fnam" + + command chmod +x "$target_binary" + command ln -f "$sym" "$target_binary" "$file" + + if [[ -x $file ]]; then + (( !OPTS[opt_-q,--quiet] )) && \ + if [[ -x $target_binary ]]; then + if [[ $hook == atclone-<-> || $ZI[annex-multi-flag:pull-active] -ge 2 ]] { + +zi-message "{pre}linkbin annex: {msg}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{msg} link and set +x on the {obj}${target_binary:t}{msg} binary{rst}" + } + else + +zi-message "{pre}linkbin annex: {error}${${${hook:#*atclone-<->}:+Re-c}:-C}reated the {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{error} link however the {obj}${target_binary:t}{error} binary does not exist or failed to set +x on it{rst}" + fi + else + +zi-message "{pre}linkbin annex: {error}Something went wrong creating the {obj}$fnam{error} link{rst}" + fi + } + } + ) +fi + +# vim: ft=zsh sw=2 ts=2 et diff --git "a/functions/\342\206\222za-lb-atdelete-handler" "b/functions/\342\206\222za-lb-atdelete-handler" new file mode 100644 index 0000000..921ce3c --- /dev/null +++ "b/functions/\342\206\222za-lb-atdelete-handler" @@ -0,0 +1,119 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# +# Original work Copyright (c) 2019-2020 Sebastian Gniazdowski +# Modified work Copyright (c) 2020-2021 Nicholas Serrano +# Copyright (c) 2022 Salvydas Lukosius +# License MIT + +# https://z.digitalclouds.dev/community/zsh_plugin_standard#standard-recommended-options +emulate -L zsh +setopt extended_glob warn_create_global typeset_silent \ + no_short_loops rc_quotes no_auto_pushd + +if [[ "$1" = plugin ]]; then + local type="$1" user="$2" plugin="$3" id_as="$4" dir="${5#%}" hook="$6" +else + local type="$1" url="$2" id_as="$3" dir="${4#%}" hook="$5" +fi + +# +# lbin'' ice – creation of links +# + +if (( ${+ICE[lbin]} )); then + (( ${+ICE[sbin]} )) && { + (( !OPTS[opt_-q,--quiet] )) && \ + +zi-message "{pre}linkbin annex: {ice}sbin{warn} ice detected, not doing anything...{rst}" + return; + } + local -a lbins srcdst + lbins=( ${(s.;.)ICE2[lbin]} ) + + local lbin sym="-P" + + ( + # CD for the globbing through eval + builtin cd -q "$dir" || return + + for lbin ( $lbins "" ) { + [[ ${lbin[1]} = "!" ]] && sym="-s" + + if [[ -z $lbin && ${#lbins} -eq 0 ]] || [[ $lbin = "!" && ${#lbins} -eq 1 ]]; then + local -a files + integer i=0 + while [[ ! -f $files[1] && $i -lt 9 ]]; do + ((i++)) + case $i in + 1) + files=( $dir/${id_as:t}(Nnon.) ) + ;; + 2) + [[ -n $plugin ]] && files=( $dir/$plugin(Nnon.) ) + ;; + 3) + [[ -n $url ]] && files=( $dir/${url:t}(Nnon.) ) + ;; + 4) + files=( $dir/*(*Nnon.:t) ) + ;; + 5) + files=( $dir/**/${id_as:t} ) + ;; + 6) + [[ -n $plugin ]] && files=( $dir/**/$plugin(Nnon.) ) + ;; + 7) + [[ -n $url ]] && files=( $dir/**/${url:t}(Nnon.) ) + ;; + 8) + files=( $dir/**/*(*Nnon.:t) ) + ;; + 9) + +zi-message "{pre}linkbin annex: {error}The automatic-empty {ice}lbin{error} ice didn't find any executable files{rst}" + ;; + esac + done + [[ $i -gt 8 ]] && break + lbin=$files[1] + else + lbin=${lbin#!} + [[ -z $lbin ]] && continue + fi + srcdst=( ${(@s.->.)lbin} ) + srcdst=( "${srcdst[@]//((#s)[[:space:]]##|[[:space:]]##(#e))/}" ) + + # Substitute the standard keywords and param''-s + @zi-substitute 'srcdst[1]' 'srcdst[2]' + + local -a fnames + local fname + eval "fnames=( ${srcdst[1]}(Nnon.) )" + + if (( !${#fnames} )) { + +zi-message "{pre}linkbin annex: {error}The {ice}lbin{error} ice (\`{glob}$lbin{error}')didn't match any files{rst}" + continue + } + + for fname ( $fnames ) { + srcdst[1]="$fname" + + local fnam="${srcdst[2]:-${srcdst[1]:t}}" + local file="$ZPFX/bin/$fnam" + + if [[ -f $file ]] { + command rm "$file" + if ! [[ -f $file ]]; then + (( !OPTS[opt_-q,--quiet] )) && \ + +zi-message "{pre}linkbin annex: {msg}Removed {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{msg} link{rst}" + else + +zi-message "{pre}linkbin annex: {error}Something went wrong deleting the {obj}$fnam{error} link{rst}" + fi + } else { + +zi-message "{pre}linkbin annex: {error}The {obj}$fnam{data2} ${${${sym#-P}:+soft}:-hard}{error} link didn't exist in \$ZPFX/bin (or isn't a regular file){rst}" + } + } + } + ) +fi + +# vim: ft=zsh sw=2 ts=2 et diff --git a/z-a-linkbin.plugin.zsh b/z-a-linkbin.plugin.zsh index 1b8c4db..59c492f 100644 --- a/z-a-linkbin.plugin.zsh +++ b/z-a-linkbin.plugin.zsh @@ -1,37 +1,43 @@ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# # Original work Copyright (c) 2019-2020 Sebastian Gniazdowski # Modified work Copyright (c) 2020 Nicholas Serrano +# Copyright (c) 2022 Salvydas Lukosius # 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-lb-atclone-handler :za-lb-atdelete-handler +# Functions directory +# https://z.digitalclouds.dev/community/zsh_plugin_standard#funtions-directory +if [[ $PMSPEC != *f* ]] { + fpath+=( "${0:h}/functions" ) +} + +# https://z.digitalclouds.dev/community/zsh_plugin_standard#the-proposed-function-name-prefixes +autoload →za-lb-atclone-handler →za-lb-atdelete-handler # An empty stub to fill the help handler fields -:za-lb-null-handler() { :; } +→za-lb-null-handler() { :; } #@zi-register-annex "z-a-linkbin" \ # subcommand:link-list \ -# :za-lb-list \ -# :za-lb-help-handler - +# →za-lb-list \ +# →za-lb-help-handler -@zi-register-annex "z-a-linkbin" \ - hook:atclone-50 \ - :za-lb-atclone-handler \ - :za-lb-null-handler \ - "lbin|lbin''" # also register new ices +@zi-register-annex "z-a-linkbin" hook:atclone-50 \ + →za-lb-atclone-handler \ + →za-lb-null-handler \ + "lbin|lbin''" # also register new ices -@zi-register-annex "z-a-linkbin" \ - hook:\%atpull-50 \ - :za-lb-atclone-handler \ - :za-lb-null-handler +@zi-register-annex "z-a-linkbin" hook:\%atpull-50 \ + →za-lb-atclone-handler \ + →za-lb-null-handler -@zi-register-annex "z-a-linkbin" \ - hook:atdelete-50 \ - :za-lb-atdelete-handler \ - :za-lb-null-handler +@zi-register-annex "z-a-linkbin" hook:atdelete-50 \ + →za-lb-atdelete-handler \ + →za-lb-null-handler +# vim: ft=zsh sw=2 ts=2 et