#!/bin/sh set -e usage() { cat <<'EOF' Usage: kakpipe [OPTIONS] [-- KAK_ARGS...] Edit standard input in Kakoune, then write the result to standard output. This allows Kakoune to be used in the middle of a pipeline: command1 | kakpipe | command2 Options: -s, --suffix EXT Append .EXT to the temporary file name. Enables Kakoune syntax highlighting and other filetype-related functionality. -h, --help Show this message and exit. All arguments after '--' are passed directly to Kakoune. Examples: ls | kakpipe | wc -l jq . data.json | kakpipe -s json | less command1 | kakpipe -e 'set-option window indentwidth 4' | command2 Author: Daniel Fichtinger License: BSD-0-CLAUSE EOF } while [ "$#" -gt 0 ]; do case "$1" in -h | --help) usage exit 1 ;; -s | --suffix) suffix="$2" shift 2 ;; --) shift break ;; *) break ;; esac done tmp="$(mktemp /tmp/kakpipe.XXXXXX${suffix:+.$suffix})" || exit 1 trap 'rm -f "$tmp"' EXIT INT TERM HUP cat >"$tmp" exec 3>&1 exec /dev/tty kak "$@" "$tmp" exec >&3 cat "$tmp"