[bash,zsh] Work around Solaris awk, which is non-standard

Solaris awk at /usr/bin/awk is meant for backward compatibility with
an ancient implementation of 1977 awk in the original UNIX.  It lacks
many features of POSIX awk.  To use a standard-conforming version in
Solaris, one needs to explicitly use /usr/xpg4/bin/awk.
This commit is contained in:
Koichi Murase
2025-06-04 14:07:01 +09:00
committed by Junegunn Choi
parent 09194c24f2
commit c166eaba6d
4 changed files with 56 additions and 24 deletions

View File

@@ -50,13 +50,21 @@ __fzf_defaults() {
__fzf_exec_awk() { __fzf_exec_awk() {
if [[ -z ${__fzf_awk-} ]]; then if [[ -z ${__fzf_awk-} ]]; then
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
# Note: Solaris awk at /usr/bin/awk is meant for backward compatibility
# with an ancient implementation of 1977 awk in the original UNIX. It
# lacks many features of POSIX awk, so it is essentially useless in the
# modern point of view. To use a standard-conforming version in Solaris,
# one needs to explicitly use /usr/xpg4/bin/awk.
__fzf_awk=/usr/xpg4/bin/awk
else
# choose the faster mawk if: it's installed && build date >= 20230322 && # choose the faster mawk if: it's installed && build date >= 20230322 &&
# version >= 1.3.4 # version >= 1.3.4
local n x y z d local n x y z d
IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk
fi fi
fi
# Note: macOS awk has a quirk that it stops processing at all when it sees # Note: macOS awk has a quirk that it stops processing at all when it sees
# any data not following UTF-8 in the input stream when the current LC_CTYPE # any data not following UTF-8 in the input stream when the current LC_CTYPE

View File

@@ -115,13 +115,21 @@ __fzf_defaults() {
__fzf_exec_awk() { __fzf_exec_awk() {
if [[ -z ${__fzf_awk-} ]]; then if [[ -z ${__fzf_awk-} ]]; then
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
# Note: Solaris awk at /usr/bin/awk is meant for backward compatibility
# with an ancient implementation of 1977 awk in the original UNIX. It
# lacks many features of POSIX awk, so it is essentially useless in the
# modern point of view. To use a standard-conforming version in Solaris,
# one needs to explicitly use /usr/xpg4/bin/awk.
__fzf_awk=/usr/xpg4/bin/awk
else
# choose the faster mawk if: it's installed && build date >= 20230322 && # choose the faster mawk if: it's installed && build date >= 20230322 &&
# version >= 1.3.4 # version >= 1.3.4
local n x y z d local n x y z d
IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk
fi fi
fi
# Note: macOS awk has a quirk that it stops processing at all when it sees # Note: macOS awk has a quirk that it stops processing at all when it sees
# any data not following UTF-8 in the input stream when the current LC_CTYPE # any data not following UTF-8 in the input stream when the current LC_CTYPE

View File

@@ -36,13 +36,21 @@ __fzf_defaults() {
__fzf_exec_awk() { __fzf_exec_awk() {
if [[ -z ${__fzf_awk-} ]]; then if [[ -z ${__fzf_awk-} ]]; then
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
# Note: Solaris awk at /usr/bin/awk is meant for backward compatibility
# with an ancient implementation of 1977 awk in the original UNIX. It
# lacks many features of POSIX awk, so it is essentially useless in the
# modern point of view. To use a standard-conforming version in Solaris,
# one needs to explicitly use /usr/xpg4/bin/awk.
__fzf_awk=/usr/xpg4/bin/awk
else
# choose the faster mawk if: it's installed && build date >= 20230322 && # choose the faster mawk if: it's installed && build date >= 20230322 &&
# version >= 1.3.4 # version >= 1.3.4
local n x y z d local n x y z d
IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk
fi fi
fi
# Note: macOS awk has a quirk that it stops processing at all when it sees # Note: macOS awk has a quirk that it stops processing at all when it sees
# any data not following UTF-8 in the input stream when the current LC_CTYPE # any data not following UTF-8 in the input stream when the current LC_CTYPE

View File

@@ -57,13 +57,21 @@ __fzf_defaults() {
__fzf_exec_awk() { __fzf_exec_awk() {
if [[ -z ${__fzf_awk-} ]]; then if [[ -z ${__fzf_awk-} ]]; then
__fzf_awk=awk __fzf_awk=awk
if [[ $OSTYPE == solaris* && -x /usr/xpg4/bin/awk ]]; then
# Note: Solaris awk at /usr/bin/awk is meant for backward compatibility
# with an ancient implementation of 1977 awk in the original UNIX. It
# lacks many features of POSIX awk, so it is essentially useless in the
# modern point of view. To use a standard-conforming version in Solaris,
# one needs to explicitly use /usr/xpg4/bin/awk.
__fzf_awk=/usr/xpg4/bin/awk
else
# choose the faster mawk if: it's installed && build date >= 20230322 && # choose the faster mawk if: it's installed && build date >= 20230322 &&
# version >= 1.3.4 # version >= 1.3.4
local n x y z d local n x y z d
IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null) IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)
[[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk [[ $n == mawk ]] && (( d >= 20230302 && (x * 1000 + y) * 1000 + z >= 1003004 )) && __fzf_awk=mawk
fi fi
fi
# Note: macOS awk has a quirk that it stops processing at all when it sees # Note: macOS awk has a quirk that it stops processing at all when it sees
# any data not following UTF-8 in the input stream when the current LC_CTYPE # any data not following UTF-8 in the input stream when the current LC_CTYPE