mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Merge pull request #664 from asdf-vm/tb/file-extensions
Add .bash file extension to files executed by Bash
This commit is contained in:
commit
7cdfc0fa2a
20
bin/asdf
20
bin/asdf
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck source=lib/utils.sh
|
||||
source "$(dirname "$(dirname "$0")")/lib/utils.sh"
|
||||
# shellcheck source=lib/utils.bash
|
||||
source "$(dirname "$(dirname "$0")")/lib/utils.bash"
|
||||
|
||||
find_cmd() {
|
||||
local cmd_dir="$1"
|
||||
@ -9,16 +9,16 @@ find_cmd() {
|
||||
|
||||
local cmd_name
|
||||
local args_offset="$#"
|
||||
cmd_name="command-$(echo "${@:1:${args_offset}}" | tr ' ' '-')"
|
||||
cmd_name="command-$(echo "${@:1:${args_offset}}" | tr ' ' '-').bash"
|
||||
while [ ! -f "$cmd_dir/$cmd_name" ] && [ "$args_offset" -gt 0 ]; do
|
||||
args_offset=$((args_offset - 1))
|
||||
cmd_name="command-$(echo "${@:1:${args_offset}}" | tr ' ' '-')"
|
||||
cmd_name="command-$(echo "${@:1:${args_offset}}" | tr ' ' '-').bash"
|
||||
done
|
||||
|
||||
if [ -f "$cmd_dir/$cmd_name" ]; then
|
||||
echo "$cmd_dir/$cmd_name" "$((args_offset + 1))"
|
||||
elif [ -f "$cmd_dir/command" ]; then
|
||||
echo "$cmd_dir/command" 1
|
||||
elif [ -f "$cmd_dir/command.bash" ]; then
|
||||
echo "$cmd_dir/command.bash" 1
|
||||
fi
|
||||
}
|
||||
|
||||
@ -29,15 +29,15 @@ find_asdf_cmd() {
|
||||
'exec' | 'current' | 'env' | 'global' | 'install' | 'latest' | 'local' | \
|
||||
'reshim' | 'uninstall' | 'update' | 'where' | 'which' | \
|
||||
'export-shell-version')
|
||||
echo "$asdf_cmd_dir/command-$1" 2
|
||||
echo "$asdf_cmd_dir/command-$1.bash" 2
|
||||
;;
|
||||
|
||||
'' | '--help' | '-h' | 'help')
|
||||
echo "$asdf_cmd_dir/command-help" 2
|
||||
echo "$asdf_cmd_dir/command-help.bash" 2
|
||||
;;
|
||||
|
||||
'--version' | 'version')
|
||||
echo "$asdf_cmd_dir/command-version" 2
|
||||
echo "$asdf_cmd_dir/command-version.bash" 2
|
||||
;;
|
||||
|
||||
*)
|
||||
@ -79,7 +79,7 @@ asdf_cmd() {
|
||||
local asdf_cmd_dir
|
||||
asdf_cmd_dir="$(asdf_dir)/lib/commands"
|
||||
echo "Unknown command: \`asdf ${*}\`" >&2
|
||||
source "$asdf_cmd_dir/command-help" >&2
|
||||
source "$asdf_cmd_dir/command-help.bash" >&2
|
||||
return 127
|
||||
fi
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
echo "asdf is self upgrading shims to new asdf exec ..."
|
||||
|
||||
asdf_dir="$(dirname "$(dirname "$(dirname "$0")")")"
|
||||
# shellcheck source=lib/utils.sh
|
||||
source "$asdf_dir/lib/utils.sh"
|
||||
# shellcheck source=lib/utils.bash
|
||||
source "$asdf_dir/lib/utils.bash"
|
||||
rm "$(asdf_data_dir)"/shims/*
|
||||
"$asdf_dir"/bin/asdf reshim
|
||||
shim_name=$(basename "$2")
|
||||
|
@ -35,7 +35,7 @@ This script should install the version, in the path mentioned in `ASDF_INSTALL_P
|
||||
|
||||
The install script should exit with a status of `0` when the installation is successful. If the installation fails the script should exit with any non-zero exit status.
|
||||
|
||||
If possible the script should only place files in the `ASDF_INSTALL_PATH` directory once the build and installation of the tool is deemed successful by the install script. asdf [checks for the existence](https://github.com/asdf-vm/asdf/blob/242d132afbf710fe3c7ec23c68cec7bdd2c78ab5/lib/utils.sh#L44) of the `ASDF_INSTALL_PATH` directory in order to determine if that version of the tool is installed. If the `ASDF_INSTALL_PATH` directory is populated at the beginning of the installation process other asdf commands run in other terminals during the installation may consider that version of the tool installed, even when it is not fully installed.
|
||||
If possible the script should only place files in the `ASDF_INSTALL_PATH` directory once the build and installation of the tool is deemed successful by the install script. asdf [checks for the existence](https://github.com/asdf-vm/asdf/blob/242d132afbf710fe3c7ec23c68cec7bdd2c78ab5/lib/utils.bash#L44) of the `ASDF_INSTALL_PATH` directory in order to determine if that version of the tool is installed. If the `ASDF_INSTALL_PATH` directory is populated at the beginning of the installation process other asdf commands run in other terminals during the installation may consider that version of the tool installed, even when it is not fully installed.
|
||||
|
||||
## Optional Scripts
|
||||
|
||||
@ -90,18 +90,18 @@ This can be used to further parse the legacy file found by asdf. If `parse-legac
|
||||
|
||||
## Extension commands for asdf CLI.
|
||||
|
||||
It's possible for plugins to define new asdf commands by providing `bin/command*` scripts or executables that will
|
||||
be callable using the asdf command line interface by using the plugin name as a subcommand.
|
||||
It's possible for plugins to define new asdf commands by providing `bin/command*.bash` scripts or executables that
|
||||
will be callable using the asdf command line interface by using the plugin name as a subcommand.
|
||||
|
||||
For example, suppose a `foo` plugin has:
|
||||
|
||||
```shell
|
||||
foo/
|
||||
bin/
|
||||
command
|
||||
command-bat
|
||||
command-bat-man
|
||||
command-help
|
||||
command.bash
|
||||
command-bat.bash
|
||||
command-bat-man.bash
|
||||
command-help.bash
|
||||
```
|
||||
|
||||
Users can now execute
|
||||
@ -118,7 +118,7 @@ Plugin authors can use this feature to provide utilities related to their tools,
|
||||
or even create plugins that are just new command extensions for asdf itself.
|
||||
|
||||
When `command*` files exists but have no executable bit set, they are considered to be
|
||||
bash scripts and will be sourced having all the functions from `$ASDF_DIR/lib/utils.sh`
|
||||
bash scripts and will be sourced having all the functions from `$ASDF_DIR/lib/utils.bash`
|
||||
available. Also, the `$ASDF_CMD_FILE` resolves to the full path of the file being sourced.
|
||||
If the executable bit is set, they are just executed and replace the asdf execution.
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
# -*- sh -*-
|
||||
|
||||
# shellcheck source=lib/commands/version_commands.sh
|
||||
source "$(dirname "$ASDF_CMD_FILE")/version_commands.sh"
|
||||
version_command global "$@"
|
5
lib/commands/command-global.bash
Normal file
5
lib/commands/command-global.bash
Normal file
@ -0,0 +1,5 @@
|
||||
# -*- sh -*-
|
||||
|
||||
# shellcheck source=lib/commands/version_commands.bash
|
||||
source "$(dirname "$ASDF_CMD_FILE")/version_commands.bash"
|
||||
version_command global "$@"
|
@ -1,7 +1,7 @@
|
||||
# -*- sh -*-
|
||||
|
||||
# shellcheck source=lib/commands/version_commands.sh
|
||||
source "$(dirname "$ASDF_CMD_FILE")/version_commands.sh"
|
||||
# shellcheck source=lib/commands/version_commands.bash
|
||||
source "$(dirname "$ASDF_CMD_FILE")/version_commands.bash"
|
||||
|
||||
local_command() {
|
||||
local parent=false
|
@ -1,7 +1,7 @@
|
||||
# -*- sh -*-
|
||||
|
||||
# shellcheck source=lib/commands/reshim.sh
|
||||
source "$(dirname "$ASDF_CMD_FILE")/reshim.sh"
|
||||
# shellcheck source=lib/commands/reshim.bash
|
||||
source "$(dirname "$ASDF_CMD_FILE")/reshim.bash"
|
||||
|
||||
reshim_command() {
|
||||
local plugin_name=$1
|
@ -1,7 +1,7 @@
|
||||
# -*- sh -*-
|
||||
|
||||
# shellcheck source=lib/commands/reshim.sh
|
||||
source "$(dirname "$ASDF_CMD_FILE")/reshim.sh"
|
||||
# shellcheck source=lib/commands/reshim.bash
|
||||
source "$(dirname "$ASDF_CMD_FILE")/reshim.bash"
|
||||
|
||||
uninstall_command() {
|
||||
local plugin_name=$1
|
@ -630,7 +630,7 @@ get_shim_versions() {
|
||||
|
||||
preset_versions() {
|
||||
shim_name=$1
|
||||
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c "source $(asdf_dir)/lib/utils.sh; echo PLUGIN \$(get_preset_version_for PLUGIN)"
|
||||
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c "source $(asdf_dir)/lib/utils.bash; echo PLUGIN \$(get_preset_version_for PLUGIN)"
|
||||
}
|
||||
|
||||
select_from_preset_version() {
|
2
lint.sh
2
lint.sh
@ -2,7 +2,7 @@
|
||||
exec shellcheck -s bash -x \
|
||||
asdf.sh lint.sh release/tag.sh \
|
||||
bin/asdf bin/private/asdf-exec \
|
||||
lib/utils.sh lib/commands/* \
|
||||
lib/utils.bash lib/commands/*.bash \
|
||||
completions/*.bash \
|
||||
test/test_helpers.bash \
|
||||
test/fixtures/dummy_plugin/bin/*
|
||||
|
@ -15,11 +15,11 @@ teardown() {
|
||||
plugin_path="$(get_plugin_path dummy)"
|
||||
|
||||
# this plugin defines a new `asdf dummy foo` command
|
||||
cat <<'EOF' > "$plugin_path/bin/command-foo"
|
||||
cat <<'EOF' > "$plugin_path/bin/command-foo.bash"
|
||||
#!/usr/bin/env bash
|
||||
echo this is an executable $*
|
||||
EOF
|
||||
chmod +x "$plugin_path/bin/command-foo"
|
||||
chmod +x "$plugin_path/bin/command-foo.bash"
|
||||
|
||||
expected="this is an executable bar"
|
||||
|
||||
@ -32,7 +32,7 @@ EOF
|
||||
plugin_path="$(get_plugin_path dummy)"
|
||||
|
||||
# this plugin defines a new `asdf dummy foo` command
|
||||
echo 'echo sourced script has asdf utils $(get_plugin_path dummy) $*' > "$plugin_path/bin/command-foo"
|
||||
echo 'echo sourced script has asdf utils $(get_plugin_path dummy) $*' > "$plugin_path/bin/command-foo.bash"
|
||||
|
||||
expected="sourced script has asdf utils $plugin_path bar"
|
||||
|
||||
@ -45,11 +45,11 @@ EOF
|
||||
plugin_path="$(get_plugin_path dummy)"
|
||||
|
||||
# this plugin defines a new `asdf dummy` command
|
||||
cat <<'EOF' > "$plugin_path/bin/command"
|
||||
cat <<'EOF' > "$plugin_path/bin/command.bash"
|
||||
#!/usr/bin/env bash
|
||||
echo hello
|
||||
EOF
|
||||
chmod +x "$plugin_path/bin/command"
|
||||
chmod +x "$plugin_path/bin/command.bash"
|
||||
|
||||
expected="hello"
|
||||
|
||||
@ -62,11 +62,11 @@ EOF
|
||||
plugin_path="$(get_plugin_path dummy)"
|
||||
|
||||
# this plugin defines a new `asdf dummy` command
|
||||
cat <<'EOF' > "$plugin_path/bin/command"
|
||||
cat <<'EOF' > "$plugin_path/bin/command.bash"
|
||||
#!/usr/bin/env bash
|
||||
echo hello $*
|
||||
EOF
|
||||
chmod +x "$plugin_path/bin/command"
|
||||
chmod +x "$plugin_path/bin/command.bash"
|
||||
|
||||
expected="hello world"
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
# tests fail when it is set to something other than the temp dir.
|
||||
unset ASDF_DIR
|
||||
|
||||
# shellcheck source=lib/utils.sh
|
||||
. "$(dirname "$BATS_TEST_DIRNAME")"/lib/utils.sh
|
||||
# shellcheck source=lib/utils.bash
|
||||
. "$(dirname "$BATS_TEST_DIRNAME")"/lib/utils.bash
|
||||
|
||||
setup_asdf_dir() {
|
||||
BASE_DIR=$(mktemp -dt asdf.XXXX)
|
||||
|
Loading…
Reference in New Issue
Block a user