mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
fix!: align Fish entrypoint behaviour with other shells (#1524)
This commit is contained in:
parent
b6d0ca28d5
commit
8919f4009e
@ -9,3 +9,6 @@ insert_final_newline = true
|
||||
|
||||
[*.py]
|
||||
indent_size = 4
|
||||
|
||||
[*.fish]
|
||||
indent_size = 4
|
||||
|
6
.github/workflows/lint.yml
vendored
6
.github/workflows/lint.yml
vendored
@ -25,6 +25,12 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Fish (for fish_indent)
|
||||
run: |
|
||||
sudo add-apt-repository -y ppa:fish-shell/nightly-master
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install fish
|
||||
|
||||
- name: Install asdf dependencies
|
||||
uses: asdf-vm/actions/install@v2
|
||||
|
||||
|
48
asdf.fish
48
asdf.fish
@ -1,38 +1,24 @@
|
||||
if not set -q ASDF_DIR
|
||||
set -x ASDF_DIR (dirname (status -f))
|
||||
if test -z $ASDF_DIR
|
||||
set ASDF_DIR (realpath (dirname (status filename)))
|
||||
end
|
||||
set --export ASDF_DIR $ASDF_DIR
|
||||
|
||||
set -l _asdf_bin "$ASDF_DIR/bin"
|
||||
if test -z $ASDF_DATA_DIR
|
||||
set _asdf_shims "$HOME/.asdf/shims"
|
||||
else
|
||||
set _asdf_shims "$ASDF_DATA_DIR/shims"
|
||||
end
|
||||
|
||||
# Add asdf to PATH
|
||||
# fish_add_path was added in fish 3.2, so we need a fallback for older version
|
||||
if type -q fish_add_path
|
||||
if test -n "$ASDF_DATA_DIR"
|
||||
fish_add_path --global --move "$ASDF_DATA_DIR/shims" "$ASDF_DIR/bin"
|
||||
else
|
||||
fish_add_path --global --move "$HOME/.asdf/shims" "$ASDF_DIR/bin"
|
||||
end
|
||||
else
|
||||
set -l asdf_user_shims (
|
||||
if test -n "$ASDF_DATA_DIR"
|
||||
printf "%s\n" "$ASDF_DATA_DIR/shims"
|
||||
else
|
||||
printf "%s\n" "$HOME/.asdf/shims"
|
||||
end
|
||||
)
|
||||
|
||||
set -l asdf_bin_dirs $ASDF_DIR/bin $asdf_user_shims
|
||||
|
||||
for x in $asdf_bin_dirs
|
||||
if test -d $x
|
||||
for i in (seq 1 (count $PATH))
|
||||
if test $PATH[$i] = $x
|
||||
set -e PATH[$i]
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
set PATH $x $PATH
|
||||
# Do not use fish_add_path (added in Fish 3.2) because it
|
||||
# potentially changes the order of items in fish_user_paths
|
||||
if not contains $_asdf_bin $fish_user_paths
|
||||
set --global --prepend fish_user_paths $_asdf_bin
|
||||
end
|
||||
if not contains $_asdf_shims $fish_user_paths
|
||||
set --global --prepend fish_user_paths $_asdf_shims
|
||||
end
|
||||
set --erase _asdf_bin _asdf_shims
|
||||
|
||||
# Load the asdf wrapper function
|
||||
. $ASDF_DIR/lib/asdf.fish
|
||||
|
@ -51,87 +51,87 @@ function __fish_asdf_list_shims
|
||||
end
|
||||
|
||||
# update
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a update -d "Update asdf"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command update; and __fish_asdf_arg_number 2' -l "head" -d "Updates to master HEAD"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a update -d "Update asdf"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command update; and __fish_asdf_arg_number 2' -l head -d "Updates to master HEAD"
|
||||
|
||||
# plugin-add completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-add -d "Add git repo as plugin"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-add -d "Add git repo as plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list_all | grep -v \'*\' | awk \'{ print $1 }\')'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 3' -a '(__fish_asdf_plugin_list_all | grep (__fish_asdf_arg_at 3) | awk \'{ print $2 }\')'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-add; and __fish_asdf_arg_number 4'
|
||||
|
||||
# plugin-list completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list -d "List installed plugins"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-list -d "List installed plugins"
|
||||
|
||||
# plugin-list-all completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-list-all -d "List all existing plugins"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-list-all -d "List all existing plugins"
|
||||
|
||||
# plugin-remove completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-remove -d "Remove plugin and package versions"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-remove -d "Remove plugin and package versions"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-remove; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
|
||||
# plugin-update completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a plugin-update -d "Update plugin"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a plugin-update -d "Update plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command plugin-update; and __fish_asdf_arg_number 2' -a --all
|
||||
|
||||
# install completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a install -d "Install a specific version of a package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a install -d "Install a specific version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command install; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_all (__fish_asdf_arg_at 3))'
|
||||
|
||||
# uninstall completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a uninstall -d "Remove a specific version of a package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a uninstall -d "Remove a specific version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command uninstall; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
|
||||
|
||||
# current completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a current -d "Display version set or being used for package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a current -d "Display version set or being used for package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command current; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
|
||||
# where completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a where -d "Display install path for an installed version"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a where -d "Display install path for an installed version"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command where; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
|
||||
|
||||
# which completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a which -d "Display executable path for a command"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a which -d "Display executable path for a command"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command which; and __fish_asdf_arg_number 2' -a '(__fish_asdf_list_shims)'
|
||||
|
||||
# latest completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a latest -d "Show latest stable version of a package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a latest -d "Show latest stable version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command latest; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command latest; and __fish_asdf_arg_number 2' -a --all
|
||||
|
||||
# list completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a list -d "List installed versions of a package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a list -d "List installed versions of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command list; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
|
||||
# list-all completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a list-all -d "List all versions of a package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a list-all -d "List all versions of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command list-all; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
|
||||
# reshim completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a reshim -d "Recreate shims for version of a package"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a reshim -d "Recreate shims for version of a package"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command reshim; and __fish_asdf_arg_number 3' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3))'
|
||||
|
||||
# local completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a local -d "Set local version for a plugin"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a local -d "Set local version for a plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command local; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command local; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
|
||||
|
||||
# global completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a global -d "Set global version for a plugin"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a global -d "Set global version for a plugin"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command global; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command global; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
|
||||
|
||||
# shell completion
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a shell -d "Set version for a plugin in current shell session"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a shell -d "Set version for a plugin in current shell session"
|
||||
complete -f -c asdf -n '__fish_asdf_using_command shell; and __fish_asdf_arg_number 2' -a '(__fish_asdf_plugin_list)'
|
||||
complete -f -c asdf -n '__fish_asdf_using_command shell; and test (count (commandline -opc)) -gt 2' -a '(__fish_asdf_list_versions (__fish_asdf_arg_at 3)) system'
|
||||
|
||||
# misc
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -l "help" -d "Displays help"
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -a "info" -d "Print OS, Shell and ASDF debug information"
|
||||
complete -f -c asdf -n '__fish_asdf_needs_command' -l "version" -d "Displays asdf version"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -l help -d "Displays help"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -a info -d "Print OS, Shell and ASDF debug information"
|
||||
complete -f -c asdf -n __fish_asdf_needs_command -l version -d "Displays asdf version"
|
||||
|
@ -1,15 +1,14 @@
|
||||
|
||||
# Add function wrapper so we can export variables
|
||||
# The asdf function is a wrapper so we can export variables
|
||||
function asdf
|
||||
set command $argv[1]
|
||||
set -e argv[1]
|
||||
|
||||
switch "$command"
|
||||
case "shell"
|
||||
# source commands that need to export variables
|
||||
case shell
|
||||
# Source commands that need to export variables.
|
||||
command asdf export-shell-version fish $argv | source # asdf_allow: source
|
||||
case '*'
|
||||
# forward other commands to asdf script
|
||||
# Forward other commands to asdf script.
|
||||
command asdf "$command" $argv
|
||||
end
|
||||
end
|
||||
|
@ -23,3 +23,6 @@ shfmt --language-dialect bash --indent 2 --write \
|
||||
# check .bats files
|
||||
shfmt --language-dialect bats --indent 2 --write \
|
||||
test/*.bats
|
||||
|
||||
# check .fish files
|
||||
fish_indent --write ./**/*.fish
|
||||
|
@ -23,3 +23,6 @@ shfmt --language-dialect bash --indent 2 --diff \
|
||||
# check .bats files
|
||||
shfmt --language-dialect bats --indent 2 --diff \
|
||||
test/*.bats
|
||||
|
||||
# check .fish files
|
||||
fish_indent --check ./**/*.fish
|
||||
|
Loading…
Reference in New Issue
Block a user