Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not cancel the entire Bash/Zsh initialization on mcfly initialization failure #425

Merged
merged 1 commit into from
Jul 11, 2024

Conversation

akinomyoga
Copy link
Contributor

The shell initialiation codes contain return 1 at the top level. However, this causes the cancellation of the entire shell initialization because those codes are supposed to be evaluated as e.g. eval "$(mcfly init bash)". This is because the invocation of return in the eval'ed string takes an effect in the caller context of eval.

For example, with the following ~/.bashrc,

# bashrc

eval "$(mcfly init bash)"

alias myalias='foo bar baz'

myalias would not be set up when the mcfly initialization fails because the mcfly initialization calls return 1 at the top level, which cancels the execution of ~/.bashrc (instead of just canceling the mcfly initialization).

This PR fixes the problem by enclosing the entire mcfly initialization in a shell function (or an anonymous function in Zsh) and allows returning from the enclosing function.

The shell initialiation codes contain "return 1" at the top level.
However, this causes the cancellation of the entire shell
initialization because those codes are supposed to be evaluated as
e.g. `eval "$(mcfly init bash)"`.  The invocation of `return` in the
eval'ed string takes an effect in the caller context of `eval`.
@cantino cantino merged commit 3ddb996 into cantino:master Jul 11, 2024
19 checks passed
@cantino
Copy link
Owner

cantino commented Jul 11, 2024

Thank you @akinomyoga!

@cantino
Copy link
Owner

cantino commented Jul 11, 2024

@akinomyoga akinomyoga deleted the shell-return branch July 11, 2024 04:46
Copy link

@YoutacRandS-VA YoutacRandS-VA left a comment

Choose a reason for hiding this comment

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

Help me edit

[[ -t 0 ]] || return 0

# Avoid loading this file more than once
[[ "$__MCFLY_LOADED" != "loaded" ]] || return 0

Choose a reason for hiding this comment

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

[[ "$__YOUTACRANDSVA_LOADED" != "loaded" ]]

# Avoid loading this file more than once
if [[ -t 0 ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then
function mcfly_initialize {
unset -f "${FUNCNAME[0]}"

Choose a reason for hiding this comment

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

  • unset -f "${YOUTACRANDSVA[0]}"

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

Successfully merging this pull request may close these issues.

None yet

3 participants