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 { @@ -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()

4
src/shell/fish.rs

@ -23,9 +23,7 @@ impl Shell for Fish { @@ -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

4
src/shell/zsh.rs

@ -23,9 +23,7 @@ impl Shell for Zsh { @@ -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
}

Loading…
Cancel
Save