Skip to content

Commit

Permalink
Do not cancel shell init on mcfly init failure
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
akinomyoga committed Jul 8, 2024
1 parent cdd00e0 commit 6e064f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions mcfly.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/bin/bash

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

# Ensure stdin is a tty
[[ -t 0 ]] || return 0

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

# Setup MCFLY_HISTFILE and make sure it exists.
Expand Down Expand Up @@ -120,5 +125,5 @@ if [[ -t 0 ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then
fi
fi
fi

fi
}
mcfly_initialize
8 changes: 4 additions & 4 deletions mcfly.zsh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/zsh

# Ensure stdin is a tty
if [[ -o interactive ]]; then
() {
# Ensure stdin is a tty
[[ -o interactive ]] || return 0

# Setup MCFLY_HISTFILE and make sure it exists.
export MCFLY_HISTFILE="${HISTFILE:-$HOME/.zsh_history}"
Expand Down Expand Up @@ -100,5 +101,4 @@ if [[ -o interactive ]]; then
zle -N mcfly-history-widget
bindkey '^R' mcfly-history-widget
fi

fi
}

0 comments on commit 6e064f0

Please sign in to comment.