fix(emacs): correctly pass arguments to emacsclient when $2 is stdin
Diff
1diff --git a/plugins/emacs/emacsclient.sh b/plugins/emacs/emacsclient.sh
2index 53a3a428a7537f88b96998a793a7226103d87af3..25efe0d686a3b3946aca0bd17bc4b16625b1180e 100755
3--- a/plugins/emacs/emacsclient.sh
4+++ b/plugins/emacs/emacsclient.sh
5@@ -22,16 +22,17 @@ emacsfun() {
6 emacsclient --alternate-editor "" "$@"
7 }
8 9-
10-# adopted from https://github.com/davidshepherd7/emacs-read-stdin/blob/master/emacs-read-stdin.sh
11+# Adapted from https://github.com/davidshepherd7/emacs-read-stdin/blob/master/emacs-read-stdin.sh
12 # If the second argument is - then write stdin to a tempfile and open the
13 # tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh)
14 if [ $# -ge 2 -a "$2" = "-" ]; then
15+ # Create a tempfile to hold stdin
16 tempfile="$(mktemp --tmpdir emacs-stdin-$USERNAME.XXXXXXX 2>/dev/null \
17 || mktemp -t emacs-stdin-$USERNAME)" # support BSD mktemp
18+ # Redirect stdin to the tempfile
19 cat - > "$tempfile"
20- emacsfun --no-wait "$tempfile"
21- return $?
22+ # Reset $2 to the tempfile so that "$@" works as expected
23+ set -- "$1" "$tempfile" "${@:3}"
24 fi
2526 emacsfun "$@"