This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/bin/pipeline

68 lines
1.6 KiB
Text
Raw Normal View History

2019-12-12 11:02:24 -06:00
#!/usr/bin/env bash
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"
else
td="$(mktemp --tmpdir -d pipeline.XXXXXXXX)"
transform="$td/transform"
cleanup_trap="rm -rf \"$td\""
fi
if [[ ! -e "$transform" ]]; then
echo -e "#!/usr/bin/env bash\n# for ${td}\n\nbase64" > "$transform"
fi
in="$td/in"
2019-12-12 13:00:03 -06:00
if [[ ! -z "${1+x}" ]]; then
in="${1}"; shift
fi
2019-12-12 11:02:24 -06:00
out="$td/out"
2019-12-12 13:00:03 -06:00
if [[ ! -z "${1+x}" ]]; then
out="${1}"; shift
fi
2019-12-12 11:02:24 -06:00
2019-12-12 13:31:18 -06:00
# TODO: if no logging, log="/dev/null"
log="$td/log"
2019-12-12 11:02:24 -06:00
chmod +x "$transform"
echo "Hello World" > "$in"
2019-12-12 13:31:18 -06:00
touch "$log"
2019-12-12 11:02:24 -06:00
2019-12-12 13:00:03 -06:00
fswi \
2019-12-12 13:31:18 -06:00
"bash -c 'cd \"$td\" && < \"$in\" \"$transform\" | tee \"$out\"'" \
2019-12-12 11:02:24 -06:00
'in$|transform$' \
2019-12-12 13:31:18 -06:00
"$td" "$pdir" &> "$log" &
2019-12-12 11:02:24 -06:00
watcher="$!"
if [[ -z ${cleanup_trap+x} ]]; then
trap "kill \"$watcher\"" EXIT
else
trap "${cleanup_trap}; kill \"$watcher\"" EXIT
fi
2019-12-12 13:00:03 -06:00
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
2019-12-12 11:02:24 -06:00
nvim \
--cmd 'set shm+=atIWF' \
--cmd 'set shm-=Oo' \
-o "$in" "$transform" "$out" \
--cmd 'set autoread' \
--cmd 'set updatetime=250' \
2019-12-12 13:00:03 -06:00
--cmd 'autocmd CursorHold,CursorHoldI <buffer> silent write' \
--cmd "$(<<< "$job" tr "'" '"')"