diff --git a/src/shell/bash.rs b/src/shell/bash.rs index 4ba5e43..ec1c517 100644 --- a/src/shell/bash.rs +++ b/src/shell/bash.rs @@ -21,17 +21,19 @@ impl Shell for Bash { fn use_on_cd(&self, _config: &crate::config::FnmConfig) -> String { indoc!( r#" - __fnmcd () { - cd "$@" - - if [[ -f .node-version && .node-version ]]; then - fnm use - elif [[ -f .nvmrc && .nvmrc ]]; then + __fnm_use_if_file_found() { + if [[ -f .node-version || -f .nvmrc ]]; then fnm use fi } + __fnmcd () { + cd "$@" || return $? + __fnm_use_if_file_found + } + alias cd=__fnmcd + __fnm_use_if_file_found "# ) .into() diff --git a/src/shell/fish.rs b/src/shell/fish.rs index 24886a0..a0a36ec 100644 --- a/src/shell/fish.rs +++ b/src/shell/fish.rs @@ -23,9 +23,7 @@ impl Shell for Fish { r#" function _fnm_autoload_hook --on-variable PWD --description 'Change Node version on directory change' status --is-command-substitution; and return - if test -f .node-version - fnm use - else if test -f .nvmrc + if test -f .node-version -o -f .nvmrc fnm use end end diff --git a/src/shell/zsh.rs b/src/shell/zsh.rs index 8a1b9bf..c79a89a 100644 --- a/src/shell/zsh.rs +++ b/src/shell/zsh.rs @@ -23,9 +23,7 @@ impl Shell for Zsh { r#" autoload -U add-zsh-hook _fnm_autoload_hook () { - if [[ -f .node-version && -r .node-version ]]; then - fnm use - elif [[ -f .nvmrc && -r .nvmrc ]]; then + if [[ -f .node-version || -f .nvmrc ]]; then fnm use fi }