Skip to content

Commit

Permalink
Add install arguments to not set up {,f}path
Browse files Browse the repository at this point in the history
Fixes marlonrichert#205

Test:

```russell@zip:~ ❯ cat test.zsh
t() {
    path=(/usr/bin /bin)
    fpath=()
    echo --
    echo znap install "$@"
    znap install "$@"
    echo path = $#path , fpath = $#fpath
}

t asdf-vm/asdf --no-path --no-fpath
t --no-path --no-fpath asdf-vm/asdf
t --no-path asdf-vm/asdf
t asdf-vm/asdf --no-path
t --no-fpath asdf-vm/asdf
t asdf-vm/asdf --no-fpath
t asdf-vm/asdf
t asdf-vm/asdf --no-such-arg
russell@zip:~ ❯ source test.zsh
--
znap install asdf-vm/asdf --no-path --no-fpath
path = 2 , fpath = 0
--
znap install --no-path --no-fpath asdf-vm/asdf
path = 2 , fpath = 0
--
znap install --no-path asdf-vm/asdf
path = 2 , fpath = 1
--
znap install asdf-vm/asdf --no-path
path = 2 , fpath = 1
--
znap install --no-fpath asdf-vm/asdf
path = 3 , fpath = 0
--
znap install asdf-vm/asdf --no-fpath
path = 3 , fpath = 0
--
znap install asdf-vm/asdf
path = 3 , fpath = 1
--
znap install asdf-vm/asdf --no-such-arg
znap clone: invalid argument '--no-such-arg'
Usage: znap clone ( <user>/<repo> | <url> ) ...
Download repos in parallel.
path = 2 , fpath = 0
```
  • Loading branch information
rcloran committed Oct 10, 2023
1 parent 679a389 commit a02ec98
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions completions/_znap
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ case $words[1] in
( clone )
_arguments : '*:remote repository:_urls'
;;
( compdef )
_arguments : ':function name:' ': :_default'
;;
( compile )
_arguments : ': :_default'
;;
Expand All @@ -42,7 +39,10 @@ case $words[1] in
_arguments : ': :->repos' ':pattern:'
;;
( install )
_arguments : '*:remote repository:_urls'
_arguments : \
"--no-fpath[don't update fpath with completions or functions]" \
"--no-path[don't update PATH with binaries]" \
'*:remote repository:_urls'
;;
( multi )
_arguments : ': :_default'
Expand Down
26 changes: 16 additions & 10 deletions functions/.znap.install
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/zsh
# install executables & completion functions
# args: <repo> ...
# args: <repo> [--no-path] [--no-fpath] ...
emulate -L zsh; setopt $_znap_opts
zmodload -Fa zsh/files b:zf_ln b:zf_mkdir

Expand All @@ -10,12 +10,14 @@ if (( $# < 1 )); then
return $(( sysexits[(i)USAGE] + 63 ))
fi

local -A opts
zparseopts -A opts -E -D -- -no-path -no-fpath

.znap.clone $@ ||
return

local REPLY=
private -aU funcfiles=()
private bindir=~/.local/bin
private d='' link='' pat='[[:alnum:]][[:alnum:]_-]#[[:alnum:]]'

local -a repos=()
Expand All @@ -26,14 +28,18 @@ private repo=
for repo in $repos; do
repo=~[$repo]

path=(
$repo/{,bin/}$~pat(N*:h)
$path[@]
)
fpath=(
$repo/{,{[Cc]ompletions,[Ss]rc,zsh}/($~pat/)#}_$~pat(N^/:h)
$fpath
)
if ! (( $+opts[--no-path] )) ; then
path=(
$repo/{,bin/}$~pat(N*:h)
$path[@]
)
fi
if ! (( $+opts[--no-fpath] )) ; then
fpath=(
$repo/{,{[Cc]ompletions,[Ss]rc,zsh}/($~pat/)#}_$~pat(N^/:h)
$fpath
)
fi

funcfiles=( $repo/{,[Ff]unctions}/($~pat/)#}$~pat(N^/) )
(( $#funcfiles )) &&
Expand Down

0 comments on commit a02ec98

Please sign in to comment.