Browse Source

Update epipe script

Samuel W. Flint 1 year ago
parent
commit
48432fd94e
1 changed files with 13 additions and 10 deletions
  1. 13 10
      epipe

+ 13 - 10
epipe

@@ -1,24 +1,29 @@
 #!/bin/sh
 
-emacs=emacsclient
-show="YES"
+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-b NAME\t Rename buffer to NAME."
-    echo -e "\t-v\t Disable verbose mode (do not print output)."
+    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="NO"; shift;;
+        -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
@@ -29,14 +34,14 @@ elisp="
 (let ((find-file-hook
        '((lambda ()
            (turn-on-auto-revert-tail-mode)
-           (setq auto-revert-interval 1)
+           (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\"))))))
+             (rename-buffer \"$buffer_name\"))))))
   (find-file \"$tmpfile\"))"
-$emacs --eval "$elisp" > /dev/null &
+${EPIPE_EMACS} --eval "$elisp" > /dev/null &
 
 if [ "$show" = "NO" ]
 then
@@ -44,5 +49,3 @@ then
 else
     tee $tmpfile
 fi
-
-