Index

I just wrote a small pipe editor inspired by vipe. It’s a short shell script:

#!/bin/sh

case $1 in
  -h|--help)
      cat <<EOF
Usage:
${0} [command] [arguments...]

${0} is a pipe editor. It read its standard input, opens in a text editor,
and write the result to its standard output.

EXAMPLES

Edit a file a write it into another file:
  cat input | ${0} > output
or
  ${0} < input > output

Edit a file using gvim --nofork, a pipe the result into wc:
  ${0} gvim --nofork < input | wc

To call ${0} without any input, use /dev/null:
  ${0} < /dev/null
EOF
      exit
esac

args=$*

function edit {
  ${args:-${VISUAL:-${EDITOR:-vi}}} $*
}

tmp=`mktemp`
cat > $tmp
edit $tmp < /dev/tty > /dev/tty
cat < $tmp
rm $tmp