3 Commits c40b12b67b ... f43ba0eb58

Author SHA1 Message Date
  Samuel W. Flint f43ba0eb58 Support spaces in file names & direct piping to "listened" 1 year ago
  Samuel W. Flint 48432fd94e Update epipe script 1 year ago
  Samuel W. Flint 11a4d098f0 Add in epipe script 1 year ago
2 changed files with 61 additions and 4 deletions
  1. 51 0
      epipe
  2. 10 4
      pod

+ 51 - 0
epipe

@@ -0,0 +1,51 @@
+#!/bin/sh
+
+EPIPE_EMACS=${EPIPE_EMACS:-emacs}
+show="NO"
+buffer_name=""
+interval=1
+
+usage() {
+    self=$(basename $0)
+    echo "$self redirects stdin to an emacs buffer"
+    echo -e "Example: 'echo \"foo\" | epipe'"
+    echo
+    echo -e "\t-e CMD\t Use emacs CMD."
+    echo -e "\t-b NAME\t Piped-to buffer should have NAME."
+    echo -e "\t-I INT\t Use INT as revert interval."
+    echo -e "\t-v\t Verbose mode also prints output to stdout."
+    echo -e "\t-h\t Shows this message."
+}
+
+while [ $# -gt 0 ]
+do
+    case $1 in
+        -v) show="YES"; shift;;
+        -e) shift; EPIPE_EMACS=$1; shift;;
+        -b) shift; buffer_name=$1; shift;;
+        -I) shift; interval=$1; shift;;
+        -h) usage; exit 0; shift;;
+        *) echo "Unknown option: '$1'"; usage; exit 1;;
+    esac
+done
+
+tmpfile=$(mktemp --tmpdir=/tmp epipe.XXXXXX)
+elisp="
+(let ((find-file-hook
+       '((lambda ()
+           (turn-on-auto-revert-tail-mode)
+           (setq auto-revert-interval ${interval})
+           (auto-revert-set-timer)
+           (goto-char (point-max))
+           (cd \"$(pwd)\")
+           (unless (string-empty-p \"$buffer_name\")
+             (rename-buffer \"$buffer_name\"))))))
+  (find-file \"$tmpfile\"))"
+${EPIPE_EMACS} --eval "$elisp" > /dev/null &
+
+if [ "$show" = "NO" ]
+then
+    cat > $tmpfile
+else
+    tee $tmpfile
+fi

+ 10 - 4
pod

@@ -144,11 +144,17 @@ case "$CMD" in
     listened)
         if [ $# -lt 1 ] ; then
             FILE=$(get_cur_file)
-            git_annex_wrap metadata -s tag=listened $FILE
+            git_annex_wrap metadata -s tag=listened "${FILE}"
         else
-            for FILE in $* ; do
-                git_annex_wrap metadata -s tag=listened $FILE
-            done
+            if [ $1 = '-' ] ; then
+                cat | while read FILE ; do
+                    git_annex_wrap metadata -s tag=listened "${FILE}"
+                done
+            else
+                for FILE in $* ; do
+                    git_annex_wrap metadata -s tag=listened "${FILE}"
+                done
+            fi
         fi
         exit
         ;;