Merge branch 'master' of github.com:HashNuke/asdf

This commit is contained in:
Akash Manohar J 2015-06-24 19:17:25 +05:30
commit 9f99442603
17 changed files with 147 additions and 40 deletions

View File

@ -5,7 +5,7 @@
> * [Ruby](https://github.com/HashNuke/asdf-ruby)
> * [Erlang](https://github.com/HashNuke/asdf-erlang)
> * [Elixir](https://github.com/HashNuke/asdf-elixir)
> * Node.js pending. Tired polishing this stuff. I'll finish it up over the weekend.
> * [Node.js](https://github.com/HashNuke/asdf-nodejs)
>
> There is a [super-simple API](https://github.com/HashNuke/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.
@ -23,10 +23,10 @@ git clone https://github.com/HashNuke/asdf.git ~/.asdf
Depending on your OS, run the following
```bash
# For Ubuntu or other linux distros
echo 'source $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo '. $HOME/.asdf/asdf.sh' >> ~/.bashrc
# OR for Max OSX
echo 'source $HOME/.asdf/asdf.sh' >> ~/.bash_profile
echo '. $HOME/.asdf/asdf.sh' >> ~/.bash_profile
```
If you use zsh or any other shell, replace `.bashrc` with the config file for the respective shell.
@ -54,6 +54,13 @@ asdf plugin-add <name> <git-url>
# asdf plugin-add erlang https://github.com/HashNuke/asdf-erlang.git
```
##### List installed plugins
```bash
asdf plugin-list
# asdf plugin-list
```
##### Remove a plugin
```bash
@ -81,6 +88,10 @@ asdf plugin-update <name>
asdf install <name> <version>
# asdf install erlang 17.3
asdf which <name>
# asdf which erlang
# 17.3
asdf uninstall <name> <version>
# asdf uninstall erlang 17.3
```

View File

@ -1,5 +1,10 @@
#!/usr/bin/env bash
current_script_path=${BASH_SOURCE[0]}
if [ "${BASH_SOURCE[0]}" != "" ]; then
current_script_path=${BASH_SOURCE[0]}
else
current_script_path=$0
fi
asdf_dir=$(cd $(dirname $current_script_path); echo $(pwd))
export PATH="${asdf_dir}/bin:${asdf_dir}/shims:$PATH"

View File

@ -5,10 +5,13 @@ source $(dirname $(dirname $0))/lib/utils.sh
source $(dirname $(dirname $0))/lib/commands/help.sh
source $(dirname $(dirname $0))/lib/commands/install.sh
source $(dirname $(dirname $0))/lib/commands/uninstall.sh
source $(dirname $(dirname $0))/lib/commands/which.sh
source $(dirname $(dirname $0))/lib/commands/where.sh
source $(dirname $(dirname $0))/lib/commands/list.sh
source $(dirname $(dirname $0))/lib/commands/list-all.sh
source $(dirname $(dirname $0))/lib/commands/reshim.sh
source $(dirname $(dirname $0))/lib/commands/plugin-add.sh
source $(dirname $(dirname $0))/lib/commands/plugin-list.sh
source $(dirname $(dirname $0))/lib/commands/plugin-update.sh
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
@ -31,6 +34,12 @@ case $1 in
"uninstall")
uninstall_command $callback_args;;
"which")
which_command $callback_args;;
"where")
where_command $callback_args;;
"list")
list_command $callback_args;;
@ -46,6 +55,9 @@ case $1 in
"plugin-add")
plugin_add_command $callback_args;;
"plugin-list")
plugin_list_command $callback_args;;
"plugin-update")
plugin_update_command $callback_args;;

View File

@ -38,6 +38,11 @@ fi
install_path=$(get_install_path $plugin_name $install_type $version)
if [ ! -d $install_path ]; then
echo "$plugin_name $full_version not installed"
exit 1
fi
if [ ! -f ${install_path}/${executable_path} ]; then
echo "No such command in $full_version of $plugin_name"
exit 1

View File

@ -49,3 +49,11 @@ Setup the env to run the binaries in the package.
#### bin/uninstall
Uninstalls a specific version of a tool.
### Custom shim templates
**PLEASE use this feature only if absolutely required**
asdf allows custom shim templates. For an executable called `foo`, if there's a `shims/foo` file in the plugin, then asdf will copy that file instead of using it's standard shim template.
This must be used wisely. For now AFAIK, it's only being used in the Elixir plugin, because an executable is also read as an Elixir file apart from just being an executable. Which makes it not possible to use the standard bash shim.

View File

@ -1,5 +1,6 @@
MANAGE PLUGINS
asdf plugin-add <name> <git-url> Add git repo as plugin
asdf plugin-list List installed plugins
asdf plugin-remove <name> Remove plugin and package versions
asdf plugin-update <name> Update plugin
asdf plugin-update --all Update all plugins
@ -8,6 +9,8 @@ MANAGE PLUGINS
MANAGE PACKAGES
asdf install <name> <version> Install a specific version of a package
asdf remove <name> <version> Remove a specific version of a package
asdf which <name> Display version set or being used for package
asdf where <name> <version> Display install path for an installed version
asdf list <name> List installed versions of a package
asdf list-all <name> List all versions of a package

View File

@ -17,13 +17,14 @@ install_command() {
if [ -d $install_path ]; then
echo "$plugin_name $full_version is already installed"
echo "To uninstall it run: asdf uninstall $plugin_name $full_version"
exit 1
exit 0
fi
(
export ASDF_INSTALL_TYPE=$install_type
export ASDF_INSTALL_VERSION=$version
export ASDF_INSTALL_PATH=$install_path
mkdir $install_path
bash ${plugin_path}/bin/install
)
local exit_code=$?

View File

@ -1,6 +1,6 @@
list_all_command() {
local package_name=$1
local plugin_path=$(get_plugin_path $package_name)
local plugin_name=$1
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
local versions=$(bash ${plugin_path}/bin/list-all)

View File

@ -1,13 +1,13 @@
list_command() {
local package_name=$1
local plugin_path=$(get_plugin_path $package_name)
local plugin_name=$1
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
local package_installs_path=$(asdf_dir)/installs/${package_name}
local plugin_installs_path=$(asdf_dir)/installs/${plugin_name}
if [ -d $package_installs_path ]; then
if [ -d $plugin_installs_path ]; then
#TODO check if dir is empty and show no-installed-versions msg
for install in ${package_installs_path}/*/; do
for install in ${plugin_installs_path}/*/; do
echo "$(basename $install)"
done
else

View File

@ -1,11 +1,16 @@
plugin_add_command() {
local package_name=$1
local plugin_name=$1
local source_url=$2
local plugin_path=$(get_plugin_path $package_name)
local plugin_path=$(get_plugin_path $plugin_name)
mkdir -p $(asdf_dir)/plugins
git clone $source_url $plugin_path
if [ $? -eq 0 ]; then
chmod +x $plugin_path/bin/*
if [ -d $plugin_path ]; then
echo "Plugin named $plugin_name already added"
else
git clone $source_url $plugin_path
if [ $? -eq 0 ]; then
chmod +x $plugin_path/bin/*
fi
fi
}

View File

@ -0,0 +1,11 @@
plugin_list_command() {
local plugins_path=$(get_plugin_path)
if ls $plugins_path &> /dev/null; then
for plugin_path in $plugins_path/* ; do
echo "$(basename $plugin_path)"
done
else
echo 'Oohes nooes ~! No plugins installed'
fi
}

View File

@ -1,7 +1,7 @@
plugin_remove_command() {
local package_name=$1
local plugin_path=$(get_plugin_path $package_name)
local plugin_name=$1
local plugin_path=$(get_plugin_path $plugin_name)
rm -rf $plugin_path
rm -rf $(asdf_dir)/installs/${package_name}
rm -rf $(asdf_dir)/installs/${plugin_name}
}

View File

@ -1,6 +1,6 @@
shim_command() {
local plugin_name=$1
local executable_path=$3
local executable_path=$2
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
ensure_shims_dir
@ -20,9 +20,9 @@ reshim_command() {
generate_shims_for_version $plugin_name $full_version
else
# generate for all versions of the package
local package_installs_path=$(asdf_dir)/installs/${plugin_name}
local plugin_installs_path=$(asdf_dir)/installs/${plugin_name}
for install in ${package_installs_path}/*/; do
for install in ${plugin_installs_path}/*/; do
local full_version_name=$(echo $(basename $install) | sed 's/ref\-/ref\:/')
generate_shims_for_version $plugin_name $full_version_name
done
@ -40,12 +40,18 @@ ensure_shims_dir() {
write_shim_script() {
local plugin_name=$1
local executable_path=$3
local shim_path=$(asdf_dir)/shims/$(basename $executable_path)
local executable_path=$2
local executable_name=$(basename $executable_path)
local plugin_shims_path=$(get_plugin_path $plugin_name)/shims
local shim_path=$(asdf_dir)/shims/$executable_name
echo """#!/usr/bin/env bash
if [ -f $plugin_shims_path/$executable_name ]; then
cp $plugin_shims_path/$executable_name $shim_path
else
echo """#!/usr/bin/env bash
$(asdf_dir)/bin/private/asdf-exec ${plugin_name} ${executable_path} \"\$@\"
""" > $shim_path
fi
chmod +x $shim_path
}
@ -53,7 +59,7 @@ $(asdf_dir)/bin/private/asdf-exec ${plugin_name} ${executable_path} \"\$@\"
generate_shim_for_executable() {
local plugin_name=$1
local executable=$3
local executable=$2
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
@ -72,9 +78,9 @@ generate_shim_for_executable() {
generate_shims_for_version() {
local package_name=$1
local plugin_name=$1
local full_version=$2
local plugin_path=$(get_plugin_path $package_name)
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
IFS=':' read -a version_info <<< "$full_version"
@ -86,7 +92,7 @@ generate_shims_for_version() {
local version="${version_info[0]}"
fi
local install_path=$(get_install_path $package_name $install_type $version)
local install_path=$(get_install_path $plugin_name $install_type $version)
if [ -f ${plugin_path}/bin/list-bin-paths ]; then
local space_seperated_list_of_bin_paths=$(
@ -106,7 +112,7 @@ generate_shims_for_version() {
for executable_file in $install_path/$bin_path/*; do
# because just $executable_file gives absolute path; We don't want version hardcoded in shim
local executable_path_relative_to_install_path=$bin_path/$(basename $executable_file)
write_shim_script $package_name $executable_path_relative_to_install_path
write_shim_script $plugin_name $executable_path_relative_to_install_path
done
done
}

View File

@ -1,7 +1,7 @@
uninstall_command() {
local package_name=$1
local plugin_name=$1
local full_version=$2
local plugin_path=$(get_plugin_path $package_name)
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
@ -14,7 +14,7 @@ uninstall_command() {
local version="${version_info[0]}"
fi
local install_path=$(get_install_path $package_name $install_type $version)
local install_path=$(get_install_path $plugin_name $install_type $version)
if [ ! -d $install_path ]; then
display_error "No such version"

25
lib/commands/where.sh Normal file
View File

@ -0,0 +1,25 @@
where_command() {
local plugin_name=$1
local full_version=$2
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
IFS=':' read -a version_info <<< "$full_version"
if [ "${version_info[0]}" = "ref" ]; then
local install_type="${version_info[0]}"
local version="${version_info[1]}"
else
local install_type="version"
local version="${version_info[0]}"
fi
local install_path=$(get_install_path $plugin_name $install_type $version)
if [ -d $install_path ]; then
echo $install_path
exit 0
else
echo "Version not installed"
exit 1
fi
}

15
lib/commands/which.sh Normal file
View File

@ -0,0 +1,15 @@
which_command() {
local plugin_name=$1
local plugin_path=$(get_plugin_path $plugin_name)
check_if_plugin_exists $plugin_path
full_version=$(get_preset_version_for $plugin_name)
if [ "$full_version" == "" ]; then
echo "No version set for ${plugin_name}"
exit -1
else
echo "$full_version"
exit 0
fi
}

View File

@ -14,16 +14,16 @@ asdf_dir() {
get_install_path() {
local package=$1
local plugin=$1
local install_type=$2
local version=$3
mkdir -p $(asdf_dir)/installs/${package}
mkdir -p $(asdf_dir)/installs/${plugin}
if [ $install_type = "version" ]
then
echo $(asdf_dir)/installs/${package}/${version}
echo $(asdf_dir)/installs/${plugin}/${version}
else
echo $(asdf_dir)/installs/${package}/${install_type}-${version}
echo $(asdf_dir)/installs/${plugin}/${install_type}-${version}
fi
}
@ -77,7 +77,7 @@ get_asdf_versions_file_path() {
get_preset_version_for() {
local package=$1
local plugin=$1
local asdf_versions_path=$(get_asdf_versions_file_path)
if [ "$asdf_versions_path" != "" ]; then
@ -112,7 +112,7 @@ get_package_version_from_file() {
local tool_name=$(echo "${tool_info[0]}" | xargs)
local tool_version=$(echo "${tool_info[1]}" | xargs)
if [ "$tool_name" = "$package" ]
if [ "$tool_name" = "$plugin" ]
then
matching_tool_version=$tool_version
break;