Browse Source

Add in epipe script

Samuel W. Flint 1 year ago
parent
commit
11a4d098f0
1 changed files with 48 additions and 0 deletions
  1. 48 0
      epipe

+ 48 - 0
epipe

@@ -0,0 +1,48 @@
+#!/bin/sh
+
+emacs=emacsclient
+show="YES"
+buffer_name=""
+
+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-h\t Shows this message."
+}
+
+while [ $# -gt 0 ]
+do
+    case $1 in
+        -v) show="NO"; shift;;
+        -b) shift; buffer_name=$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 1)
+           (auto-revert-set-timer)
+           (goto-char (point-max))
+           (cd \"$(pwd)\")
+           (unless (string-empty-p \"$buffer_name\")
+              (rename-buffer \"$buffer_name\"))))))
+  (find-file \"$tmpfile\"))"
+$emacs --eval "$elisp" > /dev/null &
+
+if [ "$show" = "NO" ]
+then
+    cat > $tmpfile
+else
+    tee $tmpfile
+fi
+
+