123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/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
|