diff --git a/helper.sh b/helper.sh index 1b633b6..e0ed2f7 100755 --- a/helper.sh +++ b/helper.sh @@ -8,6 +8,7 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then _get_heighest \ _default_sort \ _etools_print_assoc_array \ + _debug_time \ _filter; do unset $function || echo "failed to unset function: $function" @@ -33,7 +34,9 @@ function _formatted_find() { function _set_weights() { for package in "${!_etools_packages[@]}"; do - for regex in ${!package_weights[@]}; do + # allow reference to sourced value + # shellcheck disable=SC2154 + for regex in "${!package_weights[@]}"; do if [[ $package =~ ^*${regex}*$ ]]; then _etools_packages[$package]=${package_weights[$regex]} fi @@ -42,7 +45,6 @@ function _set_weights() { } function _get_heighest() { - # declare -n _etools_packages=$1 local max_key="" local max_value=-100 @@ -72,8 +74,9 @@ function _etools_print_assoc_array { } function _debug_time() { - local end_time=$(date +%s%3N) - echo $((end_time - start_time)) + local end_time= + end_time=$(date +%s%3N) + echo $((end_time - $1)) } function _filter() { @@ -82,12 +85,10 @@ function _filter() { (( $# <= 1 )) && ewarn "No packages found, review config options" && return 1; declare -Ag _etools_packages for package in "$@"; do - # allow indirect reference - # shellcheck disable=SC2034 package=${package//\"/} - base_name="${package##*/}" # Get the last part - parent_name="${package%/*}" # Remove the last part - parent_name="${parent_name##*/}" # Get the second-to-last part + base_name="${package##*/}" + parent_name="${package%/*}" + parent_name="${parent_name##*/}" _etools_packages["$parent_name/$base_name"]=0 done local functions=