From 475505312cd805e9eea58ca152f5523939273014 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sun, 19 Jun 2022 16:45:11 -0300 Subject: [PATCH] Refactor repository fetch logic --- README.md | 2 +- functions/fisher.fish | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0be3c0f..a8a2d20 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Install plugins using the `install` command followed by the path to the reposito fisher install jorgebucaran/nvm.fish ``` -> To install a plugin from GitLab, prefix the repository with `gitlab.com/`. +> To install a plugin from GitLab, prefix the name with `gitlab.com/`. To get a specific version of a plugin add an `@` symbol after the plugin name followed by a tag, branch, or [commit](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefcommit-ishacommit-ishalsocommittish). diff --git a/functions/fisher.fish b/functions/fisher.fish index 74b7819..d3bba5c 100644 --- a/functions/fisher.fish +++ b/functions/fisher.fish @@ -69,6 +69,7 @@ function fisher --argument-names cmd --description "A plugin manager for Fish" end end + set --local pid_list set --local source_plugins set --local fetch_plugins $update_plugins $install_plugins @@ -87,24 +88,24 @@ function fisher --argument-names cmd --description "A plugin manager for Fish" command cp -Rf $plugin/* $source else set temp (command mktemp -d) - set name (string split \@ $plugin) || set name[2] HEAD - set url https://api.github.com/repos/\$name[1]/tarball/\$name[2] - set header 'Accept: application/vnd.github.v3+json' - - if string match -q 'gitlab.com/*' \$name[1] - set bare (string replace 'gitlab.com/' '' \$name[1]) - set repo (string split '/' \$bare) - set url https://gitlab.com/{\$bare}/-/archive/{\$name[2]}/{\$repo[2]}-{\$name[2]}.tar.gz + set repo (string split -- \@ $plugin) || set repo[2] HEAD + + if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1]) + set name (string split -- / \$path)[-1] + set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz + else + set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2] end echo Fetching (set_color --underline)\$url(set_color normal) - if curl --silent -L -H \$header \$url | tar -xzC \$temp -f - 2>/dev/null + if curl --silent -L \$url | tar -xzC \$temp -f - 2>/dev/null command cp -Rf \$temp/*/* $source else echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2 command rm -rf $source end + command rm -rf \$temp end