#!/bin/sh
name="whichvi"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
Open a program with your visual editor
Usage: whichvi PROGRAM [OPTIONS]
Options:
-h, --help print this message
-q, --quiet suppress error messages
-v, --version print version number and exit
EOF
)
. /usr/local/lib/myminiparse.sh
# open first non-option argument in editor, then exit
for arg; do
case "$arg" in
-q|--quiet)
#ignore these
;;
*)
# main routine
target=$(command -v "$arg")
if [ -z "$target" ]; then
if [ "$quiet" -eq 0 ]; then
(>&2 /usr/bin/printf "%s: No such directory '%s'\n" "$name" "$target")
fi
exit 1
else
my_visual=${VISUAL:=/usr/bin/ed}
$my_visual "$target"
exit $?
fi
;;
esac
done
# if have not exited, no program was specified
if [ "$quiet" -eq 0 ]; then
(>&2 /usr/bin/printf "Usage: whichvi PROGRAM [OPTIONS]\n")
fi
exit 1