diff --git a/asdf.nu b/asdf.nu index 909402014..57cf00b13 100644 --- a/asdf.nu +++ b/asdf.nu @@ -1,14 +1,27 @@ def-env configure-asdf [] { - - $env.ASDF_DIR = ( if ( $env | get --ignore-errors ASDF_DIR | is-empty ) { $env.ASDF_NU_DIR } else { $env.ASDF_DIR } ) - - let shims_dir = ( if ( $env | get --ignore-errors ASDF_DATA_DIR | is-empty ) { $env.HOME | path join '.asdf' } else { $env.ASDF_DIR } | path join 'shims' ) - + $env.ASDF_DIR = ( + if ($env | get --ignore-errors ASDF_NU_DIR | is-empty) == false { + $env.ASDF_NU_DIR + } + else if ($env | get --ignore-errors ASDF_DIR | is-empty) == false { + $env.ASDF_DIR + } else { + print --stderr "asdf: Either ASDF_NU_DIR or ASDF_DIR must not be empty" + return + } + ) + + let shims_dir = ( + if ( $env | get --ignore-errors ASDF_DATA_DIR | is-empty ) { + $env.HOME | path join '.asdf' + } else { + $env.ASDF_DIR + } | path join 'shims' + ) let asdf_bin_dir = ( $env.ASDF_DIR | path join 'bin' ) $env.PATH = ( $env.PATH | split row (char esep) | where { |p| $p != $shims_dir } | prepend $shims_dir ) $env.PATH = ( $env.PATH | split row (char esep) | where { |p| $p != $asdf_bin_dir } | prepend $asdf_bin_dir ) - } configure-asdf diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index de5326a5d..9f15532fb 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -300,7 +300,7 @@ Add the following to `~/.config/powershell/profile.ps1`: Add `asdf.nu` to your `~/.config/nushell/config.nu` with: ```shell -"\n$env.ASDF_NU_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path +"\n$env.ASDF_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path ``` Completions are automatically configured @@ -311,7 +311,7 @@ Completions are automatically configured Add `asdf.nu` to your `~/.config/nushell/config.nu` with: ```shell -"\n$env.ASDF_NU_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\n source " + (brew --prefix asdf | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path +"\n$env.ASDF_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\n source " + (brew --prefix asdf | str trim | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path ``` Completions are automatically configured @@ -322,7 +322,7 @@ Completions are automatically configured Add `asdf.nu` to your `~/.config/nushell/config.nu` with: ```shell -"\n$env.ASDF_NU_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path +"\n$env.ASDF_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path ``` Completions are automatically configured. diff --git a/docs/pt-br/guide/getting-started.md b/docs/pt-br/guide/getting-started.md index c1462fb38..3f5b809c1 100644 --- a/docs/pt-br/guide/getting-started.md +++ b/docs/pt-br/guide/getting-started.md @@ -297,7 +297,7 @@ Adicione a seguinte linha ao seu `~/.config/powershell/profile.ps1`: Adicione `asdf.nu` ao seu `~/.config/nushell/config.nu` através do comando: ```shell -"\n$env.ASDF_NU_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path +"\n$env.ASDF_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path ``` Ao concluir atualizará automaticamente @@ -308,7 +308,7 @@ Ao concluir atualizará automaticamente Adicione `asdf.nu` ao seu `~/.config/nushell/config.nu` através do comando: ```shell -"\n$env.ASDF_NU_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\n source " + (brew --prefix asdf | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path +"\n$env.ASDF_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\n source " + (brew --prefix asdf | str trim | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path ``` Ao concluir atualizará automaticamente @@ -319,7 +319,7 @@ Ao concluir atualizará automaticamente Adicione `asdf.nu` ao seu `~/.config/nushell/config.nu` através do comando: ```shell -"\n$env.ASDF_NU_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path +"\n$env.ASDF_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path ``` Ao concluir atualizará automaticamente diff --git a/docs/zh-hans/guide/getting-started.md b/docs/zh-hans/guide/getting-started.md index 7704db849..3747ef2f5 100644 --- a/docs/zh-hans/guide/getting-started.md +++ b/docs/zh-hans/guide/getting-started.md @@ -298,7 +298,7 @@ echo -e "\n. \"$(brew --prefix asdf)/libexec/asdf.ps1\"" >> ~/.config/powershell 使用以下命令将 `asdf.nu` 加入到 `~/.config/nushell/config.nu` 文件中: ```shell -"\n$env.ASDF_NU_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path +"\n$env.ASDF_DIR = ($env.HOME | path join '.asdf')\n source " + ($env.HOME | path join '.asdf/asdf.nu') | save --append $nu.config-path ``` 补全功能将会自动配置。 @@ -309,7 +309,7 @@ echo -e "\n. \"$(brew --prefix asdf)/libexec/asdf.ps1\"" >> ~/.config/powershell 使用以下命令将 `asdf.nu` 加入到 `~/.config/nushell/config.nu` 文件中: ```shell -"\n$env.ASDF_NU_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\n source " + (brew --prefix asdf | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path +"\n$env.ASDF_DIR = (brew --prefix asdf | str trim | into string | path join 'libexec')\n source " + (brew --prefix asdf | str trim | into string | path join 'libexec/asdf.nu') | save --append $nu.config-path ``` 补全功能将会自动配置。 @@ -320,7 +320,7 @@ echo -e "\n. \"$(brew --prefix asdf)/libexec/asdf.ps1\"" >> ~/.config/powershell 使用以下命令将 `asdf.nu` 加入到 `~/.config/nushell/config.nu` 文件中: ```shell -"\n$env.ASDF_NU_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path +"\n$env.ASDF_DIR = '/opt/asdf-vm/'\n source /opt/asdf-vm/asdf.nu" | save --append $nu.config-path ``` 补全功能将会自动配置。 diff --git a/lib/commands/command-plugin-test.bash b/lib/commands/command-plugin-test.bash index 826ac3f75..0cfa680ed 100644 --- a/lib/commands/command-plugin-test.bash +++ b/lib/commands/command-plugin-test.bash @@ -84,7 +84,7 @@ plugin_test_command() { fi # shellcheck disable=SC2119 - if ! (plugin_list_command | grep "^$plugin_name$" >/dev/null); then + if ! (plugin_list_command | grep -q "^$plugin_name$"); then fail_test "$plugin_name was not properly installed" fi @@ -95,8 +95,8 @@ plugin_test_command() { local plugin_path plugin_path=$(get_plugin_path "$plugin_name") local list_all="$plugin_path/bin/list-all" - if grep api.github.com "$list_all" >/dev/null; then - if ! grep Authorization "$list_all" >/dev/null; then + if grep -q api.github.com "$list_all"; then + if ! grep -q Authorization "$list_all"; then printf "\nLooks like %s/bin/list-all relies on GitHub releases\n" "$plugin_name" printf "but it does not properly sets an Authorization header to prevent\n" printf "GitHub API rate limiting.\n\n" diff --git a/lib/commands/reshim.bash b/lib/commands/reshim.bash index 82bed60fb..2317973a1 100644 --- a/lib/commands/reshim.bash +++ b/lib/commands/reshim.bash @@ -18,7 +18,7 @@ remove_shim_for_version() { sed -i.bak -e "/# asdf-plugin: $plugin_name $version"'$/d' "$shim_path" rm "$shim_path".bak - if ! grep "# asdf-plugin:" "$shim_path" >/dev/null || + if ! grep -q "# asdf-plugin:" "$shim_path" || [ "$count_installed" -eq 0 ]; then rm -f "$shim_path" fi diff --git a/lib/functions/versions.bash b/lib/functions/versions.bash index 4b7cc34bc..7d1d941d6 100644 --- a/lib/functions/versions.bash +++ b/lib/functions/versions.bash @@ -60,7 +60,7 @@ version_command() { resolved_versions+=("$version") done - if [ -f "$file" ] && grep "^$plugin_name " "$file" >/dev/null; then + if [ -f "$file" ] && grep -q "^$plugin_name " "$file"; then local temp_dir temp_dir=${TMPDIR:-/tmp} diff --git a/scripts/install_dependencies.bash b/scripts/install_dependencies.bash index 8965077d7..02baad752 100755 --- a/scripts/install_dependencies.bash +++ b/scripts/install_dependencies.bash @@ -22,7 +22,7 @@ fi # Elvish elvish_semver="v0.19.2" # Fish -fish_semver="3.6.1" +fish_semver="3.7.0" fish_apt_semver="${fish_semver}-1~jammy" # Nushell nushell_semver="0.84.0" diff --git a/test/asdf_nu.bats b/test/asdf_nu.bats index f46d6a669..729def500 100644 --- a/test/asdf_nu.bats +++ b/test/asdf_nu.bats @@ -26,7 +26,7 @@ run_nushell() { hide-env -i asdf hide-env -i ASDF_DIR \$env.PATH = ( '$(cleaned_path)' | split row ':' ) - \$env.ASDF_NU_DIR = '$PWD' + \$env.ASDF_DIR = '$PWD' source asdf.nu $1" @@ -60,7 +60,7 @@ run_nushell() { [ "$result" = "" ] } -@test "retains ASDF_DIR" { +@test "retains ASDF_DIR (from ASDF_NU_DIR)" { run nu -c " hide-env -i asdf \$env.ASDF_DIR = ( pwd ) @@ -75,6 +75,21 @@ run_nushell() { [ "$output" = "$PWD" ] } +@test "retains ASDF_DIR (from ASDF_DIR)" { + run nu -c " + hide-env -i asdf + \$env.ASDF_DIR = ( pwd ) + \$env.PATH = ( '$(cleaned_path)' | split row ':' ) + \$env.ASDF_DIR = '$PWD' + + source asdf.nu + + echo \$env.ASDF_DIR" + + [ "$status" -eq 0 ] + [ "$output" = "$PWD" ] +} + @test "defines the asdf or main function" { run_nushell "which asdf | get path | to text"