| 1 |
__fzf_defaults() { |
| 2 |
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS |
| 3 |
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS |
| 4 |
builtin printf '%s\n' "--height ${FZF_TMUX_HEIGHT:-40%} --min-height 20+ --bind=ctrl-z:ignore $1" |
| 5 |
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null |
| 6 |
builtin printf '%s\n' "${FZF_DEFAULT_OPTS-} $2" |
| 7 |
} |
| 8 |
|
| 9 |
__fzf_exec_awk() { |
| 10 |
# This function performs `exec awk "$@"` safely by working around awk |
| 11 |
# compatibility issues. |
| 12 |
# |
| 13 |
# To reduce an extra fork, this function performs "exec" so is expected to be |
| 14 |
# run as the last command in a subshell. |
| 15 |
if [[ -z ${__fzf_awk-} ]]; then |
| 16 |
__fzf_awk=awk |
| 17 |
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then |
| 18 |
# Note: Solaris awk at /usr/bin/awk is meant for backward compatibility |
| 19 |
# with an ancient implementation of 1977 awk in the original UNIX. It |
| 20 |
# lacks many features of POSIX awk, so it is essentially useless in the |
| 21 |
# modern point of view. To use a standard-conforming version in Solaris, |
| 22 |
# one needs to explicitly use /usr/xpg4/bin/awk. |
| 23 |
__fzf_awk=/usr/xpg4/bin/awk |
| 24 |
elif command -v mawk > /dev/null 2>&1; then |
| 25 |
# choose the faster mawk if: it's installed && build date >= 20230322 && |
| 26 |
# version >= 1.3.4 |
| 27 |
local n x y z d |
| 28 |
IFS=' .' read -r n x y z d <<< $(command mawk -W version 2> /dev/null) |
| 29 |
[[ $n == mawk ]] && |
| 30 |
(((x * 1000 + y) * 1000 + z >= 1003004)) 2> /dev/null && |
| 31 |
((d >= 20230302)) 2> /dev/null && |
| 32 |
__fzf_awk=mawk |
| 33 |
fi |
| 34 |
fi |
| 35 |
# Note: macOS awk has a quirk that it stops processing at all when it sees |
| 36 |
# any data not following UTF-8 in the input stream when the current LC_CTYPE |
| 37 |
# specifies the UTF-8 encoding. To work around this quirk, one needs to |
| 38 |
# specify LC_ALL=C to change the current encoding to the plain one. |
| 39 |
LC_ALL=C exec "$__fzf_awk" "$@" |
| 40 |
} |