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/key-bindings.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'shell/key-bindings.zsh') diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index c04a0020..4c4f0a08 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -11,6 +11,9 @@ # - $FZF_ALT_C_COMMAND # - $FZF_ALT_C_OPTS +[[ -o interactive ]] || return 0 + + # Key bindings # ------------ @@ -36,8 +39,6 @@ fi { -[[ -o interactive ]] || return 0 - # CTRL-T - Paste the selected file path(s) into the command line __fsel() { local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -- cgit v1.2.3