Skip to content

Commit

Permalink
[shell] exit immediately when called from non-interactive shell
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
calestyo committed Oct 8, 2023
1 parent 0df364e commit c448711
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions shell/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

[[ $- =~ i ]] || 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() {
Expand Down
6 changes: 3 additions & 3 deletions shell/completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions shell/key-bindings.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# - $FZF_ALT_C_COMMAND
# - $FZF_ALT_C_OPTS

[[ $- =~ i ]] || return 0


# Key bindings
# ------------
__fzf_select__() {
Expand All @@ -27,8 +30,6 @@ __fzf_select__() {
done
}

[[ $- =~ i ]] || return 0

__fzfcmd() {
[[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } &&
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
Expand Down
5 changes: 3 additions & 2 deletions shell/key-bindings.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# - $FZF_ALT_C_COMMAND
# - $FZF_ALT_C_OPTS

[[ -o interactive ]] || return 0


# Key bindings
# ------------

Expand All @@ -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 \
Expand Down

0 comments on commit c448711

Please sign in to comment.