Browse Source

Run `fnm use` on shell initialization in Bash (#322)

remotes/origin/add-with-shims
Gal Schlezinger 4 years ago committed by GitHub
parent
commit
322d2b6c1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/shell/bash.rs
  2. 4
      src/shell/fish.rs
  3. 4
      src/shell/zsh.rs

14
src/shell/bash.rs

@ -21,17 +21,19 @@ impl Shell for Bash {
fn use_on_cd(&self, _config: &crate::config::FnmConfig) -> String { fn use_on_cd(&self, _config: &crate::config::FnmConfig) -> String {
indoc!( indoc!(
r#" r#"
__fnmcd () { __fnm_use_if_file_found() {
cd "$@" if [[ -f .node-version || -f .nvmrc ]]; then
if [[ -f .node-version && .node-version ]]; then
fnm use
elif [[ -f .nvmrc && .nvmrc ]]; then
fnm use fnm use
fi fi
} }
__fnmcd () {
cd "$@" || return $?
__fnm_use_if_file_found
}
alias cd=__fnmcd alias cd=__fnmcd
__fnm_use_if_file_found
"# "#
) )
.into() .into()

4
src/shell/fish.rs

@ -23,9 +23,7 @@ impl Shell for Fish {
r#" r#"
function _fnm_autoload_hook --on-variable PWD --description 'Change Node version on directory change' function _fnm_autoload_hook --on-variable PWD --description 'Change Node version on directory change'
status --is-command-substitution; and return status --is-command-substitution; and return
if test -f .node-version if test -f .node-version -o -f .nvmrc
fnm use
else if test -f .nvmrc
fnm use fnm use
end end
end end

4
src/shell/zsh.rs

@ -23,9 +23,7 @@ impl Shell for Zsh {
r#" r#"
autoload -U add-zsh-hook autoload -U add-zsh-hook
_fnm_autoload_hook () { _fnm_autoload_hook () {
if [[ -f .node-version && -r .node-version ]]; then if [[ -f .node-version || -f .nvmrc ]]; then
fnm use
elif [[ -f .nvmrc && -r .nvmrc ]]; then
fnm use fnm use
fi fi
} }

Loading…
Cancel
Save