Skip to content

Commit b076fe8

Browse files
authored
Merge pull request asdf-vm#223 from CoffeeAndCode/shellcheck
Shellcheck
2 parents 14d7ef5 + 85550c8 commit b076fe8

30 files changed

Lines changed: 421 additions & 292 deletions

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
language: c
2-
script: bats test
2+
3+
script:
4+
- bats test
5+
- ./lint.sh
6+
7+
before_install:
8+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
9+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install shellcheck; fi
10+
311
before_script:
412
- git clone https://github.com/sstephenson/bats.git /tmp/bats
513
- export PATH=/tmp/bats/bin:$PATH
14+
615
os:
716
- linux
817
- osx

bin/asdf

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,54 @@
11
#!/usr/bin/env bash
22

3-
source $(dirname $(dirname $0))/lib/utils.sh
4-
5-
source $(dirname $(dirname $0))/lib/commands/help.sh
6-
source $(dirname $(dirname $0))/lib/commands/update.sh
7-
source $(dirname $(dirname $0))/lib/commands/install.sh
8-
source $(dirname $(dirname $0))/lib/commands/uninstall.sh
9-
source $(dirname $(dirname $0))/lib/commands/current.sh
10-
source $(dirname $(dirname $0))/lib/commands/where.sh
11-
source $(dirname $(dirname $0))/lib/commands/which.sh
12-
source $(dirname $(dirname $0))/lib/commands/version_commands.sh
13-
source $(dirname $(dirname $0))/lib/commands/list.sh
14-
source $(dirname $(dirname $0))/lib/commands/list-all.sh
15-
source $(dirname $(dirname $0))/lib/commands/reshim.sh
16-
source $(dirname $(dirname $0))/lib/commands/plugin-add.sh
17-
source $(dirname $(dirname $0))/lib/commands/plugin-list.sh
18-
source $(dirname $(dirname $0))/lib/commands/plugin-list-all.sh
19-
source $(dirname $(dirname $0))/lib/commands/plugin-update.sh
20-
source $(dirname $(dirname $0))/lib/commands/plugin-remove.sh
21-
22-
source $(dirname $(dirname $0))/lib/commands/plugin-push.sh
23-
source $(dirname $(dirname $0))/lib/commands/plugin-test.sh
24-
25-
3+
# shellcheck source=lib/utils.sh
4+
source "$(dirname "$(dirname "$0")")/lib/utils.sh"
5+
6+
# shellcheck source=lib/commands/help.sh
7+
source "$(dirname "$(dirname "$0")")/lib/commands/help.sh"
8+
# shellcheck source=lib/commands/update.sh
9+
source "$(dirname "$(dirname "$0")")/lib/commands/update.sh"
10+
# shellcheck source=lib/commands/install.sh
11+
source "$(dirname "$(dirname "$0")")/lib/commands/install.sh"
12+
# shellcheck source=lib/commands/uninstall.sh
13+
source "$(dirname "$(dirname "$0")")/lib/commands/uninstall.sh"
14+
# shellcheck source=lib/commands/current.sh
15+
source "$(dirname "$(dirname "$0")")/lib/commands/current.sh"
16+
# shellcheck source=lib/commands/where.sh
17+
source "$(dirname "$(dirname "$0")")/lib/commands/where.sh"
18+
# shellcheck source=lib/commands/which.sh
19+
source "$(dirname "$(dirname "$0")")/lib/commands/which.sh"
20+
# shellcheck source=lib/commands/version_commands.sh
21+
source "$(dirname "$(dirname "$0")")/lib/commands/version_commands.sh"
22+
# shellcheck source=lib/commands/list.sh
23+
source "$(dirname "$(dirname "$0")")/lib/commands/list.sh"
24+
# shellcheck source=lib/commands/list-all.sh
25+
source "$(dirname "$(dirname "$0")")/lib/commands/list-all.sh"
26+
# shellcheck source=lib/commands/reshim.sh
27+
source "$(dirname "$(dirname "$0")")/lib/commands/reshim.sh"
28+
# shellcheck source=lib/commands/plugin-add.sh
29+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-add.sh"
30+
# shellcheck source=lib/commands/plugin-list.sh
31+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-list.sh"
32+
# shellcheck source=lib/commands/plugin-list-all.sh
33+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-list-all.sh"
34+
# shellcheck source=lib/commands/plugin-update.sh
35+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-update.sh"
36+
# shellcheck source=lib/commands/plugin-remove.sh
37+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-remove.sh"
38+
39+
# shellcheck source=lib/commands/plugin-push.sh
40+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-push.sh"
41+
# shellcheck source=lib/commands/plugin-test.sh
42+
source "$(dirname "$(dirname "$0")")/lib/commands/plugin-test.sh"
43+
44+
# shellcheck disable=SC2124
2645
callback_args="${@:2}"
2746

47+
# shellcheck disable=SC2086
2848
case $1 in
2949

3050
"--version")
31-
asdf_version $callback_args;;
51+
asdf_version $callback_args;;
3252

3353
"help")
3454
help_command $callback_args;;

bin/private/asdf-exec

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
#!/usr/bin/env bash
22

3-
source $(dirname $(dirname $(dirname $0)))/lib/utils.sh
3+
# shellcheck source=lib/utils.sh
4+
source "$(dirname "$(dirname "$(dirname "$0")")")/lib/utils.sh"
45

56
plugin_name=$1
67
executable_path=$2
78

8-
plugin_path=$(get_plugin_path $plugin_name)
9-
check_if_plugin_exists $plugin_name
9+
plugin_path=$(get_plugin_path "$plugin_name")
10+
check_if_plugin_exists "$plugin_name"
1011

11-
full_version=$(get_preset_version_for $plugin_name)
12+
full_version=$(get_preset_version_for "$plugin_name")
1213

1314
if [ "$full_version" == "" ]; then
1415
echo "No version set for ${plugin_name}"
1516
exit -1
1617
fi
1718

19+
# shellcheck disable=SC2162
1820
IFS=' ' read -a versions <<< "$full_version"
1921

2022
for version in "${versions[@]}"; do
21-
install_path=$(find_install_path $plugin_name $version)
23+
install_path=$(find_install_path "$plugin_name" "$version")
2224

23-
if [ $version != "system" ] && [ ! -d "$install_path" ]; then
25+
if [ "$version" != "system" ] && [ ! -d "$install_path" ]; then
2426
echo "$plugin_name $version not installed"
2527
exit 1
2628
fi
2729

28-
full_executable_path=$(get_executable_path $plugin_name $version $executable_path)
30+
if full_executable_path=$(get_executable_path "$plugin_name" "$version" "$executable_path"); then
31+
if [ -f "$full_executable_path" ]; then
32+
if [ -f "${plugin_path}/bin/exec-env" ]; then
33+
export ASDF_INSTALL_TYPE=$install_type
34+
export ASDF_INSTALL_VERSION=$version
35+
export ASDF_INSTALL_PATH=$install_path
2936

30-
if [ $? -eq 0 -a -f "$full_executable_path" ]; then
31-
if [ -f ${plugin_path}/bin/exec-env ]; then
32-
export ASDF_INSTALL_TYPE=$install_type
33-
export ASDF_INSTALL_VERSION=$version
34-
export ASDF_INSTALL_PATH=$install_path
37+
# shellcheck source=/dev/null
38+
source "${plugin_path}/bin/exec-env"
3539

36-
source ${plugin_path}/bin/exec-env
40+
# unset everything, we don't want to pollute
41+
unset ASDF_INSTALL_TYPE
42+
unset ASDF_INSTALL_VERSION
43+
unset ASDF_INSTALL_PATH
44+
fi
3745

38-
# unset everything, we don't want to pollute
39-
unset ASDF_INSTALL_TYPE
40-
unset ASDF_INSTALL_VERSION
41-
unset ASDF_INSTALL_PATH
46+
exec "$full_executable_path" "${@:3}"
4247
fi
43-
44-
exec $full_executable_path "${@:3}"
4548
fi
4649
done
4750

completions/asdf.bash

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,45 @@
11
#!/usr/bin/env bash
22

33
_asdf () {
4-
local cur=${COMP_WORDS[COMP_CWORD]}
5-
local cmd=${COMP_WORDS[1]}
6-
local prev=${COMP_WORDS[COMP_CWORD-1]}
7-
local plugins=$(asdf plugin-list | tr '\n' ' ')
4+
local cur
5+
cur=${COMP_WORDS[COMP_CWORD]}
6+
local cmd
7+
cmd=${COMP_WORDS[1]}
8+
local prev
9+
prev=${COMP_WORDS[COMP_CWORD-1]}
10+
local plugins
11+
plugins=$(asdf plugin-list | tr '\n' ' ')
812

913
COMPREPLY=()
1014

1115
case "$cmd" in
1216
plugin-update)
13-
COMPREPLY=($(compgen -W "$plugins --all" -- $cur))
17+
COMPREPLY=($(compgen -W "$plugins --all" -- "$cur"))
1418
;;
1519
plugin-remove|current|list|list-all)
16-
COMPREPLY=($(compgen -W "$plugins" -- $cur))
20+
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
1721
;;
1822
install)
1923
if [[ "$plugins" == *"$prev"* ]] ; then
20-
local versions=$(asdf list-all $prev)
21-
COMPREPLY=($(compgen -W "$versions" -- $cur))
24+
local versions
25+
versions=$(asdf list-all "$prev")
26+
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
2227
else
23-
COMPREPLY=($(compgen -W "$plugins" -- $cur))
28+
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
2429
fi
2530
;;
2631
uninstall|where|reshim|local|global)
2732
if [[ "$plugins" == *"$prev"* ]] ; then
28-
local versions=$(asdf list $prev)
29-
COMPREPLY=($(compgen -W "$versions" -- $cur))
33+
local versions
34+
versions=$(asdf list "$prev")
35+
COMPREPLY=($(compgen -W "$versions" -- "$cur"))
3036
else
31-
COMPREPLY=($(compgen -W "$plugins" -- $cur))
37+
COMPREPLY=($(compgen -W "$plugins" -- "$cur"))
3238
fi
3339
;;
3440
*)
3541
local cmds='plugin-add plugin-list plugin-remove plugin-update install uninstall update current where which list list-all local global reshim'
36-
COMPREPLY=($(compgen -W "$cmds" -- $cur))
42+
COMPREPLY=($(compgen -W "$cmds" -- "$cur"))
3743
;;
3844
esac
3945

lib/commands/current.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
plugin_current_command() {
22
local plugin_name=$1
33

4-
check_if_plugin_exists $plugin_name
4+
check_if_plugin_exists "$plugin_name"
55

6-
local search_path=$(pwd)
7-
local version_and_path=$(find_version "$plugin_name" "$search_path")
8-
local version=$(cut -d '|' -f 1 <<< "$version_and_path");
9-
local version_file_path=$(cut -d '|' -f 2 <<< "$version_and_path");
6+
local search_path
7+
search_path=$(pwd)
8+
local version_and_path
9+
version_and_path=$(find_version "$plugin_name" "$search_path")
10+
local version
11+
version=$(cut -d '|' -f 1 <<< "$version_and_path");
12+
local version_file_path
13+
version_file_path=$(cut -d '|' -f 2 <<< "$version_and_path");
1014

11-
check_if_version_exists $plugin_name $version
12-
check_for_deprecated_plugin $plugin_name
15+
check_if_version_exists "$plugin_name" "$version"
16+
check_for_deprecated_plugin "$plugin_name"
1317

1418
if [ -z "$version" ]; then
1519
echo "No version set for $plugin_name"
@@ -22,24 +26,26 @@ plugin_current_command() {
2226
current_command() {
2327
if [ $# -eq 0 ]; then
2428
for plugin in $(plugin_list_command); do
25-
echo "$plugin $(plugin_current_command $plugin)"
29+
echo "$plugin $(plugin_current_command "$plugin")"
2630
done
2731
else
2832
local plugin=$1
29-
plugin_current_command $plugin
33+
plugin_current_command "$plugin"
3034
fi
3135
}
3236

3337
# Warn if the plugin isn't using the updated legacy file api.
3438
check_for_deprecated_plugin() {
3539
local plugin_name=$1
3640

37-
local plugin_path=$(get_plugin_path "$plugin_name")
38-
local legacy_config=$(get_asdf_config_value "legacy_version_file")
41+
local plugin_path
42+
plugin_path=$(get_plugin_path "$plugin_name")
43+
local legacy_config
44+
legacy_config=$(get_asdf_config_value "legacy_version_file")
3945
local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
4046
local new_script="${plugin_path}/bin/list-legacy-filenames"
4147

42-
if [ "$legacy_config" = "yes" ] && [ -f $deprecated_script ] && [ ! -f $new_script ]; then
48+
if [ "$legacy_config" = "yes" ] && [ -f "$deprecated_script" ] && [ ! -f "$new_script" ]; then
4349
echo "Heads up! It looks like your $plugin_name plugin is out of date. You can update it with:"
4450
echo ""
4551
echo " asdf plugin-update $plugin_name"

lib/commands/help.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
help_command () {
22
echo "version: $(asdf_version)"
33
echo ""
4-
cat $(asdf_dir)/help.txt
4+
cat "$(asdf_dir)/help.txt"
55
}

lib/commands/install.sh

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,36 @@ install_command() {
2020
display_error "You must specify a name and a version to install"
2121
exit 1
2222
else
23-
install_tool_version $plugin_name $full_version
23+
install_tool_version "$plugin_name" "$full_version"
2424
fi
2525
}
2626

2727
get_concurrency() {
2828
if which nproc > /dev/null 2>&1; then
29-
echo $(nproc)
29+
nproc
3030
elif which sysctl > /dev/null 2>&1 && sysctl hw.ncpu > /dev/null 2>&1; then
31-
echo $(sysctl -n hw.ncpu)
31+
sysctl -n hw.ncpu
3232
elif [ -f /proc/cpuinfo ]; then
33-
echo $(grep -c processor /proc/cpuinfo)
33+
grep -c processor /proc/cpuinfo
3434
else
3535
echo "1"
3636
fi
3737
}
3838

3939
install_local_tool_versions() {
4040
if [ -f "$(pwd)/.tool-versions" ]; then
41-
local asdf_versions_path="$(pwd)/.tool-versions"
41+
local asdf_versions_path
42+
asdf_versions_path="$(pwd)/.tool-versions"
4243

43-
while read tool_line; do
44-
IFS=' ' read -a tool_info <<< $tool_line
45-
local tool_name=$(echo "${tool_info[0]}" | xargs)
46-
local tool_version=$(echo "${tool_info[1]}" | xargs)
44+
while read -r tool_line; do
45+
IFS=' ' read -r -a tool_info <<< "$tool_line"
46+
local tool_name
47+
tool_name=$(echo "${tool_info[0]}" | xargs)
48+
local tool_version
49+
tool_version=$(echo "${tool_info[1]}" | xargs)
4750

4851
if ! [[ -z "$tool_name" || -z "$tool_version" ]]; then
49-
install_tool_version $tool_name $tool_version
52+
install_tool_version "$tool_name" "$tool_version"
5053
fi
5154
done < "$asdf_versions_path"
5255
else
@@ -60,11 +63,12 @@ install_local_tool_versions() {
6063
install_tool_version() {
6164
local plugin_name=$1
6265
local full_version=$2
63-
local plugin_path=$(get_plugin_path $plugin_name)
64-
check_if_plugin_exists $plugin_name
66+
local plugin_path
67+
plugin_path=$(get_plugin_path "$plugin_name")
68+
check_if_plugin_exists "$plugin_name"
6569

6670

67-
IFS=':' read -a version_info <<< "$full_version"
71+
IFS=':' read -r -a version_info <<< "$full_version"
6872
if [ "${version_info[0]}" = "ref" ]; then
6973
local install_type="${version_info[0]}"
7074
local version="${version_info[1]}"
@@ -74,8 +78,10 @@ install_tool_version() {
7478
fi
7579

7680

77-
local install_path=$(get_install_path $plugin_name $install_type $version)
78-
local concurrency=$(get_concurrency)
81+
local install_path
82+
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
83+
local concurrency
84+
concurrency=$(get_concurrency)
7985
trap 'handle_cancel $install_path' INT
8086

8187
if [ -d "$install_path" ]; then
@@ -92,7 +98,7 @@ install_tool_version() {
9298

9399
local exit_code=$?
94100
if [ $exit_code -eq 0 ]; then
95-
reshim_command $plugin_name $full_version
101+
reshim_command "$plugin_name" "$full_version"
96102
else
97103
handle_failure "$install_path"
98104
fi

lib/commands/list-all.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
list_all_command() {
22
local plugin_name=$1
3-
local plugin_path=$(get_plugin_path $plugin_name)
4-
check_if_plugin_exists $plugin_name
3+
local plugin_path
4+
plugin_path=$(get_plugin_path "$plugin_name")
5+
check_if_plugin_exists "$plugin_name"
56

6-
local versions=$(bash ${plugin_path}/bin/list-all)
7+
local versions
8+
versions=$(bash "${plugin_path}/bin/list-all")
79

8-
IFS=' ' read -a versions_list <<< "$versions"
10+
IFS=' ' read -r -a versions_list <<< "$versions"
911

1012
for version in "${versions_list[@]}"
1113
do

0 commit comments

Comments
 (0)