From c166eaba6d5e74d39a68c45804a01417d707a304 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 4 Jun 2025 14:07:01 +0900 Subject: [PATCH] [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. --- shell/completion.bash | 20 ++++++++++++++------ shell/completion.zsh | 20 ++++++++++++++------ shell/key-bindings.bash | 20 ++++++++++++++------ shell/key-bindings.zsh | 20 ++++++++++++++------ 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/shell/completion.bash b/shell/completion.bash index b62cf004..3589580a 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -50,12 +50,20 @@ __fzf_defaults() { __fzf_exec_awk() { if [[ -z ${__fzf_awk-} ]]; then __fzf_awk=awk - - # choose the faster mawk if: it's installed && build date >= 20230322 && - # version >= 1.3.4 - local n x y z d - 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 + 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 && + # version >= 1.3.4 + local n x y z d + 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 + fi fi # Note: macOS awk has a quirk that it stops processing at all when it sees diff --git a/shell/completion.zsh b/shell/completion.zsh index d59796bc..7f4a8112 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -115,12 +115,20 @@ __fzf_defaults() { __fzf_exec_awk() { if [[ -z ${__fzf_awk-} ]]; then __fzf_awk=awk - - # choose the faster mawk if: it's installed && build date >= 20230322 && - # version >= 1.3.4 - local n x y z d - 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 + 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 && + # version >= 1.3.4 + local n x y z d + 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 + fi fi # Note: macOS awk has a quirk that it stops processing at all when it sees diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index 946bc2d8..9cfae021 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -36,12 +36,20 @@ __fzf_defaults() { __fzf_exec_awk() { if [[ -z ${__fzf_awk-} ]]; then __fzf_awk=awk - - # choose the faster mawk if: it's installed && build date >= 20230322 && - # version >= 1.3.4 - local n x y z d - 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 + 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 && + # version >= 1.3.4 + local n x y z d + 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 + fi fi # Note: macOS awk has a quirk that it stops processing at all when it sees diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index 51defeab..f283d157 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -57,12 +57,20 @@ __fzf_defaults() { __fzf_exec_awk() { if [[ -z ${__fzf_awk-} ]]; then __fzf_awk=awk - - # choose the faster mawk if: it's installed && build date >= 20230322 && - # version >= 1.3.4 - local n x y z d - 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 + 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 && + # version >= 1.3.4 + local n x y z d + 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 + fi fi # Note: macOS awk has a quirk that it stops processing at all when it sees