Pipeline stuff
This commit is contained in:
parent
3f00303e97
commit
7fa86968e1
5 changed files with 34 additions and 47 deletions
|
@ -1,11 +1,13 @@
|
|||
scriptencoding utf-8
|
||||
set fileencoding=utf8
|
||||
|
||||
let $vimdir = $HOME.'/.vim'
|
||||
if has('nvim')
|
||||
let $vimdir = $XDG_CONFIG_HOME.'/nvim'
|
||||
endif
|
||||
|
||||
" load a per-environment file if one exists
|
||||
if filereadable("$ENV_PATH/vim")
|
||||
source "$ENV_PATH/vim"
|
||||
if filereadable($ENV_PATH."/vim")
|
||||
source $ENV_PATH."/vim"
|
||||
endif
|
||||
|
||||
call plug#begin($vimdir.'/bundle')
|
||||
|
|
2
bin/cdp
2
bin/cdp
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# TODO: needs fixing...?
|
||||
[ -f "$HOME/.fzf.bash" ] && source "$HOME/.fzf.bash" && $(__fzf_cd__)
|
||||
cd "$(dirname "$(fzf)")"
|
||||
|
|
24
bin/fsw
24
bin/fsw
|
@ -4,8 +4,8 @@ _VERSION="0.2.0"
|
|||
|
||||
function help() {
|
||||
I=" "
|
||||
cat <<USAGE
|
||||
fsw - run a command when a file is modified
|
||||
cat << USAGE
|
||||
fsw - run a command when a file is modified - v$_VERSION
|
||||
|
||||
Usage:
|
||||
${I}fsw <command> [filter] [dirs...]
|
||||
|
@ -41,11 +41,17 @@ USAGE
|
|||
}
|
||||
|
||||
dbg() {
|
||||
if [[ ! -z ${FSW_DEBUG+x} ]]; then
|
||||
echo -e "[debug] fsw: $@"
|
||||
if [[ -n ${FSW_DEBUG+x} ]]; then
|
||||
echo -e "[debug] fsw: $*"
|
||||
fi
|
||||
}
|
||||
|
||||
contains_element () {
|
||||
local e match="$1"; shift
|
||||
for e; do [[ "$e" == "$match" ]] && return 0; done
|
||||
return 1
|
||||
}
|
||||
|
||||
if [[ $1 = '-h' ]] || [[ $1 = '--help' ]] || [[ -z $1 ]]; then
|
||||
help
|
||||
exit 0
|
||||
|
@ -64,16 +70,20 @@ if [[ -e $FILTER ]]; then
|
|||
echo "It looks like your filter is an actual file. I'll just watch that for you."
|
||||
DIRS=("${FILTER}")
|
||||
fi
|
||||
while [[ ! -z $1 ]] && $(realpath $1) &> /dev/null; do
|
||||
while [[ -n $1 ]] && realpath "$1" &> /dev/null; do
|
||||
dbg "Directory: ${1}"
|
||||
DIRS+=("$1"); shift
|
||||
done
|
||||
inotifywait -m -e "${FSW_EVENTS}" -r "${DIRS[@]}" 2>&1 \
|
||||
inotifywait -m -e "${FSW_EVENTS},delete,delete_self" -r "${DIRS[@]}" 2>&1 \
|
||||
| grep --line-buffered -v ' Beware: since -r was given, this may take a while!' \
|
||||
| while read -r dir events filename; do
|
||||
if contains_element "$dir" "${DIRS[@]}" && [[ $events =~ "delete" ]]; then
|
||||
echo "One of the watched directories (\"$dir\") was deleted. Exiting..."
|
||||
exit 75
|
||||
fi
|
||||
if [[ "$dir $events" = "Watches established." ]]; then
|
||||
echo "Ready."
|
||||
dbg "Directory: ${DIRS[@]}"
|
||||
dbg "Directory: ${DIRS[*]}"
|
||||
else
|
||||
export FSW_FILENAME="$filename"
|
||||
export FSW_DIR="$dir"
|
||||
|
|
2
bin/fswi
2
bin/fswi
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
eval "${1}"
|
||||
fsw "$@"
|
||||
exec fsw "$@"
|
||||
|
|
45
bin/pipeline
45
bin/pipeline
|
@ -8,7 +8,7 @@ if [ -n "${1+x}" ]; then
|
|||
mkdir -p "$pdir"
|
||||
if [ -z ${1+x} ]; then
|
||||
td="$(mktemp -p "$pdir" -d "tmp_pipeline.XXXXXXXX")"
|
||||
cleanup_trap="rm -rf \"$td\""
|
||||
trap "rm -rf '$td'" EXIT
|
||||
else
|
||||
td="$pdir/$1"; shift
|
||||
mkdir -p "$td"
|
||||
|
@ -17,48 +17,23 @@ if [ -n "${1+x}" ]; then
|
|||
else
|
||||
td="$(mktemp --tmpdir -d pipeline.XXXXXXXX)"
|
||||
transform="$td/transform"
|
||||
cleanup_trap="rm -rf \"$td\""
|
||||
trap "rm -rf '$td'" EXIT
|
||||
fi
|
||||
|
||||
[ ! -e "$transform" ] && \
|
||||
printf "#!/usr/bin/env bash\n# for %s\n\nbase64" "${td}" > "$transform"
|
||||
printf "#!/usr/bin/env bash\n# you must save this buffer manually\n# for %s\n
|
||||
base64" "${td}" > "$transform"
|
||||
|
||||
in="$td/in"
|
||||
[ -n "${1+x}" ] && in="${1}" && shift
|
||||
out="$td/out"
|
||||
[ -n "${1+x}" ] && out="${1}" && shift
|
||||
in="$td/in"; [ -n "${1+x}" ] && in="${1}" && shift
|
||||
out="$td/out"; [ -n "${1+x}" ] && 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" 2>&1 &
|
||||
chmod +x "$transform"
|
||||
|
||||
watcher="$!"
|
||||
# TODO: saved inputs?
|
||||
echo "Hello World" > "$in"
|
||||
|
||||
if [ -z "${cleanup_trap+x}" ]; then
|
||||
trap "kill \"$watcher\"" EXIT
|
||||
else
|
||||
trap "${cleanup_trap}; kill \"$watcher\"" EXIT
|
||||
fi
|
||||
|
||||
job="$(echo "let g:pipeline_job_id = jobstart(['inotifywait', '-m', '-e', 'close_write', '${out}'], {'detach':1,'on_stdout':{j,d,e->execute('checktime')}})" | tr "'" '"')"
|
||||
|
||||
echo $job >> "$log"
|
||||
|
||||
# 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 -V9"$td/vimlog" \
|
||||
-o "$in" "$transform" "$out" \
|
||||
--cmd "$job" \
|
||||
--cmd 'set updatetime=250' \
|
||||
--cmd 'autocmd CursorHold,CursorHoldI <buffer> silent write' \
|
||||
--cmd 'autocmd VimLeave call jobstop(g:pipeline_job_id)' \
|
||||
--cmd "$job"
|
||||
env PIPELINE_IN="$id" PIPELINE_TRANSFORM="$transform" PIPELINE_OUT="$out" nvim --cmd "source $DOTFILES_PATH/apps/neovim/scripts/pipeline.vim"
|
||||
|
|
Reference in a new issue