Skip to content

Commit e814d58

Browse files
committed
Shellcheck all commands
1 parent 9d6ddb7 commit e814d58

21 files changed

Lines changed: 222 additions & 166 deletions

bin/asdf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ callback_args="${@:2}"
4747
case $1 in
4848

4949
"--version")
50-
asdf_version "$callback_args";;
50+
asdf_version "$callback_args";;
5151

5252
"help")
5353
help_command "$callback_args";;

lib/commands/current.sh

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

6-
check_if_plugin_exists $plugin_name
6+
check_if_plugin_exists "$plugin_name"
77

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

13-
check_if_version_exists $plugin_name $version
14-
check_for_deprecated_plugin $plugin_name
17+
check_if_version_exists "$plugin_name" "$version"
18+
check_for_deprecated_plugin "$plugin_name"
1519

1620
if [ -z "$version" ]; then
1721
echo "No version set for $plugin_name"
@@ -24,24 +28,26 @@ plugin_current_command() {
2428
current_command() {
2529
if [ $# -eq 0 ]; then
2630
for plugin in $(plugin_list_command); do
27-
echo "$plugin $(plugin_current_command $plugin)"
31+
echo "$plugin $(plugin_current_command "$plugin")"
2832
done
2933
else
3034
local plugin=$1
31-
plugin_current_command $plugin
35+
plugin_current_command "$plugin"
3236
fi
3337
}
3438

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

39-
local plugin_path=$(get_plugin_path "$plugin_name")
40-
local legacy_config=$(get_asdf_config_value "legacy_version_file")
43+
local plugin_path
44+
plugin_path=$(get_plugin_path "$plugin_name")
45+
local legacy_config
46+
legacy_config=$(get_asdf_config_value "legacy_version_file")
4147
local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
4248
local new_script="${plugin_path}/bin/list-legacy-filenames"
4349

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

lib/commands/help.sh

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

lib/commands/install.sh

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

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

4141
install_local_tool_versions() {
4242
if [ -f "$(pwd)/.tool-versions" ]; then
43-
local asdf_versions_path="$(pwd)/.tool-versions"
43+
local asdf_versions_path
44+
asdf_versions_path="$(pwd)/.tool-versions"
4445

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

5053
if ! [[ -z "$tool_name" || -z "$tool_version" ]]; then
51-
install_tool_version $tool_name $tool_version
54+
install_tool_version "$tool_name" "$tool_version"
5255
fi
5356
done < "$asdf_versions_path"
5457
else
@@ -62,11 +65,12 @@ install_local_tool_versions() {
6265
install_tool_version() {
6366
local plugin_name=$1
6467
local full_version=$2
65-
local plugin_path=$(get_plugin_path $plugin_name)
66-
check_if_plugin_exists $plugin_name
68+
local plugin_path
69+
plugin_path=$(get_plugin_path "$plugin_name")
70+
check_if_plugin_exists "$plugin_name"
6771

6872

69-
IFS=':' read -a version_info <<< "$full_version"
73+
IFS=':' read -r -a version_info <<< "$full_version"
7074
if [ "${version_info[0]}" = "ref" ]; then
7175
local install_type="${version_info[0]}"
7276
local version="${version_info[1]}"
@@ -76,8 +80,10 @@ install_tool_version() {
7680
fi
7781

7882

79-
local install_path=$(get_install_path $plugin_name $install_type $version)
80-
local concurrency=$(get_concurrency)
83+
local install_path
84+
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
85+
local concurrency
86+
concurrency=$(get_concurrency)
8187
trap 'handle_cancel $install_path' INT
8288

8389
if [ -d "$install_path" ]; then
@@ -94,7 +100,7 @@ install_tool_version() {
94100

95101
local exit_code=$?
96102
if [ $exit_code -eq 0 ]; then
97-
reshim_command $plugin_name $full_version
103+
reshim_command "$plugin_name" "$full_version"
98104
else
99105
handle_failure "$install_path"
100106
fi

lib/commands/list-all.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
list_all_command() {
44
local plugin_name=$1
5-
local plugin_path=$(get_plugin_path $plugin_name)
6-
check_if_plugin_exists $plugin_name
5+
local plugin_path
6+
plugin_path=$(get_plugin_path "$plugin_name")
7+
check_if_plugin_exists "$plugin_name"
78

8-
local versions=$(bash ${plugin_path}/bin/list-all)
9+
local versions
10+
versions=$(bash "${plugin_path}/bin/list-all")
911

10-
IFS=' ' read -a versions_list <<< "$versions"
12+
IFS=' ' read -r -a versions_list <<< "$versions"
1113

1214
for version in "${versions_list[@]}"
1315
do

lib/commands/list.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
list_command() {
44
local plugin_name=$1
5-
check_if_plugin_exists $plugin_name
5+
check_if_plugin_exists "$plugin_name"
66

7-
local versions=$(list_installed_versions $plugin_name)
7+
local versions
8+
versions=$(list_installed_versions "$plugin_name")
89

910
if [ -n "${versions}" ]; then
1011
for version in $versions; do
11-
echo $version
12+
echo "$version"
1213
done
1314
else
1415
display_error 'No versions installed'

lib/commands/plugin-add.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ plugin_add_command() {
2121
exit 1
2222
fi
2323

24-
local plugin_path=$(get_plugin_path $plugin_name)
24+
local plugin_path
25+
plugin_path=$(get_plugin_path "$plugin_name")
2526

26-
mkdir -p $(asdf_dir)/plugins
27+
mkdir -p "$(asdf_dir)/plugins"
2728

28-
if [ -d $plugin_path ]; then
29+
if [ -d "$plugin_path" ]; then
2930
display_error "Plugin named $plugin_name already added"
3031
exit 1
3132
else
32-
git clone $source_url $plugin_path
33-
if [ ! $? -eq 0 ]; then
33+
if ! git clone "$source_url" "$plugin_path"; then
3434
exit 1
3535
fi
3636
fi

lib/commands/plugin-list-all.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#!/usr/bin/env bash
2+
13
plugin_list_all_command() {
24
initialize_or_update_repository
35

4-
local plugins_path=$(asdf_dir)/repository/plugins
6+
local plugins_path
7+
plugins_path="$(asdf_dir)/repository/plugins"
58
for plugin in $plugins_path/*; do
6-
local plugin_name="$(basename $plugin)"
7-
echo "$plugin_name"
9+
basename "$plugin"
810
done
911
}

lib/commands/plugin-list.sh

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

33
plugin_list_command() {
4-
local plugins_path=$(get_plugin_path)
4+
local plugins_path
5+
plugins_path=$(get_plugin_path)
56

6-
if ls $plugins_path &> /dev/null; then
7+
if ls "$plugins_path" &> /dev/null; then
78
for plugin_path in $plugins_path/* ; do
8-
echo "$(basename $plugin_path)"
9+
basename "$plugin_path"
910
done
1011
else
1112
echo 'Oohes nooes ~! No plugins installed'

lib/commands/plugin-push.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ plugin_push_command() {
44
local plugin_name=$1
55
if [ "$plugin_name" = "--all" ]; then
66
for dir in $(asdf_dir)/plugins/*; do
7-
echo "Pushing $(basename $dir)..."
7+
echo "Pushing $(basename "$dir")..."
88
(cd "$dir" && git push)
99
done
1010
else
11-
local plugin_path=$(get_plugin_path $plugin_name)
12-
check_if_plugin_exists $plugin_name
11+
local plugin_path
12+
plugin_path=$(get_plugin_path "$plugin_name")
13+
check_if_plugin_exists "$plugin_name"
1314
echo "Pushing $plugin_name..."
14-
(cd $plugin_path; git push)
15+
(cd "$plugin_path" && git push)
1516
fi
1617
}

0 commit comments

Comments
 (0)