Skip to content

Conversation

dijonkitchen
Copy link
Contributor

Resolves #3081

README.md Outdated
@@ -599,8 +599,9 @@ cdnvm() {
fi
fi
}

cdnvm "$PWD" || exit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the intention here that if cdnvm fails, the alias should not be set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was meant to address https://www.shellcheck.net/wiki/SC2164, but I think it's surprising with the reordering which was meant to keep the cdnvm code together and the alias after and separate since shellcheck advised against using an alias in the same parsing unit: https://www.shellcheck.net/wiki/SC2262

To adhere more to the principle of least surprise, I'm going to reorder it back and still have the exit:

# ...
alias cd='cdnvm'
cdnvm "$PWD" || exit
# ...

Copy link

@dse dse Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The instructions on using the cdnvm function say to put the function definition at the end of your .bashrc, then put these two lines after the function definition:

alias cd='cdnvm'
cdnvm "$PWD" || exit

In the event cdnvm fails, this would exit the shell. Is this the desired outcome? Would it not be better to simply delete the alias?

alias cd='cdnvm'
cdnvm "$PWD" || { echo "cdnvm failed; unaliasing" >&2; unalias cd; }

Is there something else I'm missing?

(And is there a better forum to ask this question?)

Magicman10000

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants