- ci: use && (tears of joy)
- docs: better explore package directions
- refactor: add license info to README; remove LICENSE file
- refactor `fisher ls REGEX`
- refactor: merge fishfile read/write parser to one script
- refactor: take advantage of nullglob in for loops
- refactor: prepend "fisher:" to error messages to improve logging
- refactor: remove unnecessary message after self-uninstall
- refactor: rename `fisher self-complete` to `fisher complete`
- refactor: simplify status report format script
This commit is contained in:
Jorge Bucaran 2019-01-17 17:59:33 +09:00
parent 9fc0779339
commit 6401d18504
No known key found for this signature in database
GPG key ID: E54BA3C0E646DB30
4 changed files with 66 additions and 135 deletions

View file

@ -5,6 +5,4 @@ before_install:
- sudo apt-get -y install fish - sudo apt-get -y install fish
script: script:
- curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish - curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
- fish -c "fisher version; and fisher help" - fish -c "fisher version && fisher help"
notifications:
email: false

View file

@ -1,19 +0,0 @@
Copyright © 2016-present [Jorge Bucaran](https://github.com/jorgebucaran)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -1,21 +1,19 @@
> ###### ✋ Psst! Migrating from V2 to V3? We got you. Check our [**migration guide**](https://github.com/jorgebucaran/fisher/issues/450) and happy upgrading!
# Fisher # Fisher
[![Build Status](https://img.shields.io/travis/jorgebucaran/fisher.svg)](https://travis-ci.org/jorgebucaran/fisher) [![Build Status](https://img.shields.io/travis/jorgebucaran/fisher.svg)](https://travis-ci.org/jorgebucaran/fisher)
[![Releases](https://img.shields.io/github/release/jorgebucaran/fisher.svg?label=latest)](https://github.com/jorgebucaran/fisher/releases) [![Releases](https://img.shields.io/github/release/jorgebucaran/fisher.svg?label=latest)](https://github.com/jorgebucaran/fisher/releases)
Fisher is a package manager for the [fish shell](https://fishshell.com). It defines a common interface for package authors to build and distribute their shell scripts in a portable way. You can use it to extend your shell capabilities, change the look of your prompt and create repeatable configurations across different systems effortlessly. Fisher is a package manager for the <a href="https://fishshell.com" title="friendly interactive shell">fish shell</a>. It defines a common interface for package authors to build and distribute shell scripts in a portable way. You can use it to extend your shell capabilities, change the look of your prompt and create repeatable configurations across different systems effortlessly.
Looking for packages? Check the [awesome fish shell](https://github.com/jorgebucaran/awesome-fish-shell) repository to get started. Looking for packages? Browse our curated collection at [git.io/awesome-fish](https://git.io/awesome-fish).
## Features ## Features
- Zero configuration - Zero configuration
- Oh My Fish package support - Oh My Fish! package support
- High-speed concurrent package downloads⌁! - High-speed concurrent package downloads
- If you've installed a package before, you can install it again offline - Cached downloads—if you've installed a package before, you can install it again offline
- Add, update and remove functions, completions, key bindings and configuration snippets from a variety of sources using the command line, editing your [fishfile](#using-the-fishfile) or both - Add, update and remove functions, completions, key bindings, and configuration snippets from a variety of sources using the command line, editing your [fishfile](#using-the-fishfile) or both
## Installation ## Installation
@ -39,7 +37,7 @@ Stuck in fish 2.0 and can't upgrade your shell? Check our [legacy fish support g
### Bootstrap installation ### Bootstrap installation
To automate installing Fisher and the packages listed in your [fishfile](#using-the-fishfile) on a new system, add the following code to your fish configuration file. To automate the installation process on a new system and fetch packages in your [fishfile](#using-the-fishfile) for the first time, add the following code to your fish configuration file.
```fish ```fish
if not functions -q fisher if not functions -q fisher
@ -117,7 +115,7 @@ edc/bass
~/path/to/myfish/pkg ~/path/to/myfish/pkg
``` ```
Is the output too large? This command accepts a regular expression to filter the listed packages. Is the output too large? This command accepts a regular expression to refine the listed packages.
``` ```
fisher ls "^gitlab|fish-.*" fisher ls "^gitlab|fish-.*"
@ -190,7 +188,7 @@ That will remove **rafaelrinaldi/pure** and **jethrokuan/z**, add **FabioAntunes
Packages help you organize shell scripts into reusable, independent components that can be shared through a git URL or the path to a local directory. Even if your package is not meant to be shared with others, you can benefit from composition and the ability to depend on other packages. Packages help you organize shell scripts into reusable, independent components that can be shared through a git URL or the path to a local directory. Even if your package is not meant to be shared with others, you can benefit from composition and the ability to depend on other packages.
The structure of a package can be adopted from the fictional project described below. These are the files that fisher looks for when installing or uninstalling a package. Of course, you can elaborate on this to add tests, documentation, and other files such as README and LICENSE files. The name of the root directory can be anything you like. The structure of a package can be adopted from the fictional project described below. These are the files that fisher looks for when installing or uninstalling a package. The name of the root directory can be anything you like.
``` ```
fish-kraken fish-kraken
@ -281,7 +279,7 @@ end
## Uninstalling ## Uninstalling
You want to know how to remove this package manager and everything you've installed with it from your system. This command will purge all packages, cache, configuration and related files. We'll miss you. You want to know how to remove this package manager and everything you've installed with it from your system. So long, and thanks for all the fish~! This command will purge all packages, cache, configuration and related files.
```fish ```fish
fisher self-uninstall fisher self-uninstall
@ -289,4 +287,10 @@ fisher self-uninstall
## License ## License
Fisher is MIT licensed. See the [LICENSE](LICENSE.md) for details. Copyright © 2016-2019 Jorge Bucaran <<https://jorgebucaran.com>>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,4 +1,4 @@
set -g fisher_version 3.2.4 set -g fisher_version 3.2.5
function fisher -a cmd -d "fish package manager" function fisher -a cmd -d "fish package manager"
set -q XDG_CACHE_HOME; or set XDG_CACHE_HOME ~/.cache set -q XDG_CACHE_HOME; or set XDG_CACHE_HOME ~/.cache
@ -17,8 +17,8 @@ function fisher -a cmd -d "fish package manager"
end end
if test ! -e $fisher_path/completions/fisher.fish if test ! -e $fisher_path/completions/fisher.fish
echo "fisher self-complete" >$fisher_path/completions/fisher.fish echo "fisher complete" >$fisher_path/completions/fisher.fish
_fisher_self_complete _fisher_complete
end end
if test -e $fisher_path/conf.d/fisher.fish if test -e $fisher_path/conf.d/fisher.fish
@ -38,13 +38,18 @@ function fisher -a cmd -d "fish package manager"
end end
switch "$cmd" switch "$cmd"
case self-complete case {,self-}complete
_fisher_self_complete _fisher_complete
case copy-user-key-bindings case copy-user-key-bindings
_fisher_copy_user_key_bindings _fisher_copy_user_key_bindings
case ls case ls
set -e argv[1] set -e argv[1]
_fisher_ls | _fisher_fmt | _fisher_filter | command awk "/$argv[1]/" if test -s "$fisher_path/fishfile"
set -l file (_fisher_fmt <$fisher_path/fishfile | _fisher_diff R)
_fisher_ls | _fisher_fmt | command awk -v FILE="$file" "
BEGIN { for (n = split(FILE, f); ++i <= n;) file[f[i]] } \$0 in file && /$argv[1]/
"
end
case self-update case self-update
_fisher_self_update (status -f) _fisher_self_update (status -f)
case self-uninstall case self-uninstall
@ -63,28 +68,28 @@ function fisher -a cmd -d "fish package manager"
end end
if test (count $argv) = 1 if test (count $argv) = 1
echo "invalid number of arguments" >&2 echo "fisher: invalid number of arguments" >&2
_fisher_help >&2 _fisher_help >&2
return 1 return 1
end end
_fisher_commit $argv _fisher_commit $argv
case \* case \*
echo "unknown flag or command \"$cmd\"" >&2 echo "fisher: unknown flag or command \"$cmd\"" >&2
_fisher_help >&2 _fisher_help >&2
return 1 return 1
end end
end end
function _fisher_self_complete function _fisher_complete
complete -ec fisher complete -ec fisher
complete -xc fisher -n __fish_use_subcommand -a add -d "Add packages" complete -xc fisher -n __fish_use_subcommand -a add -d "Add packages"
complete -xc fisher -n __fish_use_subcommand -a rm -d "Remove packages" complete -xc fisher -n __fish_use_subcommand -a rm -d "Remove packages"
complete -xc fisher -n __fish_use_subcommand -a ls -d "List installed packages" complete -xc fisher -n __fish_use_subcommand -a ls -d "List installed packages matching REGEX"
complete -xc fisher -n __fish_use_subcommand -a help -d "Show usage help" complete -xc fisher -n __fish_use_subcommand -a help -d "Show usage help"
complete -xc fisher -n __fish_use_subcommand -a version -d "$fisher_version" complete -xc fisher -n __fish_use_subcommand -a version -d "$fisher_version"
complete -xc fisher -n __fish_use_subcommand -a self-update -d "Update to the latest version" complete -xc fisher -n __fish_use_subcommand -a self-update -d "Update to the latest version"
for pkg in (_fisher_ls | _fisher_fmt | _fisher_filter) for pkg in (fisher ls)
complete -xc fisher -n "__fish_seen_subcommand_from rm" -a $pkg complete -xc fisher -n "__fish_seen_subcommand_from rm" -a $pkg
end end
end end
@ -113,22 +118,6 @@ function _fisher_fmt
command sed "s|^[[:space:]]*||;s|^$fisher_config/||;s|^$HOME|~|;s|^\.\/|$PWD/|;s|^github\.com/||;s|^https*://||;s|/*\$||" command sed "s|^[[:space:]]*||;s|^$fisher_config/||;s|^$HOME|~|;s|^\.\/|$PWD/|;s|^github\.com/||;s|^https*://||;s|/*\$||"
end end
function _fisher_file -a file
set -e argv[1]
_fisher_fmt < $file | _fisher_read $argv
end
function _fisher_filter
set -l file (_fisher_file $fisher_path/fishfile)
command awk -v FILE="$file" '
BEGIN {
n = split(FILE, file, " ")
for (i = 1; i <= n; i++) found[file[i]] = i
}
found[$0]
'
end
function _fisher_version -a file function _fisher_version -a file
echo "fisher version $fisher_version $file" | command sed "s|$HOME|~|" echo "fisher version $fisher_version $file" | command sed "s|$HOME|~|"
end end
@ -143,13 +132,11 @@ function _fisher_help
echo " fisher version Show the current version" echo " fisher version Show the current version"
echo " fisher self-update Update to the latest version" echo " fisher self-update Update to the latest version"
echo " fisher self-uninstall Uninstall from your system" echo " fisher self-uninstall Uninstall from your system"
echo
echo "examples:" echo "examples:"
echo " fisher add jethrokuan/z rafaelrinaldi/pure" echo " fisher add jethrokuan/z rafaelrinaldi/pure"
echo " fisher add gitlab.com/foo/bar@v2" echo " fisher add gitlab.com/foo/bar@v2"
echo " fisher add ~/path/to/local/pkg" echo " fisher add ~/path/to/local/pkg"
echo " fisher add < bundle" echo " fisher add < file"
echo " fisher rm rafaelrinaldi/pure"
echo " fisher rm rafaelrinaldi/pure" echo " fisher rm rafaelrinaldi/pure"
echo " fisher ls | fisher rm" echo " fisher ls | fisher rm"
echo " fisher ls fish-\*" echo " fisher ls fish-\*"
@ -165,7 +152,7 @@ function _fisher_self_update -a file
case "" $fisher_version case "" $fisher_version
command rm -f $file. command rm -f $file.
if test -z "$next_version" if test -z "$next_version"
echo "cannot update fisher -- are you offline?" >&2 echo "fisher: cannot update fisher -- are you offline?" >&2
return 1 return 1
end end
echo "fisher is already up-to-date" >&2 echo "fisher is already up-to-date" >&2
@ -174,7 +161,7 @@ function _fisher_self_update -a file
command mv -f $file. $file command mv -f $file. $file
source $file source $file
echo "updated to $fisher_version -- hooray!" >&2 echo "updated to $fisher_version -- hooray!" >&2
_fisher_self_complete _fisher_complete
end end
end end
@ -192,10 +179,8 @@ function _fisher_self_uninstall
set -e "$name" set -e "$name"
end end
complete -c fisher --erase
functions -e (functions -a | command awk '/^_fisher/') fisher functions -e (functions -a | command awk '/^_fisher/') fisher
complete -c fisher --erase
echo "done -- see you again!" >&2
end end
function _fisher_commit -a cmd function _fisher_commit -a cmd
@ -215,7 +200,7 @@ function _fisher_commit -a cmd
command rm -Rf $fisher_config command rm -Rf $fisher_config
command mkdir -p $fisher_config command mkdir -p $fisher_config
set -l next_pkgs (_fisher_file $fishfile $cmd (printf "%s\n" $argv | _fisher_fmt)) set -l next_pkgs (_fisher_fmt <$fishfile | _fisher_diff R $cmd (printf "%s\n" $argv | _fisher_fmt))
set -l new_pkgs (_fisher_fetch $next_pkgs) set -l new_pkgs (_fisher_fetch $next_pkgs)
set -l old_pkgs set -l old_pkgs
for pkg in $rm_pkgs for pkg in $rm_pkgs
@ -240,73 +225,38 @@ function _fisher_commit -a cmd
end end
end end
printf "%s\n" (_fisher_fmt <$fishfile | _fisher_write $cmd $actual_pkgs) >$fishfile printf "%s\n" (_fisher_fmt <$fishfile | _fisher_diff W $cmd $actual_pkgs) >$fishfile
_fisher_self_complete _fisher_complete
command awk -v N=(count $new_pkgs) -v O=(count $old_pkgs) -v R=(count $rm_pkgs) -v E=(_fisher_now $elapsed) ' command awk -v N=(count $new_pkgs) -v O=(count $old_pkgs) -v R=(count $rm_pkgs) -v E=(_fisher_now $elapsed) '
BEGIN { BEGIN {
if (N = N - O) res = msg(res, "added", N) res = fmt("removed", R - O, fmt("updated", O, fmt("added", N - O)))
if (O) res = msg(res, "updated", O)
if (R = R - O) res = msg(res, "removed", R)
printf((res ? res : "done") " in %.2fs\n", E / 1000) printf((res ? res : "done") " in %.2fs\n", E / 1000)
} }
function msg(res, str, n) { function fmt(action, n, s) {
return (res ? res ", " : "") str " " n " package" (n > 1 ? "s" : "") return n ? (s ? s ", " : s) action " " n " package" (n > 1 ? "s" : "") : s
} }
' >&2 ' >&2
end end
function _fisher_read -a cmd function _fisher_diff -a diff cmd
set -e argv[1] set -e argv[1..2]
command awk -v FS="[[:space:]]*#" -v CMD="$cmd" -v ARGS="$argv" ' command awk -v FS="[[:space:]]*#" -v DIFF="$diff" -v CMD="$cmd" -v ARGSTR="$argv" '
BEGIN { BEGIN {
split(ARGS, args, " ") for (n = split(ARGSTR, a, " "); i++ < n;) pkgs[getkey(a[i])] = a[i]
for (i in args) {
if (!((k = getkey(args[i])) in pkgs)) {
pkgs[k] = args[i]
if (CMD == "add") out[n++] = args[i]
}
}
}
!/^#/ && NF {
if (!file[k = getkey($1)]++ && !(k in pkgs)) out[n++] = $1
} }
{ k = getkey($1) }
DIFF == "R" && !(k in pkgs) && $0 = $1
DIFF == "W" && (/^#/ || !NF || (k in pkgs && $0 = pkgs[k]) || CMD != "rm")
DIFF == "W" || CMD == "rm" { delete pkgs[k] }
END { END {
for (i = 0; i < n; i++) print out[i] for (k in pkgs) {
if (CMD == "rm") { if (CMD != "rm" || DIFF == "W") print pkgs[k]
for (pkg in pkgs) { else print "package not in fishfile: \""k"\"" > "/dev/stderr"
if (!(pkg in file)) {
print "cannot remove \""pkg"\" -- package not listed in fishfile" > "/dev/stderr"
}
}
} }
} }
function getkey(s) { function getkey(s, a) {
return (split(s, a, /@+|:/) > 2) ? a[2]"/"a[1]"/"a[3] : a[1]
}
'
end
function _fisher_write -a cmd
set -e argv[1]
command awk -v CMD="$cmd" -v ARGS="$argv" '
BEGIN {
split(ARGS, args, " ")
for (i in args) pkgs[getkey(args[i])] = args[i]
}
{
if (/^#/ || !NF) print $0
else {
k = getkey($0)
if (out = pkgs[k] != 0 ? pkgs[k] : CMD != "rm" ? $0 : "") print out
pkgs[k] = 0
}
}
END {
for (k in pkgs) if (pkgs[k]) print pkgs[k]
}
function getkey(s) {
return (split(s, a, /@+|:/) > 2) ? a[2]"/"a[1]"/"a[3] : a[1] return (split(s, a, /@+|:/) > 2) ? a[2]"/"a[1]"/"a[3] : a[1]
} }
' '
@ -317,7 +267,7 @@ function _fisher_fetch
set -l next_pkgs set -l next_pkgs
set -l local_pkgs set -l local_pkgs
set -l actual_pkgs set -l actual_pkgs
set -q fisher_user_api_token; and set -l user_info -u $fisher_user_api_token set -q fisher_user_api_token; and set -l curl_opts -u $fisher_user_api_token
for i in $argv for i in $argv
switch $i switch $i
@ -326,7 +276,7 @@ function _fisher_fetch
if test -e "$path" if test -e "$path"
set local_pkgs $local_pkgs $path set local_pkgs $local_pkgs $path
else else
echo "cannot add \"$i\" -- is this a valid file?" >&2 echo "fisher: cannot add \"$i\" -- is this a valid file?" >&2
end end
continue continue
end end
@ -351,21 +301,21 @@ function _fisher_fetch
if test ! -d "$fisher_config/$pkg" if test ! -d "$fisher_config/$pkg"
fish -c " fish -c "
echo fetching $url >&2 echo fetching $url >&2
command mkdir -p $fisher_config/$pkg $fisher_cache/(dirname $pkg) command mkdir -p $fisher_config/$pkg $fisher_cache/(command dirname $pkg)
if test ! -z \"$branch\" if test ! -z \"$branch\"
command git clone $url $fisher_config/$pkg --branch $branch --depth 1 2>/dev/null command git clone $url $fisher_config/$pkg --branch $branch --depth 1 2>/dev/null
or echo cannot clone \"$url\" -- is this a valid url\? >&2 or echo fisher: cannot clone \"$url\" -- is this a valid url\? >&2
else if command curl $user_info -Ss $url 2>&1 | command tar -xzf- -C $fisher_config/$pkg 2>/dev/null else if command curl $curl_opts -Ss $url 2>&1 | command tar -xzf- -C $fisher_config/$pkg 2>/dev/null
command rm -Rf $fisher_cache/$pkg command rm -Rf $fisher_cache/$pkg
command mv -f $fisher_config/$pkg/* $fisher_cache/$pkg command mv -f $fisher_config/$pkg/* $fisher_cache/$pkg
command rm -Rf $fisher_config/$pkg command rm -Rf $fisher_config/$pkg
command cp -Rf {$fisher_cache,$fisher_config}/$pkg command cp -Rf {$fisher_cache,$fisher_config}/$pkg
else if test -d \"$fisher_cache/$pkg\" else if test -d \"$fisher_cache/$pkg\"
echo cannot connect to server -- searching in \"$fisher_cache/$pkg\" | command sed 's|$HOME|~|' >&2 echo fisher: cannot connect to server -- searching in \"$fisher_cache/$pkg\" | command sed 's|$HOME|~|' >&2
command cp -Rf $fisher_cache/$pkg $fisher_config/$pkg/.. command cp -Rf $fisher_cache/$pkg $fisher_config/$pkg/..
else else
command rm -Rf $fisher_config/$pkg command rm -Rf $fisher_config/$pkg
echo cannot add \"$pkg\" -- is this a valid package\? >&2 echo fisher: cannot add \"$pkg\" -- is this a valid package\? >&2
end end
" >/dev/null & " >/dev/null &
@ -403,15 +353,14 @@ function _fisher_deps
if test ! -d "$pkg" if test ! -d "$pkg"
echo $pkg echo $pkg
else if test -s "$pkg/fishfile" else if test -s "$pkg/fishfile"
_fisher_deps (_fisher_fmt < $pkg/fishfile | _fisher_read) _fisher_deps (_fisher_fmt < $pkg/fishfile | _fisher_diff R)
end end
end end
end end
function _fisher_add -a pkg opts function _fisher_add -a pkg opts
set -l name (command basename $pkg) set -l name (command basename $pkg)
set -l files $pkg/{functions,completions,conf.d}/**.* $pkg/*.fish for src in $pkg/{functions,completions,conf.d}/**.* $pkg/*.fish
for src in $files
set -l target (command basename $src) set -l target (command basename $src)
switch $src switch $src
case $pkg/conf.d\* case $pkg/conf.d\*
@ -443,8 +392,7 @@ end
function _fisher_rm -a pkg function _fisher_rm -a pkg
set -l name (command basename $pkg) set -l name (command basename $pkg)
set -l files $pkg/{conf.d,completions,functions}/**.* $pkg/*.fish for src in $pkg/{conf.d,completions,functions}/**.* $pkg/*.fish
for src in $files
set -l target (command basename $src) set -l target (command basename $src)
set -l filename (command basename $target .fish) set -l filename (command basename $target .fish)
switch $src switch $src