From 65c67aca6cfde2876e4687f84e017627baafd8d2 Mon Sep 17 00:00:00 2001 From: Vladimir Bauer Date: Fri, 15 Nov 2024 07:09:41 +0500 Subject: [PATCH] kamp-fifo: require client in order to focus --- scripts/kamp-fifo | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/scripts/kamp-fifo b/scripts/kamp-fifo index de1ddad..e8604f3 100755 --- a/scripts/kamp-fifo +++ b/scripts/kamp-fifo @@ -2,18 +2,42 @@ # # pipe stdin into fifo buffer # -# Example: -# make | kamp-fifo [output_buffer_name] +# Example: make | kamp-fifo set -euf -# Fail early if there is no session -kamp > /dev/null +usage() { + printf "Usage: %s: [-c client] [fifo_buffer_name]\n" "$(basename "$0")" >&2 + exit 2 +} + +cflag= +while getopts 'c:h' OPTION; do + case $OPTION in + c) + cflag=1 + cval="$OPTARG" + ;; + h|?) + usage + ;; + esac +done +shift $(($OPTIND - 1)) + +kamp >/dev/null # fail early if there is no session d=$(mktemp -d) fifo="$d/fifo" -trap 'rm -rf "$d"; exit' EXIT HUP INT TERM +trap 'unlink "$fifo" && rmdir "$d"; exit' EXIT HUP INT TERM mkfifo "$fifo" -kamp send "edit -scroll -fifo $fifo *${1:-fifo}*" + +if [ "$cflag" ]; then + kamp -c "$cval" send "edit -scroll -fifo $fifo *${1:-kamp-fifo}*; focus" +else + kamp ctx -c >/dev/null # fail early if there is no client + kamp send "edit -scroll -fifo $fifo *${1:-kamp-fifo}*; focus" +fi + cat >"$fifo"