vipe (826B)
1 #!/usr/bin/env bash 2 3 # 4 # vipe(1) - Pipe in and out of $EDITOR 5 # 6 # (c) 2014 Julian Gruber <julian@juliangruber.com>. 7 # MIT licensed. 8 # 9 # Example: 10 # 11 # $ echo foo | vipe | gist 12 # $ vipe | gist 13 # 14 # This is a lightweight bash only version. For the original impementation in 15 # python, check https://github.com/madx/moreutils/blob/master/vipe 16 # 17 18 # version 19 20 VERSION="0.1.0" 21 22 # usage 23 24 if [ ${1} ]; then 25 case "${1}" in 26 "-h") 27 echo "usage: vipe [-hV]" 28 exit 0 ;; 29 "-V") 30 echo "$VERSION" 31 exit 0 ;; 32 *) 33 echo "unknown option: \"${1}\"" 34 echo "usage: vipe [-hV]" 35 exit 1 36 esac 37 fi 38 39 # temp file 40 41 t=/tmp/vipe.$$.txt 42 touch $t 43 44 # read from stdin 45 46 if [ ! -t 0 ]; then 47 cat > $t 48 fi 49 50 # spawn editor with stdio connected 51 52 ${EDITOR} $t < /dev/tty > /dev/tty || exit $? 53 54 # write to stdout 55 56 cat $t 57 58 # cleanup 59 60 rm $t 61