fisher/functions/fisher_install.fish
Jorge Bucaran 9a4f0f0650
Fisherman v0.2.0
* Improved README, added links to screencasts, updated
documentation with new changes and fixed other typos and
composition errors.

* Removed `fisher update --cache` in favor of
`fisher --cache | fisher update` and
`fisher uninstall --all` in favor of
`fisher --cache | fisher uninstall`.

* Fisherman does not move initialization / configuration
files following the convention `name`.config.fish to
`$fisher_config/functions`, but to `$fisher_config/conf.d`
now and evaluates  each `*.config.fish` inside at shell
start as usual. Closes #13.

* Added `fisher --cache[=base]` option to retrieve contents
in `$fisher_cache`, eliminating flaky usage of `find(1)`.
Closes #11.

* Fisherman now generates information about plugins installed
via custom URLs. For the description, a shortened version of
the URL is used. For the URL the full URL is used. For tags,
the URL is fuzzily checked and tags such as _theme_, _plugin_,
_config_ and _omf_ are added. The tag _orphan_ is added by
default as well. Finally, the author is generated by
retrieving the e-mail or username of the author of the
first commit in the plugin's repository. Closes #9 and #14.

* Changed `--path-in-cache` to `--translate.` This function
translates an name or supported URL/URL variation into a path
inside `$fisher_cache`. This allows you to treat plugins
installed via custom URLs almost like regular plugins if they
are installed. Closes #8.

* Fixed a bug with `mktemp` failing on some systems.
Closes #7. Thanks @tobywf.

* Added [CODE_OF_CONDUCT][code_of_conduct]. Closes #6.

* Fisherman can now unload themes within the same shell,
without having to restart the session. Closes #5.

* Fisherman can now load themes within the same shell,
without having to restart the session using `exec fish`.
Shoddy themes, for example those failing to declare global
variables with the `-g` flag still require the session to
be reset. See [**related**][bobthefish-19]. Closes #4.

* Move `getopts` implementation to `share/getopts.awk`.
Closes #3.

* Support dots inside URIs in `fisher --validate`.
Closes #2.
2016-01-05 06:05:11 +09:00

170 lines
4.6 KiB
Fish

function fisher_install -d "Enable / Install Plugins"
set -l items
set -l error /dev/stderr
getopts $argv | while read -l 1 2
switch "$1"
case _
set items $items $2
case q quiet
set error /dev/null
case h help
printf "usage: fisher install [<name or url> ...] [--quiet] [--help]\n\n"
printf " -q --quiet Enable quiet mode\n"
printf " -h --help Show usage help\n"
return
case \*
printf "fisher: '%s' is not a valid option\n" $1 >& 2
fisher_install --help >& 2
return 1
end
end
set -l count 0
set -l total (count $items)
set -l elapsed (date +%s)
if set -q items[1]
printf "%s\n" $items
else
fisher --file=-
end | fisher --validate | while read -l item
switch "$item"
case \*/\*
printf "%s %s\n" $item (
if not fisher_search --url=$item --name
printf "%s" $item | sed -E '
s/.*\/(.*)/\1/
s/^(plugin|theme|pkg|omf|fish|fisher)-//'
end)
case \*
if set -l url (fisher_search --name=$item --url)
printf "%s %s\n" $url $item
else if test -d $fisher_cache/$item
printf "%s %s\n" (git -C $fisher_cache/$item ls-remote --get-url) $item
else
printf "fisher: '%s' not found\n" $item > $error
end
end
end | while read -l url name
printf "Installing " > $error
switch $total
case 0 1
printf ">> %s\n" $name > $error
case \*
printf "(%s of %s) >> %s\n" (math 1 + $count) $total $name > $error
end
mkdir -p $fisher_config/{cache,functions,completions,conf.d,man}
set -l path $fisher_cache/$name
if not test -e $path
if not wait --spin=pipe --log=$fisher_error_log "
git clone --quiet --depth 1 $url $path"
printf "fisher: Repository not found: '%s'\n" $url > $error
continue
end
end
set -l bundle $path/fishfile
if test -e $path/bundle
set bundle $path/bundle
end
if test -e $bundle
printf "Resolving dependencies in %s\n" $name/(basename $bundle) > $error
set -l deps (fisher --file=$bundle \
| fisher_install ^&1 \
| sed -En 's/([0-9]+) plugin\/s.*/\1/p')
set count (math $count + 0$deps)
end
if test -s $path/Makefile -o -s $path/makefile
pushd $path
if not make > /dev/null ^ $error
popd
printf "fisher: Can't make '%s'\n" $name > $error
continue
end
popd
end
if test -e $path/fish_prompt.fish -o -e $path/fish_right_prompt.fish
rm -f $fisher_config/functions/{fish_prompt,fish_right_prompt}.fish
functions -e fish_{,right_}prompt
end
for file in $path/{*,functions{/*,/**/*}}.fish
set -l base (basename $file)
switch $base
case {$name,fish_{,right_}prompt}.fish
source $file
case {init,uninstall}.fish
set base $name.(basename $base .fish).config.fish
end
switch $base
case \*\?.config.fish
cp -f $file $fisher_config/conf.d/$base
case \*
cp -f $file $fisher_config/functions/$base
end
end
cp -f $path/completions/*.fish $fisher_config/completions/ ^ /dev/null
for n in (seq 9)
if test -d $path/man/man$n
mkdir -p $fisher_config/man/man$n
end
cp -f $path/man/man$n/*.$n $fisher_config/man/man$n/ ^ /dev/null
end
set count (math $count + 1)
set -l file $fisher_config/fishfile
if test -s $file
if fisher --file=$file | grep -Eq "^$name\$|^$url\$"
continue
end
end
touch $file
if not fisher_search --name=$name --field=name --quiet
set name $url
end
printf "%s\n" "$name" >> $file
end
printf "%d plugin/s installed (%0.fs)\n" (math $count) (
math (date +%s) - $elapsed) > $error
if not test $count -gt 0
return 1
end
end