Emacs pipe

# FILE: ~/.zshrc
# Open in Terminal

alias e='emacsclient --alternate-editor="" --tty'
# FILE: ~/.bin/ec
# Open file in Emacs existing Frame, otherwise create a new frame

#!/usr/bin/env bash

framelist=`emacsclient -a '' --eval '(frame-list)' 2>/dev/null | grep -o '#<frame'`

if [ "$(echo "$framelist" | sed -n '$=')" -ge 2 ]; then
    # if a frame already exist
    emacsclient --alternate-editor="" --no-wait "[email protected]"
else
    # create one if there is no frame yet
    emacsclient --alternate-editor="" --create-frame --no-wait "[email protected]"
fi
# FILE: ~/.bin/ep
# Emacs Pipe

#!/bin/sh
TMP=$(mktemp) && cat > $TMP && ec $TMP ; rm $TMP
# Test
echo 'hello world' | ep
> echo "Hello!" | emacs --batch --eval "(princ (read))"
Lisp expression: Hello! # no newline here
> echo "Hello!" | emacs --batch --eval "(prin1 (read))"
Lisp expression: Hello! # no newline here
> echo "Hello!" | emacs --batch --eval "(print (read))"
Lisp expression: 
Hello!
> echo "Hello!" | emacs --batch --eval '(message "%s" (read))'
Lisp expression: Hello!
> echo "Hello!" | emacs --batch --eval '(message "%s" (read))' 1> /dev/null
Hello!
> echo "Hello!" | (emacs --batch --eval '(message "%s" (read))' 3>&2 2>&1 1>&3) 2> /dev/null
Hello!
> echo "Hello!" | (emacs --batch --eval '(message "%s" (read))' 3>&2 2>&1 1>&3)
Lisp expression: Hello!

不知道有没有正常的方法把Lisp expression:去掉。。。

(read (read-from-minibuffer ""))

vipe from moreutils了解下

2 个赞

原来是PROMPT。。。

然而实际上从没用到过这个。不知道有啥使用场景?

我也不知道,很少写shell脚本,不然也不会问expand tilde的这种shell低级问题。

个人想的比较适合的场景是类似AUR Helper那样,执行前允许你确认一遍,再改一下输入什么的