#!/usr/bin/env bash
SAVED_PIPELINE_DIR="$DOTFILES_PATH/bin/pipelines"
mkdir -p "$SAVED_PIPELINE_DIR"
if [[ ! -z "${1+x}" ]]; then
pdir="$SAVED_PIPELINE_DIR/$1"; shift
mkdir -p "$pdir"
if [[ -z ${1+x} ]]; then
td="$(mktemp -p "$pdir" -d "tmp_pipeline.XXXXXXXX")"
cleanup_trap="rm -rf \"$td\""
else
td="$pdir/$1"; shift
mkdir -p "$td"
fi
transform="$pdir/transform"
td="$(mktemp --tmpdir -d pipeline.XXXXXXXX)"
transform="$td/transform"
if [[ ! -e "$transform" ]]; then
echo -e "#!/usr/bin/env bash\n# for ${td}\n\nbase64" > "$transform"
in="$td/in"
in="${1}"; shift
out="$td/out"
out="${1}"; shift
# TODO: if no logging, log="/dev/null"
log="$td/log"
chmod +x "$transform"
echo "Hello World" > "$in"
touch "$log"
fswi \
"bash -c 'cd \"$td\" && < \"$in\" \"$transform\" | tee \"$out\"'" \
'in$|transform$' \
"$td" "$pdir" &> "$log" &
watcher="$!"
if [[ -z ${cleanup_trap+x} ]]; then
trap "kill \"$watcher\"" EXIT
trap "${cleanup_trap}; kill \"$watcher\"" EXIT
job="call jobstart(['inotifywait', '-m', '-e', 'close_write', '${out}'], {'on_stdout':{j,d,e->execute('checktime')}})"
# this will only autosave (and therefore autoreload) for the out buffer (since
# it was opened last) - autosaving (and therefore autorunning) is potentially
# very scary
nvim \
--cmd 'set shm+=atIWF' \
--cmd 'set shm-=Oo' \
-o "$in" "$transform" "$out" \
--cmd 'set autoread' \
--cmd 'set updatetime=250' \
--cmd 'autocmd CursorHold,CursorHoldI <buffer> silent write' \
--cmd "$(<<< "$job" tr "'" '"')"
# SAVED_PIPELINE_DIR="$EDFP/pipelines"
# mkdir -p "$SAVED_PIPELINE_DIR"
# if [[ ! -z "${1+x}" ]]; then
# pdir="$SAVED_PIPELINE_DIR/$1"; shift
# mkdir -p "$pdir"
# if [[ -z ${1+x} ]]; then
# td="$(mktemp -p "$pdir" -d "tmp_pipeline.XXXXXXXX")"
# cleanup_trap="rm -rf \"$td\""
# else
# td="$pdir/$1"; shift
# mkdir -p "$td"
# fi
# transform="$pdir/transform"
# td="$(mktemp --tmpdir -d pipeline.XXXXXXXX)"
# transform="$td/transform"
# if [[ ! -e "$transform" ]]; then
# echo -e "#!/usr/bin/env bash\n# for ${td}\n\nbase64" > "$transform"
# in="$td/in"
# in="${1}"; shift
# out="$td/out"
# out="${1}"; shift
# # TODO: if no logging, log="/dev/null"
# log="$td/log"
# chmod +x "$transform"
# echo "Hello World" > "$in"
# touch "$log"
# fswi \
# "bash -c 'cd \"$td\" && < \"$in\" \"$transform\" | tee \"$out\"'" \
# 'in$|transform$' \
# "$td" "$pdir" &> "$log" &
# watcher="$!"
# if [[ -z ${cleanup_trap+x} ]]; then
# trap "kill \"$watcher\"" EXIT
# trap "${cleanup_trap}; kill \"$watcher\"" EXIT
# job="call jobstart(['inotifywait', '-m', '-e', 'close_write', '${out}'], {'on_stdout':{j,d,e->execute('checktime')}})"
# # this will only autosave (and therefore autoreload) for the out buffer (since
# # it was opened last) - autosaving (and therefore autorunning) is potentially
# # very scary
# nvim \
# --cmd 'set shm+=atIWF' \
# --cmd 'set shm-=Oo' \
# -o "$in" "$transform" "$out" \
# --cmd 'set autoread' \
# --cmd 'set updatetime=250' \
# --cmd 'autocmd CursorHold,CursorHoldI <buffer> silent write' \
# --cmd "$(<<< "$job" tr "'" '"')"