From 8b50c699652e39812024af2c34973c6359302c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 6 Jun 2021 21:41:54 +0200 Subject: Read stdin if not a tty --- vp | 17 ++++++++++++++++- vpeval | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/vp b/vp index 366a1b6..88bfdf9 100755 --- a/vp +++ b/vp @@ -1,2 +1,17 @@ #!/bin/sh -exec vi +':so /usr/local/etc/vprc' "$@" `mktemp` + +VPIN= +if [ ! -t 0 ]; then + VPIN=`mktemp` + cat > "$VPIN" +fi +export VPIN + +f=`mktemp` +/dev/tty vi +':so /usr/local/etc/vprc' "$@" "$f" +[ "$(wc -c "$f" | awk '{print $1}')" -eq 0 ] && rm "$f" + +if [ ! -z "$VPIN" ]; then + cat "$VPIN" + rm "$VPIN" +fi diff --git a/vpeval b/vpeval index 4c5b785..3031cff 100755 --- a/vpeval +++ b/vpeval @@ -1,2 +1,7 @@ #!/bin/sh -echo "$(eval "$(sed '/^#/d')" 2>&1)" | sed 's/^/# /' +{ + if [ -z "$VPIN" ] + then eval "$(sed '/^#/d')" 2>&1 + else eval "$(sed '/^#/d')" 2>&1 <"$VPIN" + fi +} | sed 's/^/# /' -- cgit v1.2.3