From dc8a6e6297c861edb127f85f42fce30b4ba5d7de Mon Sep 17 00:00:00 2001 From: knutze <34371397+knutze@users.noreply.github.com> Date: Sat, 27 Aug 2022 22:58:30 +0900 Subject: [PATCH] Updated Examples (markdown) --- Examples.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Examples.md b/Examples.md index ebd6b52..6b1e7ba 100644 --- a/Examples.md +++ b/Examples.md @@ -559,13 +559,6 @@ fi # CTRL-R script for MSYS2 environment (requires winpty) # For the most part the same as the original __fzf_history__. _fzf_history_msys2() { - # Bash 4.4 or later - local - && set -o pipefail - - # Concurrency is not considered (who needs it?) - local WORK_DIR="${TMPDIR:-/tmp}/${FUNCNAME[0]##_}-${UID:-$(id -u)}" - mkdir -p "${WORK_DIR}" || return - local PERL_SCRIPT=' BEGIN { getc; $/ = "\n\t"; $HISTCOUNT = $ENV{last_hist} + 1 } s/^[ *]//; print $HISTCOUNT - $. . "\t$_" if !$seen{$_}++ @@ -580,20 +573,30 @@ _fzf_history_msys2() { +m --read0 " + # Concurrency is not considered (who needs it?) + local WORK_DIR="${TMPDIR:-/tmp}/${FUNCNAME[0]##_}-${UID:-$(id -u)}" + mkdir -p "${WORK_DIR}" || return + + # `builtin fc` does not work inside winpty, so run it here + # to take output to a file. + (set -o pipefail + builtin fc -lnr -2147483648 | + last_hist=$(HISTTIMEFORMAT='' builtin history 1) \ + perl -n -l0 -e "${PERL_SCRIPT}" \ + >"${WORK_DIR}"/input + ) || return + # stdin is passed to winpty as-is tty, and input/output # to/from fzf is via file. - builtin fc -lnr -2147483648 | - last_hist=$(HISTTIMEFORMAT='' builtin history 1) \ - perl -n -l0 -e "${PERL_SCRIPT}" \ - >"${WORK_DIR}"/stdin || return winpty -- bash -c " set -o pipefail - cat '${WORK_DIR}'/stdin | \ + cat '${WORK_DIR}'/input | \ FZF_DEFAULT_OPTS='${FZF_OPTS}' fzf --query '${READLINE_LINE}' \ - >'${WORK_DIR}'/stdout + >'${WORK_DIR}'/output " || return - READLINE_LINE=$(sed -E 's|^[0-9]*\s*||' "${WORK_DIR}"/stdout) + # Get fzf output from file. + READLINE_LINE=$(sed -E 's|^[0-9]*\s*||' "${WORK_DIR}"/output) if [[ -z "${READLINE_POINT}" ]]; then echo "${READLINE_LINE}" else