Skip to content

Commit 20cdbfe

Browse files
committed
Use a git repository for installing plugins.
1 parent 68d759b commit 20cdbfe

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
installs
22
plugins
33
shims
4+
repository
45
.vagrant
5-

‎help.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
MANAGE PLUGINS
2-
asdf plugin-add <name> <git-url> Add git repo as plugin
2+
asdf plugin-add <name> [<git-url>] Add a plugin
33
asdf plugin-list List installed plugins
44
asdf plugin-remove <name> Remove plugin and package versions
55
asdf plugin-update <name> Update plugin

‎lib/commands/plugin-add.sh‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
plugin_add_command() {
2-
if [ "$#" -ne 2 ]; then
3-
display_error "usage: asdf plugin-add <name> <git-url>"
2+
if [[ $# -lt 1 || $# -gt 2 ]]; then
3+
display_error "usage: asdf plugin-add <name> [<git-url>]"
44
exit 1
55
fi
66

77
local plugin_name=$1
8-
local source_url=$2
8+
9+
if [ -n "$2" ]; then
10+
local source_url=$2
11+
else
12+
initialize_or_update_repository
13+
local source_url=$(get_plugin_source_url $plugin_name)
14+
fi
15+
16+
if [ -z "$source_url" ]; then
17+
display_error "plugin $plugin_name not found in repository"
18+
exit 1
19+
fi
20+
921
local plugin_path=$(get_plugin_path $plugin_name)
1022

1123
mkdir -p $(asdf_dir)/plugins

‎lib/utils.sh‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,29 @@ get_asdf_config_value() {
206206
get_asdf_config_value_from_file $default_config_path $key
207207
fi
208208
}
209+
210+
asdf_repository_url() {
211+
echo "https://github.com/doughsay/asdf-plugins.git"
212+
}
213+
214+
initialize_or_update_repository() {
215+
local repository_url=$(asdf_repository_url)
216+
local repository_path=$(asdf_dir)/repository
217+
218+
if [ -d $repository_path ]; then
219+
echo "updating plugin repository..."
220+
(cd $repository_path && git pull)
221+
else
222+
echo "initializing plugin repository..."
223+
git clone $repository_url $repository_path
224+
fi
225+
}
226+
227+
get_plugin_source_url() {
228+
local plugin_name=$1
229+
local plugin_config="$(asdf_dir)/repository/plugins/$plugin_name"
230+
231+
if [ -f $plugin_config ]; then
232+
cat $plugin_config | grep "repository" | awk -F'=' '{print $2}' | sed 's/ //'
233+
fi
234+
}

0 commit comments

Comments
 (0)