fix: create fishfile automatically; close #451

- create fishfile if one doesn't already exist
- only read from stdin when using `add` or `rm` commands
- show help if unknown command is entered
- show error message when fishfile is empty and no packages
  were added, removed or updated
This commit is contained in:
Jorge Bucaran 2018-10-06 02:20:08 +09:00
parent 318a1941dc
commit 444a8fee8c
No known key found for this signature in database
GPG key ID: E54BA3C0E646DB30

View file

@ -48,16 +48,19 @@ function fisher -a cmd -d "fish package manager"
_fisher_self_complete _fisher_self_complete
case self-uninstall case self-uninstall
_fisher_self_uninstall _fisher_self_uninstall
case "" add rm case add rm ""
if not isatty if test ! -z "$argv"
while read -l i if not isatty
set argv $argv $i while read -l i
set argv $argv $i
end
end end
end end
_fisher_commit $argv; or return _fisher_commit $argv; or return
_fisher_self_complete _fisher_self_complete
case \* case \*
echo "unknown flag or command \"$cmd\" -- try fisher help" >&2 echo "error: unknown flag or command \"$cmd\"" >&2
_fisher_help >&2
return 1 return 1
end end
end end
@ -91,7 +94,7 @@ function _fisher_help
echo " fisher rm <PACKAGES> remove packages" echo " fisher rm <PACKAGES> remove packages"
echo " fisher ls list installed packages" echo " fisher ls list installed packages"
echo " fisher self-update update fisher" echo " fisher self-update update fisher"
echo " fisher self-uninstall uninstall fisher and all packages" echo " fisher self-uninstall uninstall fisher & all packages"
echo " fisher help show this help" echo " fisher help show this help"
echo " fisher version show version" echo " fisher version show version"
echo echo
@ -141,28 +144,21 @@ end
function _fisher_commit function _fisher_commit
set -l elapsed (_fisher_now) set -l elapsed (_fisher_now)
set -l fishfile $fish_config/fishfile set -l removed_pkgs (_fisher_pkg_remove_all $fisher_config/*/*/*)
set -l added_pkgs
set -l updated_pkgs
set -l removed_pkgs
if test -z "$cmd" -a ! -e "$fishfile"
echo "fishfile not found -- need help? try fisher help" | command sed "s|$HOME|~|" >&2
return 1
end
command touch $fishfile
_fisher_fishfile_indent (echo -s $argv\;) < $fishfile > $fishfile@
command mv -f $fishfile@ $fishfile
command rm -f $fishfile@
set removed_pkgs (_fisher_pkg_remove_all $fisher_config/*/*/*)
command rm -rf $fisher_config command rm -rf $fisher_config
command mkdir -p $fisher_config command mkdir -p $fisher_config
set added_pkgs (_fisher_pkg_fetch_all (_fisher_fishfile_load < $fishfile)) set -l fishfile $fish_config/fishfile
set updated_pkgs ( if test ! -e "$fishfile"
command touch $fishfile
echo "created empty fishfile in $fishfile" | command sed "s|$HOME|~|" >&2
end
_fisher_fishfile_indent (echo -s $argv\;) < $fishfile > $fishfile@
command mv -f $fishfile@ $fishfile
command rm -f $fishfile@
set -l added_pkgs (_fisher_pkg_fetch_all (_fisher_fishfile_load < $fishfile))
set -l updated_pkgs (
for pkg in $removed_pkgs for pkg in $removed_pkgs
set pkg (echo $pkg | command sed "s|$fisher_config/||") set pkg (echo $pkg | command sed "s|$fisher_config/||")
if contains -- $pkg $added_pkgs if contains -- $pkg $added_pkgs
@ -170,9 +166,12 @@ function _fisher_commit
end end
end) end)
if test ! -z "$added_pkgs$updated_pkgs$removed_pkgs" if test -z "$added_pkgs$updated_pkgs$removed_pkgs" -a ! -s "$fishfile"
echo (count $added_pkgs) (count $updated_pkgs) (count $removed_pkgs) (_fisher_now $elapsed) | _fisher_status_report >&2 echo "nothing to commit -- try adding some packages" >&2
return 1
end end
echo (count $added_pkgs) (count $updated_pkgs) (count $removed_pkgs) (_fisher_now $elapsed) | _fisher_status_report >&2
end end
function _fisher_pkg_remove_all function _fisher_pkg_remove_all