From 6e064f0b19b9a48644169d1a93820a8f5092b301 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Mon, 8 Jul 2024 20:39:20 +0900 Subject: [PATCH] Do not cancel shell init on mcfly init failure 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`. --- mcfly.bash | 15 ++++++++++----- mcfly.zsh | 8 ++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mcfly.bash b/mcfly.bash index 6fffc409..f7bf075b 100644 --- a/mcfly.bash +++ b/mcfly.bash @@ -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. @@ -120,5 +125,5 @@ if [[ -t 0 ]] && [[ "$__MCFLY_LOADED" != "loaded" ]]; then fi fi fi - -fi +} +mcfly_initialize diff --git a/mcfly.zsh b/mcfly.zsh index 6c480447..5ef8b9f7 100644 --- a/mcfly.zsh +++ b/mcfly.zsh @@ -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}" @@ -100,5 +101,4 @@ if [[ -o interactive ]]; then zle -N mcfly-history-widget bindkey '^R' mcfly-history-widget fi - -fi +}