Skip to content

Commit 4755053

Browse files
committed
Refactor repository fetch logic
1 parent daddbad commit 4755053

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Install plugins using the `install` command followed by the path to the reposito
2929
fisher install jorgebucaran/nvm.fish
3030
```
3131

32-
> To install a plugin from GitLab, prefix the repository with `gitlab.com/`.
32+
> To install a plugin from GitLab, prefix the name with `gitlab.com/`.
3333
3434
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).
3535

functions/fisher.fish

+10-9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
6969
end
7070
end
7171

72+
7273
set --local pid_list
7374
set --local source_plugins
7475
set --local fetch_plugins $update_plugins $install_plugins
@@ -87,24 +88,24 @@ function fisher --argument-names cmd --description "A plugin manager for Fish"
8788
command cp -Rf $plugin/* $source
8889
else
8990
set temp (command mktemp -d)
90-
set name (string split \@ $plugin) || set name[2] HEAD
91-
set url https://api.github.com/repos/\$name[1]/tarball/\$name[2]
92-
set header 'Accept: application/vnd.github.v3+json'
93-
94-
if string match -q 'gitlab.com/*' \$name[1]
95-
set bare (string replace 'gitlab.com/' '' \$name[1])
96-
set repo (string split '/' \$bare)
97-
set url https://gitlab.com/{\$bare}/-/archive/{\$name[2]}/{\$repo[2]}-{\$name[2]}.tar.gz
91+
set repo (string split -- \@ $plugin) || set repo[2] HEAD
92+
93+
if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1])
94+
set name (string split -- / \$path)[-1]
95+
set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz
96+
else
97+
set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2]
9898
end
9999
100100
echo Fetching (set_color --underline)\$url(set_color normal)
101101
102-
if curl --silent -L -H \$header \$url | tar -xzC \$temp -f - 2>/dev/null
102+
if curl --silent -L \$url | tar -xzC \$temp -f - 2>/dev/null
103103
command cp -Rf \$temp/*/* $source
104104
else
105105
echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2
106106
command rm -rf $source
107107
end
108+
108109
command rm -rf \$temp
109110
end
110111

0 commit comments

Comments
 (0)