From 4bd2aeabaf066768fe1c0281644b4a62a7a2c222 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 22 Jan 2025 12:14:02 +0200 Subject: [PATCH 1/3] ironing this odd lint problem --- clean_files.txt | 1 + plugins/available/z_autoenv.plugin.bash | 68 ++++++++++++------------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 88fbd3e648..93fbfca475 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -134,6 +134,7 @@ plugins/available/textmate.plugin.bash plugins/available/todo.plugin.bash plugins/available/url.plugin.bash plugins/available/xterm.plugin.bash +plugins/available/z_autoenv.plugin.bash plugins/available/zoxide.plugin.bash # tests diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index a2f97d2833..283be98ceb 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -1,45 +1,43 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'source into environment when cding to directories' -if [[ -n "${ZSH_VERSION}" ]] -then __array_offset=0 -else __array_offset=1 +if [[ -n "${ZSH_VERSION}" ]]; then + __array_offset=0 +else + __array_offset=1 fi -autoenv_init() -{ - typeset target home _file - typeset -a _files - target=$1 - home="${HOME%/*}" +autoenv_init() { + typeset home _file # target + typeset -a _files + #target=$1 + home="${HOME%/*}" - _files=( $( - while [[ "$PWD" != "/" && "$PWD" != "$home" ]] - do - _file="$PWD/.env" - if [[ -e "${_file}" ]] - then echo "${_file}" - fi - builtin cd .. - done - ) ) + while [[ "$PWD" != "/" && "$PWD" != "$home" ]]; do + _file="$PWD/.env" + if [[ -e "${_file}" ]]; then + _files+=("${_file}") + fi + builtin cd .. || true + done - _file=${#_files[@]} - while (( _file > 0 )) - do - source "${_files[_file-__array_offset]}" - : $(( _file -= 1 )) - done + _file=${#_files[@]} + while ((_file > 0)); do + #shellcheck disable=SC1090 + source "${_files[_file - __array_offset]}" + : $((_file -= 1)) + done } -cd() -{ - if builtin cd "$@" - then - autoenv_init - return 0 - else - echo "else?" - return $? - fi +cd() { + if builtin cd "$@"; then + autoenv_init + return 0 + else + local return_code + return_code=$? + echo "else?" + return $return_code + fi } From d62c62bf4ded27b256b1c6ec9e700df75e1f7b00 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 22 Jan 2025 12:23:43 +0200 Subject: [PATCH 2/3] ironing this odd lint problem --- plugins/available/z_autoenv.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 8ffd11e6e6..98347a973a 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -32,11 +32,11 @@ autoenv_init() { } cd() { + local return_code if builtin cd "$@"; then autoenv_init return 0 else - local return_code return_code=$? echo "else?" return $return_code From 791d557698adcac3004962c58c2a5e95a6947cc5 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Wed, 22 Jan 2025 12:29:53 +0200 Subject: [PATCH 3/3] you go "quote-TOAH" on that thang! Co-authored-by: Koichi Murase --- plugins/available/z_autoenv.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 98347a973a..b7c4b38a47 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -39,6 +39,6 @@ cd() { else return_code=$? echo "else?" - return $return_code + return "$return_code" fi }