From f103aa4753b435f8f45c5130323effeb75583c15 Mon Sep 17 00:00:00 2001 From: Christoph Anton Mitterer Date: Sun, 8 Oct 2023 18:19:28 +0200 Subject: Improve interactiveness checks (#3449) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [bash] return instead of not executing an if-block, when non-interactive This should keep the code more readable, be less error prone (accidentally doing something outside the if-block and aligns the code with what’s already done for zsh. `0` is returned, because it shall not be considered an error when the script is (accidentally) sourced from a non-interactive shell. If executed as a script (rather than sourced), the results are not specified by POSIX but depend on the shell, with bash giving an error in that case. Signed-off-by: Christoph Anton Mitterer * [shell] exit immediately when called from non-interactive shell The shell execution environment shouldn’t be modified at all, when called from a non-interactive shell. It shall be noted that the current check may become error prone for bash, namely in case there should ever be a differentiation between `i` and `I` in the special variable `-` and bash’s `nocasematch`-shell-option be used. Signed-off-by: Christoph Anton Mitterer --- shell/completion.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'shell/completion.zsh') diff --git a/shell/completion.zsh b/shell/completion.zsh index 1e7d6f10..a0406cb4 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -9,6 +9,9 @@ # - $FZF_COMPLETION_TRIGGER (default: '**') # - $FZF_COMPLETION_OPTS (default: empty) +[[ -o interactive ]] || return 0 + + # Both branches of the following `if` do the same thing -- define # __fzf_completion_options such that `eval $__fzf_completion_options` sets # all options to the same values they currently have. We'll do just that at @@ -73,9 +76,6 @@ fi # `finally` in lesser languages. We use it to *always* restore user options. { -# Bail out if not interactive shell. -[[ -o interactive ]] || return 0 - # To use custom commands instead of find, override _fzf_compgen_{path,dir} if ! declare -f _fzf_compgen_path > /dev/null; then _fzf_compgen_path() { -- cgit v1.2.3