fisher/functions/fisher_update.fish
Jorge Bucaran 4b15cf374f
Ahoy! We are getting close to 0.8.0
* Move AUTHORS -> THANKS and remove automatic generation.

THANKS is more sensible than AUTHORS. CREDITS was second best.
Also, after perusing similar files in other projects I noticed
some entries lacking a valid email address and decided fow now
this file should be curated manually to make sure each entry
contains a useful link. This allows users who have contributed
to the project ways other than committing code to be added to
the list as well.

* Rename wait -> spin.

* Remove extra padding in links. (Cosmetic)

* Update to reflect API refactorings.

* Fix bug causing brackets to show up in description.

* Implement using spin function.

* __fisher_gist_to_name uses curl to query the GitHub API which will
return a JSON stream even if the Gist could not be found. So, it's
not possible to determine whether we failed or not using our spin
function and actually need to check the returned string to see if
it contains a valid name or not.

* Let git pull write errors to stderr.

* Use new internal __fisher_spin.

* Extract spin to independent / external module and tweak Makefile
to better integrate with new install process.
2016-02-14 13:17:47 +09:00

114 lines
3.3 KiB
Fish

function fisher_update -d "Update Plugins/Fisherman"
set -l plugins
set -l option self
set -l stdout /dev/stdout
set -l stderr /dev/stderr
getopts $argv | while read -l 1 2
switch "$1"
case _
set option
if test "$2" != -
set plugins $plugins $2
end
case q quiet
set stdout /dev/null
set stderr /dev/null
case h
printf "usage: fisher update [<plugins>] [--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 > /dev/stderr
fisher_update -h > /dev/stderr
return 1
end
end
switch "$option"
case self
set -l time (date +%s)
printf "Updating >> Fisherman\n" > $stderr
if not spin "
__fisher_index_update 0
__fisher_path_update $fisher_home" --error=$stderr
###
###
printf "fisher: Arrr! Could not update Fisherman.\n" > $stderr
return 1
end
printf "Aye! Fisherman updated to version %s (%0.fs)\n" (
cat $fisher_home/VERSION) (math (date +%s) - $time) > $stderr
case \*
set -l time (date +%s)
set -l count 0
set -l index 1
set -l total (count $plugins)
set -l skipped
if set -q plugins[1]
printf "%s\n" $plugins
else
__fisher_file
end | while read -l item path
if not set item (__fisher_plugin_validate $item)
printf "fisher: '%s' is not a valid name, path or url.\n" $item > $stderr
continue
end
if not set path (__fisher_path_from_plugin $item)
set total (math $total - 1)
printf "fisher: '%s' not found.\n" $item > $stderr
continue
end
set -l name (printf "%s\n" $path | __fisher_name)
printf "Updating " > $stderr
switch $total
case 0 1
printf ">> %s\n" $name > $stderr
case \*
printf "(%s of %s) >> %s\n" $index $total $name > $stderr
set index (math $index + 1)
end
if test ! -L $path
if not spin "__fisher_path_update $path" --error=$stderr
continue
end
end
if __fisher_plugin_can_enable "$name" "$path"
fisher_install --quiet --force -- $name
end
set count (math $count + 1)
end
set time (math (date +%s) - $time)
if test $count -le 0
printf "No plugins were updated.\n" > $stdout
return 1
end
printf "Aye! %d plugin/s updated in %0.fs\n" $count $time > $stdout
end
end