Skip to content
Myr

Improve interactiveness checks (#3449)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* [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 <mail@christoph.anton.mitterer.name> * [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.

authored by Christoph Anton Mitterer · committed by GitHub · parent 8848560 · Browse files · 4 files+11 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>

Diff stats

4 files+11 added−12 removed

  • other:+11 added−12 removed

4 files+11 added−12 removed

modified:shell/completion.bash+2 added-3 removed
7 unmodified lines
8# - $FZF_TMUX_OPTS (default: empty)9# - $FZF_COMPLETION_TRIGGER (default: '**')10# - $FZF_COMPLETION_OPTS (default: empty)1112if [[ $- =~ i ]]; then12[[ $- =~ i ]] || return 0131415# To use custom commands instead of find, override _fzf_compgen_{path,dir}16if ! declare -F _fzf_compgen_path > /dev/null; then17 _fzf_compgen_path() {18 echo "$1"
382 unmodified lines
401_fzf_setup_completion 'var' export unset printenv402_fzf_setup_completion 'alias' unalias403_fzf_setup_completion 'host' telnet404_fzf_setup_completion 'proc' kill404405fi
modified:shell/completion.zsh+3 added-3 removed
7 unmodified lines
8# - $FZF_TMUX_OPTS (default: '-d 40%')9# - $FZF_COMPLETION_TRIGGER (default: '**')10# - $FZF_COMPLETION_OPTS (default: empty)1112[[ -o interactive ]] || return 0131415# Both branches of the following `if` do the same thing -- define16# __fzf_completion_options such that `eval $__fzf_completion_options` sets17# all options to the same values they currently have. We'll do just that at18# the bottom of the file after changing options to what we prefer.
56 unmodified lines
75# This brace is the start of try-always block. The `always` part is like76# `finally` in lesser languages. We use it to *always* restore user options.77{7876# Bail out if not interactive shell.77[[ -o interactive ]] || return 07879# To use custom commands instead of find, override _fzf_compgen_{path,dir}80if ! declare -f _fzf_compgen_path > /dev/null; then81 _fzf_compgen_path() {82 echo "$1"
260 unmodified lines
modified:shell/key-bindings.bash+3 added-4 removed
modified:shell/key-bindings.zsh+3 added-2 removed
9 unmodified lines
10# - $FZF_CTRL_R_OPTS11# - $FZF_ALT_C_COMMAND12# - $FZF_ALT_C_OPTS1314[[ -o interactive ]] || return 0151617# Key bindings18# ------------1920# The code at the top and the bottom of this file is the same as in completion.zsh.
17 unmodified lines
38'emulate' 'zsh' '-o' 'no_aliases'3940{4139[[ -o interactive ]] || return 04042# CTRL-T - Paste the selected file path(s) into the command line43__fsel() {44 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 \45 -o -type f -print \
76 unmodified lines