diff --git a/apps/neovim/init.vim b/apps/neovim/init.vim index e2280bc..685036b 100644 --- a/apps/neovim/init.vim +++ b/apps/neovim/init.vim @@ -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') diff --git a/bin/cdp b/bin/cdp index d8b12a7..dd354d0 100755 --- a/bin/cdp +++ b/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)")" diff --git a/bin/fsw b/bin/fsw index 08331cd..56898aa 100755 --- a/bin/fsw +++ b/bin/fsw @@ -4,8 +4,8 @@ _VERSION="0.2.0" function help() { I=" " - cat < [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" diff --git a/bin/fswi b/bin/fswi index 9eb7a8c..fc53f8b 100755 --- a/bin/fswi +++ b/bin/fswi @@ -1,4 +1,4 @@ #!/usr/bin/env bash eval "${1}" -fsw "$@" +exec fsw "$@" diff --git a/bin/pipeline b/bin/pipeline index 70d978e..1908407 100755 --- a/bin/pipeline +++ b/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 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"