Compare commits

...

12 Commits

Author SHA1 Message Date
진재연(Jin Jae-yeon)
602a40216d
Merge 40ea0e1ce6 into c778ea1dec 2024-12-18 10:38:27 -05:00
ooo oo
c778ea1dec
docs: split Lint and Test badges for title asdf in README.MD (#1725)
Co-authored-by: Trevor Brown <Stratus3D@users.noreply.github.com>
2024-12-18 10:37:35 -05:00
Trevor Brown
98b8c6fd92 Merge branch 'OJarrisonn-nu/completion' 2024-12-18 10:32:27 -05:00
Trevor Brown
04fe7e30ca feat: correct description for version preceded by star 2024-12-18 10:31:05 -05:00
Trevor Brown
e8d6372564
Merge branch 'master' into nu/completion 2024-12-18 10:29:06 -05:00
莊喬
fa3d216540
test: unset ASDF_DATA_DIR and ASDF_CONFIG_FILE during test (#1722)
Co-authored-by: Trevor Brown <Stratus3D@users.noreply.github.com>
2024-12-17 15:58:05 -05:00
Kamontat Chantrachirathumrong
221507f1c0
fix: when download path got removed, it should use -f to force delete the download files (#1746)
Co-authored-by: Trevor Brown <Stratus3D@users.noreply.github.com>
2024-12-17 14:53:15 -05:00
Andrew Zipperer
d462b55ec9
docs: propose edits for tiny typographical/grammatical errors (#1747)
Co-authored-by: Andrew-Zipperer <atzipperer@gmail.com>
Co-authored-by: Trevor Brown <Stratus3D@users.noreply.github.com>
2024-12-17 14:49:40 -05:00
Ben Blank
ebdb229ce6
fix(completions): Address two Bash completion bugs (#1770)
Co-authored-by: Trevor Brown <Stratus3D@users.noreply.github.com>
2024-12-17 07:42:20 -05:00
Trevor Brown
8db4c60934
Merge branch 'master' into nu/completion 2024-12-16 19:41:14 -05:00
진재연 (Jin Jae-yeon)
40ea0e1ce6 fix: Support for Windows with Git-Bash or MSYS Bash
- .exe executables are shims to non-extensions path
- .bat files to reshim for cmd or Powershell
- .bat execute bash script with bash built Windows
2024-10-24 10:55:35 +09:00
OJarrisonn
82be580602 feat: improved completions for version in commands
Improved completions for commands such as `asdf global <name> <version>` to list the installed versions

Added "complete asdf plugin versions installed" and "complete asdf plugin versions all" that produce completions for the installed versions and for all versions available for a given plugin

Improved `asdf install` completion to list the installed plugins and all the available versions
2024-06-01 17:40:04 -03:00
9 changed files with 85 additions and 23 deletions

View File

@ -1,4 +1,6 @@
# asdf [![Lint](https://github.com/asdf-vm/asdf/actions/workflows/lint.yml/badge.svg)](https://github.com/asdf-vm/asdf/actions/workflows/lint.yml) [![Tests](https://github.com/asdf-vm/asdf/actions/workflows/tests.yml/badge.svg)](https://github.com/asdf-vm/asdf/actions/workflows/tests.yml)
# asdf
[![Lint](https://github.com/asdf-vm/asdf/actions/workflows/lint.yml/badge.svg)](https://github.com/asdf-vm/asdf/actions/workflows/lint.yml) [![Tests](https://github.com/asdf-vm/asdf/actions/workflows/tests.yml/badge.svg)](https://github.com/asdf-vm/asdf/actions/workflows/tests.yml)
**Manage multiple runtime versions with a single CLI tool, extendable via plugins** - [docs at asdf-vm.com](https://asdf-vm.com/)

50
asdf.nu
View File

@ -74,6 +74,30 @@ module asdf {
}
}
def "complete asdf plugin versions all" [context: string] {
let plugin = $context | str trim | split words | last
^asdf list all $plugin
| lines
| each { |line| $line | str trim }
| prepend "latest"
}
def "complete asdf plugin versions installed" [context: string] {
let plugin = $context | str trim | split words | last
let versions = ^asdf list $plugin
| lines
| each { |line| $line | str trim }
| each { |version| if ($version | str starts-with "*") {{value: ($version | str substring 1..), description: "current version"}} else {{value: $version, description: ""}} }
let latest = ^asdf latest $plugin | str trim
if ($versions | get value | any {|el| $el == $latest}) {
$versions | prepend {value: "latest", description: $"alias to ($latest)"}
} else {
$versions
}
}
# ASDF version manager
export extern main [
subcommand?: string@"complete asdf sub-commands"
@ -145,15 +169,15 @@ module asdf {
# install a package version
export extern "asdf install" [
name?: string # Name of the package
version?: string # Version of the package or latest
name?: string@"complete asdf installed plugins" # Name of the package
version?: string@"complete asdf plugin versions all" # Version of the package or latest
]
# Remove an installed package version
export extern "asdf uninstall" [
name: string@"complete asdf installed" # Name of the package
version: string # Version of the package
version: string@"complete asdf plugin versions installed" # Version of the package
]
# Display current version
@ -169,31 +193,31 @@ module asdf {
# Display install path for an installled package version
export extern "asdf where" [
name: string@"complete asdf installed" # Name of installed package
version?: string # Version of installed package
version?: string@"complete asdf plugin versions installed" # Version of installed package
]
# Set the package local version
export extern "asdf local" [
name: string@"complete asdf installed" # Name of the package
version?: string # Version of the package or latest
version?: string@"complete asdf plugin versions installed" # Version of the package or latest
]
# Set the package global version
export extern "asdf global" [
name: string@"complete asdf installed" # Name of the package
version?: string # Version of the package or latest
version?: string@"complete asdf plugin versions installed" # Version of the package or latest
]
# Set the package to version in the current shell
export extern "asdf shell" [
name: string@"complete asdf installed" # Name of the package
version?: string # Version of the package or latest
version?: string@"complete asdf plugin versions installed" # Version of the package or latest
]
# Show latest stable version of a package
export extern "asdf latest" [
name: string # Name of the package
version?: string # Filter latest stable version from this version
name: string@"complete asdf installed" # Name of the package
version?: string@"complete asdf plugin versions installed" # Filter latest stable version from this version
]
# Show latest stable version for all installed packages
@ -202,13 +226,13 @@ module asdf {
# List installed package versions
export extern "asdf list" [
name?: string@"complete asdf installed" # Name of the package
version?: string # Filter the version
version?: string@"complete asdf plugin versions installed" # Filter the version
]
# List all available package versions
export def "asdf list all" [
name: string@"complete asdf installed" # Name of the package
version?: string="" # Filter the version
version?: string@"complete asdf plugin versions installed"="" # Filter the version
] {
^asdf list all $name $version | lines | parse "{version}" | str trim
}
@ -216,7 +240,7 @@ module asdf {
# Show documentation for plugin
export extern "asdf help" [
name: string@"complete asdf installed" # Name of the plugin
version?: string # Version of the plugin
version?: string@"complete asdf plugin versions installed" # Version of the plugin
]
# Execute a command shim for the current version
@ -237,7 +261,7 @@ module asdf {
# Recreate shims for version package
export extern "asdf reshim" [
name?: string@"complete asdf installed" # Name of the package
version?: string # Version of the package
version?: string@"complete asdf plugin versions installed" # Version of the package
]
# List the plugins and versions that provide a command

View File

@ -56,7 +56,8 @@ _asdf() {
uninstall | where | reshim)
if [[ " $plugins " == *" $prev "* ]]; then
local versions
versions=$(asdf list "$prev" 2>/dev/null)
# The first two columns are either blank or contain the "current" marker.
versions=$(asdf list "$prev" 2>/dev/null | colrm 1 2)
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
else
@ -67,7 +68,8 @@ _asdf() {
local | global | shell)
if [[ " $plugins " == *" $prev "* ]]; then
local versions
versions=$(asdf list "$prev" 2>/dev/null)
# The first two columns are either blank or contain the "current" marker.
versions=$(asdf list "$prev" 2>/dev/null | colrm 1 2)
versions+=" system"
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "$versions" -- "$cur"))

View File

@ -364,7 +364,7 @@ export ASDF_DIR="/opt/asdf-vm"
`asdf` scripts need to be sourced **after** you have set your `$PATH` and **after** you have sourced your framework (oh-my-zsh etc).
::: warning
On macOS, starting a Bash or Zsh shell automatically calls a utility called `path_helper`. `path_helper` can rearrange items in `PATH` (and `MANPATH`), causing inconsistent behavior for tools that require specific ordering. To workaround this, `asdf` on macOS defaults to forcily adding its `PATH`-entries to the front (taking highest priority). This is controllable with the `ASDF_FORCE_PREPEND` variable.
On macOS, starting a Bash or Zsh shell automatically calls a utility called `path_helper`. `path_helper` can rearrange items in `PATH` (and `MANPATH`), causing inconsistent behavior for tools that require specific ordering. To workaround this, `asdf` on macOS defaults to forcibly adding its `PATH`-entries to the front (taking highest priority). This is controllable with the `ASDF_FORCE_PREPEND` variable.
:::
Restart your shell so that `PATH` changes take effect. Opening a new terminal tab will usually do it.

View File

@ -80,7 +80,7 @@ asdf local <name> latest[:<version>]
`global` writes the version to `$HOME/.tool-versions`.
`shell` set the version to an environment variable named `ASDF_${TOOL}_VERSION`, for the current shell session only.
`shell` sets the version to an environment variable named `ASDF_${TOOL}_VERSION`, for the current shell session only.
`local` writes the version to `$PWD/.tool-versions`, creating it if needed.

View File

@ -78,7 +78,7 @@ write_shim_script() {
local version=$2
local executable_path=$3
if ! is_executable "$executable_path"; then
if ! is_executable "$executable_path" && ! is_executable "$executable_path.exe"; then
return 0
fi
@ -107,6 +107,32 @@ $(sort -u <"$temp_versions_path")
exec $(asdf_dir)/bin/asdf exec "${executable_name}" "\$@" # asdf_allow: ' asdf '
EOF
if [ "$OSTYPE" == "msys" ] || [ "$OSTYPE" == "win32" ]; then
cat <<EOF >"$shim_path.bat"
@ECHO OFF
$(sort -u <"$temp_versions_path" | sed -En "s/# /REM /p")
IF "%1"=="" (
GOTO NO_ARGS
) ELSE (
GOTO ARGS_EXIST
)
:NO_ARGS
bash "$HOME/.asdf/shims/${executable_name}"
GOTO EXIT
:ARGS_EXIST
SET ARGUMENTS=%*
SET ARGUMENTS=%ARGUMENTS:\\=\\\\%
bash "$HOME/.asdf/shims/${executable_name}" %ARGUMENTS%
GOTO EXIT
:EXIT
EOF
fi
rm "$temp_versions_path"
chmod +x "$shim_path"

View File

@ -243,7 +243,7 @@ install_tool_version() {
fi
# Otherwise, remove the download directory if it exists
elif [ -d "$download_path" ]; then
rm -r "$download_path"
rm -rf "$download_path"
fi
reshim_command "$plugin_name" "$full_version"

View File

@ -618,6 +618,9 @@ plugin_executables() {
for bin_path in "${all_bin_paths[@]}"; do
for executable_file in "$bin_path"/*; do
if is_executable "$executable_file"; then
if [[ "$executable_file" == *".exe" ]]; then
executable_file=${executable_file::-4}
fi
printf "%s\n" "$executable_file"
fi
done

View File

@ -3,6 +3,11 @@ setup_suite() {
# tests fail when it is set to something other than the temp dir.
unset ASDF_DIR
# Also unset below variables, because in users shell shimmed commands
# (include bats) export them by determining user's real HOME.
unset ASDF_DATA_DIR
unset ASDF_CONFIG_FILE
# Set an agnostic Git configuration directory to prevent personal
# configuration from interfering with the tests
export GIT_CONFIG_GLOBAL=/dev/null