diff --git a/fisher.fish b/fisher.fish index 472948a..6bea76b 100644 --- a/fisher.fish +++ b/fisher.fish @@ -189,7 +189,7 @@ function _fisher_commit command touch $fishfile echo "created empty fishfile in $fishfile" | command sed "s|$HOME|~|" >&2 end - printf "%s\n" (_fisher_fishfile_format (echo -s $argv\;) < $fishfile) > $fishfile + printf "%s\n" (_fisher_fishfile_format (echo -s $argv\;) (echo -s $removed_pkgs\;) < $fishfile) > $fishfile set -l expected_pkgs (_fisher_fishfile_read < $fishfile) set -l added_pkgs (_fisher_pkg_fetch_all $expected_pkgs) @@ -374,8 +374,8 @@ function _fisher_fishfile_read command awk -v FS=\# '!/^#/ && NF { print $1 }' end -function _fisher_fishfile_format -a pkgs - command awk -v PWD=$PWD -v HOME=$HOME -v PKGS="$pkgs" ' +function _fisher_fishfile_format -a pkgs removed_pkgs + command awk -v PWD=$PWD -v HOME=$HOME -v PKGS="$pkgs" -v REMOVED_PKGS="$removed_pkgs" ' BEGIN { pkg_count = split(PKGS, pkgs, ";") - 1 cmd = pkgs[1] @@ -401,10 +401,15 @@ function _fisher_fishfile_format -a pkgs } else if (newln) newln = "\n"(newln > 0 ? "" : newln) } END { - if (cmd == "rm" || pkg_count <= 1) exit - for (i = 2; i <= pkg_count; i++) { - if (!seen_pkgs[pkg_ids[i - 1]]) print pkgs[i] + if (cmd == "rm" || pkg_count <= 1) { + split(REMOVED_PKGS, tmp, ";") + for (i in tmp) removed_pkgs[normalize(tmp[i])] = i + for (i in pkg_ids) if (!(pkg_ids[i] in removed_pkgs)) { + print "cannot remove \"" pkg_ids[i] "\" -- package not found" > "/dev/stderr" + } + exit } + for (i in pkg_ids) if (!seen_pkgs[pkg_ids[i]]) print pkgs[i+1] } function normalize(s) { gsub(/^[ \t]*(https?:\/\/)?(.*github\.com\/)?|[\/ \t]*$/, "", s)