From 30f71a98c2dfcfe6efc755f01ea8ae44bd516f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Haasler=20Garc=C3=ADa?= Date: Fri, 22 Nov 2019 21:12:05 +0100 Subject: [PATCH] Use a FIFO as fzf input The named pipe is used as input for fzf, which means that there is no need to tail the file and kill that process. --- sway-launcher-desktop.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index ff788ba..2441cbe 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -142,9 +142,9 @@ esac touch "$HIST_FILE" readarray HIST_LINES <"$HIST_FILE" -FZFPIPE=$(mktemp) -PIDFILE=$(mktemp) -trap 'rm "$FZFPIPE" "$PIDFILE"' EXIT INT +FZFPIPE=$(mktemp -u) +mkfifo "$FZFPIPE" +trap 'rm "$FZFPIPE"' EXIT INT # Append Launcher History, removing usage count (printf '%s' "${HIST_LINES[@]#* }" >>"$FZFPIPE") & @@ -173,14 +173,10 @@ entries ${DIRS[@]} >>"$FZFPIPE" ) & COMMAND_STR=$( - ( - tail -n +0 -f "$FZFPIPE" & - echo $! >"$PIDFILE" - ) | - fzf +s -x -d '\034' --nth ..3 --with-nth 3 \ - --preview "$0 describe {1} {2}" \ - --preview-window=up:3:wrap --ansi - (kill -9 "$(<"$PIDFILE")"; exit 0) | tail -n1 + fzf +s -x -d '\034' --nth ..3 --with-nth 3 \ + --preview "$0 describe {1} {2}" \ + --preview-window=up:3:wrap --ansi \ + <"$FZFPIPE" ) || exit 1 [ -z "$COMMAND_STR" ] && exit 1