mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Add config option to install plugins in $HOME/.asdf
This commit is contained in:
parent
6e9da8af0c
commit
c86707c55f
@ -1,11 +1,11 @@
|
||||
#!/usr/bin/env fish
|
||||
|
||||
set -l asdf_dir (dirname (status -f))
|
||||
set -l asdf_data_dir (dirname (status -f))
|
||||
|
||||
# we get an ugly warning when setting the path if shims does not exist
|
||||
mkdir -p $asdf_dir/shims
|
||||
mkdir -p $asdf_data_dir/shims
|
||||
|
||||
for x in $asdf_dir/{bin,shims}
|
||||
for x in $asdf_data_dir/{bin,shims}
|
||||
if not contains $x $PATH
|
||||
and test -d $x
|
||||
set -gx PATH $x $PATH
|
||||
|
2
asdf.sh
2
asdf.sh
@ -17,8 +17,10 @@ ASDF_DIR="$(dirname "$current_script_path")"
|
||||
# replace all occurrences - ${parameter//pattern/string}
|
||||
ASDF_BIN="${ASDF_DIR}/bin"
|
||||
ASDF_SHIMS="${ASDF_DIR}/shims"
|
||||
ASDF_USER_SHIMS="${HOME}/.asdf/shims"
|
||||
[[ ":$PATH:" == *":${ASDF_BIN}:"* ]] && PATH="${PATH//$ASDF_BIN:/}"
|
||||
[[ ":$PATH:" == *":${ASDF_SHIMS}:"* ]] && PATH="${PATH//$ASDF_SHIMS:/}"
|
||||
[[ ":$PATH:" == *":${ASDF_USER_SHIMS}:"* ]] && PATH="${PATH//$ASDF_USER_SHIMS:/}"
|
||||
# add to front of $PATH
|
||||
PATH="${ASDF_BIN}:$PATH"
|
||||
PATH="${ASDF_SHIMS}:$PATH"
|
||||
|
@ -22,7 +22,7 @@ plugin_add_command() {
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
|
||||
mkdir -p "$(asdf_dir)/plugins"
|
||||
mkdir -p "$(asdf_data_dir)/plugins"
|
||||
|
||||
if [ -d "$plugin_path" ]; then
|
||||
display_error "Plugin named $plugin_name already added"
|
||||
|
@ -2,7 +2,7 @@ plugin_list_all_command() {
|
||||
initialize_or_update_repository
|
||||
|
||||
local plugins_index_path
|
||||
plugins_index_path="$(asdf_dir)/repository/plugins"
|
||||
plugins_index_path="$(asdf_data_dir)/repository/plugins"
|
||||
|
||||
local plugins_local_path
|
||||
plugins_local_path="$(get_plugin_path)"
|
||||
|
@ -1,7 +1,7 @@
|
||||
plugin_push_command() {
|
||||
local plugin_name=$1
|
||||
if [ "$plugin_name" = "--all" ]; then
|
||||
for dir in "$(asdf_dir)"/plugins/*; do
|
||||
for dir in "$(asdf_data_dir)"/plugins/*; do
|
||||
echo "Pushing $(basename "$dir")..."
|
||||
(cd "$dir" && git push)
|
||||
done
|
||||
|
@ -6,7 +6,7 @@ plugin_remove_command() {
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
|
||||
rm -rf "$plugin_path"
|
||||
rm -rf "$(asdf_dir)/installs/${plugin_name}"
|
||||
rm -rf "$(asdf_data_dir)/installs/${plugin_name}"
|
||||
|
||||
grep -l "asdf-plugin: ${plugin_name}" "$(asdf_dir)"/shims/* 2>/dev/null | xargs rm -f
|
||||
grep -l "asdf-plugin: ${plugin_name}" "$(asdf_data_dir)"/shims/* 2>/dev/null | xargs rm -f
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ plugin_update_command() {
|
||||
|
||||
local plugin_name=$1
|
||||
if [ "$plugin_name" = "--all" ]; then
|
||||
for dir in "$(asdf_dir)"/plugins/*; do
|
||||
for dir in "$(asdf_data_dir)"/plugins/*; do
|
||||
echo "Updating $(basename "$dir")..."
|
||||
(cd "$dir" && git pull)
|
||||
done
|
||||
|
@ -23,7 +23,7 @@ reshim_command() {
|
||||
else
|
||||
# generate for all versions of the package
|
||||
local plugin_installs_path
|
||||
plugin_installs_path="$(asdf_dir)/installs/${plugin_name}"
|
||||
plugin_installs_path="$(asdf_data_dir)/installs/${plugin_name}"
|
||||
|
||||
for install in "${plugin_installs_path}"/*/; do
|
||||
local full_version_name
|
||||
@ -37,8 +37,8 @@ reshim_command() {
|
||||
|
||||
ensure_shims_dir() {
|
||||
# Create shims dir if doesn't exist
|
||||
if [ ! -d "$(asdf_dir)/shims" ]; then
|
||||
mkdir "$(asdf_dir)/shims"
|
||||
if [ ! -d "$(asdf_data_dir)/shims" ]; then
|
||||
mkdir "$(asdf_data_dir)/shims"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ write_shim_script() {
|
||||
local plugin_shims_path
|
||||
plugin_shims_path=$(get_plugin_path "$plugin_name")/shims
|
||||
local shim_path
|
||||
shim_path="$(asdf_dir)/shims/$executable_name"
|
||||
shim_path="$(asdf_data_dir)/shims/$executable_name"
|
||||
|
||||
if [ -f "$plugin_shims_path/$executable_name" ]; then
|
||||
cp "$plugin_shims_path/$executable_name" "$shim_path"
|
||||
@ -169,7 +169,7 @@ remove_obsolete_shims() {
|
||||
local plugin_name=$1
|
||||
local full_version=$2
|
||||
local shims_path
|
||||
shims_path="$(asdf_dir)/shims"
|
||||
shims_path="$(asdf_data_dir)/shims"
|
||||
|
||||
IFS=':' read -r -a version_info <<< "$full_version"
|
||||
if [ "${version_info[0]}" = "ref" ]; then
|
||||
@ -203,7 +203,7 @@ remove_shim_for_version() {
|
||||
local plugin_shims_path
|
||||
plugin_shims_path=$(get_plugin_path "$plugin_name")/shims
|
||||
local shim_path
|
||||
shim_path="$(asdf_dir)/shims/$executable_name"
|
||||
shim_path="$(asdf_data_dir)/shims/$executable_name"
|
||||
local count_installed
|
||||
count_installed=$(list_installed_versions "$plugin_name" | wc -l)
|
||||
|
||||
|
@ -2,7 +2,7 @@ update_command() {
|
||||
local update_to_head=$1
|
||||
|
||||
(
|
||||
cd "$(asdf_dir)" || exit 1
|
||||
cd "$(asdf_data_dir)" || exit 1
|
||||
|
||||
if [ -f asdf_updates_disabled ]; then
|
||||
echo "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf."
|
||||
|
48
lib/utils.sh
48
lib/utils.sh
@ -23,17 +23,40 @@ asdf_repository_url() {
|
||||
echo "https://github.com/asdf-vm/asdf-plugins.git"
|
||||
}
|
||||
|
||||
get_install_type(){
|
||||
local install_type
|
||||
install_type=$(get_asdf_config_value "install_type")
|
||||
|
||||
echo "$install_type"
|
||||
}
|
||||
|
||||
asdf_data_dir(){
|
||||
local data_dir
|
||||
|
||||
if [ "$(get_install_type)" = "user" ]; then
|
||||
data_dir="${HOME}/.asdf"
|
||||
else
|
||||
data_dir="$(asdf_dir)"
|
||||
fi
|
||||
|
||||
echo "$data_dir"
|
||||
}
|
||||
|
||||
get_install_path() {
|
||||
local plugin=$1
|
||||
local install_type=$2
|
||||
local version=$3
|
||||
mkdir -p "$(asdf_dir)/installs/${plugin}"
|
||||
|
||||
local install_dir
|
||||
install_dir="$(asdf_data_dir)/installs"
|
||||
|
||||
mkdir -p "${install_dir}/${plugin}"
|
||||
|
||||
if [ "$install_type" = "version" ]
|
||||
then
|
||||
echo "$(asdf_dir)/installs/${plugin}/${version}"
|
||||
echo "${install_dir}/${plugin}/${version}"
|
||||
else
|
||||
echo "$(asdf_dir)/installs/${plugin}/${install_type}-${version}"
|
||||
echo "${install_dir}/${plugin}/${install_type}-${version}"
|
||||
fi
|
||||
}
|
||||
|
||||
@ -42,8 +65,11 @@ list_installed_versions() {
|
||||
local plugin_path
|
||||
plugin_path=$(get_plugin_path "$plugin_name")
|
||||
|
||||
local install_dir
|
||||
install_dir="$(asdf_data_dir)/installs"
|
||||
|
||||
local plugin_installs_path
|
||||
plugin_installs_path=$(asdf_dir)/installs/${plugin_name}
|
||||
plugin_installs_path=${install_dir}/${plugin_name}
|
||||
|
||||
if [ -d "$plugin_installs_path" ]; then
|
||||
# shellcheck disable=SC2045
|
||||
@ -62,7 +88,7 @@ check_if_plugin_exists() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$(asdf_dir)/plugins/$plugin_name" ]; then
|
||||
if [ ! -d "$(asdf_data_dir)/plugins/$plugin_name" ]; then
|
||||
display_error "No such plugin: $plugin_name"
|
||||
exit 1
|
||||
fi
|
||||
@ -84,7 +110,7 @@ check_if_version_exists() {
|
||||
}
|
||||
|
||||
get_plugin_path() {
|
||||
echo "$(asdf_dir)/plugins/$1"
|
||||
echo "$(asdf_data_dir)/plugins/$1"
|
||||
}
|
||||
|
||||
display_error() {
|
||||
@ -303,7 +329,7 @@ get_asdf_config_value() {
|
||||
|
||||
repository_needs_update() {
|
||||
local update_file_dir
|
||||
update_file_dir="$(asdf_dir)/tmp"
|
||||
update_file_dir="$(asdf_data_dir)/tmp"
|
||||
local update_file_name
|
||||
update_file_name="repo-updated"
|
||||
# `find` outputs filename if it has not been modified in the last day
|
||||
@ -317,7 +343,7 @@ initialize_or_update_repository() {
|
||||
local repository_path
|
||||
|
||||
repository_url=$(asdf_repository_url)
|
||||
repository_path=$(asdf_dir)/repository
|
||||
repository_path=$(asdf_data_dir)/repository
|
||||
|
||||
if [ ! -d "$repository_path" ]; then
|
||||
echo "initializing plugin repository..."
|
||||
@ -327,15 +353,15 @@ initialize_or_update_repository() {
|
||||
(cd "$repository_path" && git fetch && git reset --hard origin/master)
|
||||
fi
|
||||
|
||||
mkdir -p "$(asdf_dir)/tmp"
|
||||
touch "$(asdf_dir)/tmp/repo-updated"
|
||||
mkdir -p "$(asdf_data_dir)/tmp"
|
||||
touch "$(asdf_data_dir)/tmp/repo-updated"
|
||||
}
|
||||
|
||||
get_plugin_source_url() {
|
||||
local plugin_name=$1
|
||||
local plugin_config
|
||||
|
||||
plugin_config="$(asdf_dir)/repository/plugins/$plugin_name"
|
||||
plugin_config="$(asdf_data_dir)/repository/plugins/$plugin_name"
|
||||
|
||||
|
||||
if [ -f "$plugin_config" ]; then
|
||||
|
@ -124,6 +124,14 @@ teardown() {
|
||||
[ "$output" = "0.1.0|$HOME/.tool-versions" ]
|
||||
}
|
||||
|
||||
@test "asdf_data_dir should return user dir if configured" {
|
||||
echo "install_type = user" > $HOME/.asdfrc
|
||||
|
||||
run asdf_data_dir
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$HOME/.asdf" ]
|
||||
}
|
||||
|
||||
@test "find_version should return \$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" {
|
||||
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions"
|
||||
echo "dummy 0.1.0" > $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
|
||||
|
Loading…
Reference in New Issue
Block a user