diff options
-rwxr-xr-x | bin/edda | 21 | ||||
-rwxr-xr-x | bin/eds | 20 |
2 files changed, 9 insertions, 32 deletions
@@ -4,25 +4,10 @@ # Give up completely if no BASH_VERSINFO (<2.0) [ -n "$BASH_VERSINFO" ] || exit -# Define usage function -usage() { - printf 'USAGE: %s [OPTS] [--] FILE1 [FILE2...]\n' "$self" -} - -# Need at least one file -if ! (($#)) ; then - usage >&2 - exit 1 -fi - # Parse options out, give help if necessary declare -a opts for arg ; do case $arg in - --help|-h|-\?) - usage - exit - ;; --) shift break @@ -34,6 +19,12 @@ for arg ; do esac done +# Need at least one file after options are parsed out +if ! (($#)) ; then + printf >&2 'edda: Need at least one file\n' + exit 2 +fi + # Duplicate stdin into a file, which we'll remove on exit stdin=$(mktemp -t "$self".XXXXXX) || exit cleanup() { @@ -1,24 +1,13 @@ #!/usr/bin/env bash # Create and edit executable scripts in a directory EDSPATH (defaults to ~/.local/bin) -self=eds # Give up completely if no BASH_VERSINFO (<2.0) [ -n "$BASH_VERSINFO" ] || exit -# Define a function to show usage -usage() { - printf 'USAGE: %s [EDITOR_OPTS] [--] FILE1 [FILE2...]\n' \ - "$self" -} - # Process options, including detecting requests for help declare -a opts for arg ; do case $arg in - --help|-h|-\?) - usage - exit 0 - ;; --) shift break @@ -27,16 +16,13 @@ for arg ; do shift opts[${#opts[@]}]=$arg ;; - *) - break - ;; esac done -# If no arguments left, spit usage as an error and bail +# Need at least one file after options are parsed out if ! (($#)) ; then - usage >&2 - exit 1 + printf >&2 'eds: Need at least one script name\n' + exit 2 fi # Create the script directory if it doesn't exist yet |