From 972508e74de6e41fd2633b1405c032935f8d9a3c Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 12 Dec 2019 11:02:24 -0600 Subject: [PATCH] WIP pipeline --- apps/neovim/settings.vim | 2 +- bin/fsw | 18 +++++++++++-- bin/pipeline | 55 ++++++++++++++++++++++++++++++++++++++++ bin/upload | 2 ++ readme.md | 1 + setup | 1 + shell/bash/aliases | 3 ++- shell/bash/bashrc | 4 +-- 8 files changed, 80 insertions(+), 6 deletions(-) create mode 100755 bin/pipeline diff --git a/apps/neovim/settings.vim b/apps/neovim/settings.vim index 349d8a7..88eb70a 100644 --- a/apps/neovim/settings.vim +++ b/apps/neovim/settings.vim @@ -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 diff --git a/bin/fsw b/bin/fsw index 57a35a5..08331cd 100755 --- a/bin/fsw +++ b/bin/fsw @@ -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 diff --git a/bin/pipeline b/bin/pipeline new file mode 100755 index 0000000..b39ea47 --- /dev/null +++ b/bin/pipeline @@ -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 silent write' + --cmd 'autocmd BufWrite * sleep 500m | checktime' + +# TODO: vim set autoread diff --git a/bin/upload b/bin/upload index 38936ac..18882c7 100755 --- a/bin/upload +++ b/bin/upload @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# TODO: progress bar! + HOST="ld" f="${1}" diff --git a/readme.md b/readme.md index 479de71..67087df 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/setup b/setup index 1465e2a..8050fed 100755 --- a/setup +++ b/setup @@ -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" diff --git a/shell/bash/aliases b/shell/bash/aliases index e19c153..71eba07 100644 --- a/shell/bash/aliases +++ b/shell/bash/aliases @@ -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" diff --git a/shell/bash/bashrc b/shell/bash/bashrc index 2543424..c1b595a 100644 --- a/shell/bash/bashrc +++ b/shell/bash/bashrc @@ -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"