WIP pipeline

This commit is contained in:
Daniel Flanagan 2019-12-12 11:02:24 -06:00
parent fa8fe7cdcc
commit 972508e74d
8 changed files with 80 additions and 6 deletions

View file

@ -105,7 +105,7 @@ highlight GitGutterChangeDelete ctermbg=black guibg=black
hi NonText ctermfg=black guifg=black
set hidden " allows buffer switching without saving
set shortmess=Ia " hide vim intro, skip lots of file messages/prompts
set shortmess+=Ia " hide vim intro, skip lots of file messages/prompts
set history=1000
" undo files

18
bin/fsw
View file

@ -40,21 +40,32 @@ ${I}${I}${I}'.*' /etc/secrets \$HOME/.secrets
USAGE
}
dbg() {
if [[ ! -z ${FSW_DEBUG+x} ]]; then
echo -e "[debug] fsw: $@"
fi
}
if [[ $1 = '-h' ]] || [[ $1 = '--help' ]] || [[ -z $1 ]]; then
help
exit 0
fi
FSW_EVENTS="${FSW_EVENTS:-close_write}"
dbg "Events: $FSW_EVENTS"
SHELL_COMMAND="${1}"; shift
dbg "Command: $SHELL_COMMAND"
FILTER="${1}"; shift
dbg "Filter: $FILTER"
dbg "Directory: ${1}"
DIRS=("${1:-.}"); shift
if [[ -e $FILTER ]]; then
# TODO: this is a sad hack/workaround
echo "It looks like your filter is an actual file. I'll just watch that for you."
DIRS=("${FILTER}")
fi
while [[ ! -z $1 ]]; do
while [[ ! -z $1 ]] && $(realpath $1) &> /dev/null; do
dbg "Directory: ${1}"
DIRS+=("$1"); shift
done
inotifywait -m -e "${FSW_EVENTS}" -r "${DIRS[@]}" 2>&1 \
@ -62,12 +73,15 @@ inotifywait -m -e "${FSW_EVENTS}" -r "${DIRS[@]}" 2>&1 \
| while read -r dir events filename; do
if [[ "$dir $events" = "Watches established." ]]; then
echo "Ready."
dbg "Directory: ${DIRS[@]}"
else
export FSW_FILENAME="$filename"
export FSW_DIR="$dir"
export FSW_PATH="$dir$filename"
export FSW_FILE_EVENTS="$events"
export FSW_EVENT="$events $dir$filename"
<<< "$FSW_PATH" grep -P "$FILTER" > /dev/null 2>&1 && eval "${SHELL_COMMAND}"
dbg "Event:\n $(date)\n $FSW_PATH\n $FILTER\n $FSW_EVENT\n $dir $events $filename\n ${SHELL_COMMAND}"
dbg "Filtered Event: $(<<< "$FSW_PATH" grep -P "$FILTER")"
<<< "$FSW_PATH" grep -P "$FILTER" > /dev/null 2>&1 && eval "${SHELL_COMMAND}"
fi
done

55
bin/pipeline Executable file
View file

@ -0,0 +1,55 @@
#!/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"
out="$td/out"
chmod +x "$transform"
echo "Hello World" > "$in"
touch /tmp/ll.log
FSW_DEBUG=1 fswi \
"bash -c '< \"$in\" \"$transform\" > \"$out\"'" \
'in$|transform$' \
"$td" "$pdir" \ &> /tmp/ll.log &
watcher="$!"
if [[ -z ${cleanup_trap+x} ]]; then
trap "kill \"$watcher\"" EXIT
else
trap "${cleanup_trap}; kill \"$watcher\"" EXIT
fi
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 'autocmd BufWrite * sleep 500m | checktime'
# TODO: vim set autoread

View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash
# TODO: progress bar!
HOST="ld"
f="${1}"

View file

@ -78,6 +78,7 @@ Here are some bullet points on my workflow:
* Makefile instead of setup script
* [Vimux](https://github.com/benmills/vimux)?
* Nerd Fonts with ligatures and icons for Kitty
* Setup network file sharing directory
[upstream]: https://git.faceless.lytedev.io/lytedev/dotfiles

1
setup
View file

@ -1,6 +1,7 @@
#!/usr/bin/env bash
# TODO: ascii art header since I'm a leet haxx0r
# TODO: quiet mode?
dfp=$(cd "$(dirname "${BASH_SOURCE[0]}" )/" && pwd)
source "${dfp}/scripts/setup_helpers.bash"

View file

@ -108,7 +108,8 @@ alias sctlu="systemctl --user"
alias logs="sudo journalctl"
alias logsr="sudo journalctl -r"
alias logsf="sudo journalctl -f"
alias btctl="sudo bluetoothctl"
alias bt="sudo bluetoothctl"
alias btctl="bt"
alias pt="htop -t" # experimental htop tree-view-by-default
alias resrc="source \$HOME/.bashrc"
alias redshift="redshift -r -l 39.0997:-94.5786 -t 6500K:2500K"

View file

@ -12,9 +12,9 @@ NICE_HOME="$HOME"
# TODO: better logic for auto-detecting alternative home directories?
# 1. check dirname(basename $HOME)) matches username
# 2. check /home/$username
[[ $(basename "${HOME}") = "usr" ]] && NICE_HOME="$(realpath "$HOME/..")"
[[ $(basename "${HOME}") = ".home" ]] && NICE_HOME="$(realpath "$HOME/..")"
# TODO: nice home explicitly definable on a per-device (env) basis
[[ -e "${HOME}/.nice_home" ]] && NICE_HOME="$(cat "${HOME}/.nice_home")"
[[ -e "${EDFP}/.nice_home" ]] && NICE_HOME="$(cat "${EDFP}/.nice_home")"
export NICE_HOME
export NOTES_DIR="$NICE_HOME/doc/notes"