diff options
Diffstat (limited to 'os1w5/textfrutter.sh')
-rwxr-xr-x | os1w5/textfrutter.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/os1w5/textfrutter.sh b/os1w5/textfrutter.sh new file mode 100755 index 0000000..8c8ffe3 --- /dev/null +++ b/os1w5/textfrutter.sh @@ -0,0 +1,52 @@ +#!/bin/dash +TO_UPPER="" +TO_LOWER="" +PREFIX= +SUFFIX= +FILTER_VOWELS="" +ARGC=0 + +usage() { + cat << EOF +usage: $0 [-luvh] [-p prefix] [-s suffix] [inputs...] + +options: + -l convert inputs to lowercase + -u convert inputs to uppercase + -v remove vowels from inputs + -h show help + -p prefix add \`prefix\` to each line before inputs + -s suffix add \`suffix\` to each line after inputs + +notes: + if -l and -u are specified at the same time, the lowercase option will have + precedence +EOF + exit $1 +} + +while getopts dulhp:s:v OPT; do + [ $OPTIND -gt $ARGC ] && ARGC=$OPTIND + case $OPT in + u) TO_UPPER="y" ;; + l) TO_LOWER="y" ;; + h) usage 0 ;; + p) PREFIX=$OPTARG ;; + s) SUFFIX=$OPTARG ;; + v) FILTER_VOWELS="y" ;; + \?|*) usage 1 ;; + esac +done + +[ $(( $# - $ARGC )) -lt 0 ] && echo "please provide some input" && usage 1 + +shift $(( ARGC - 1 )) + +while [ -n "$1" ]; do + OUT="$1" + [ -n "$TO_UPPER" ] && OUT="`echo "$OUT" | sed 's/./\U\0/g'`" + [ -n "$TO_LOWER" ] && OUT="`echo "$OUT" | sed 's/./\L\0/g'`" + [ -n "$FILTER_VOWELS" ] && OUT="`echo "$OUT" | sed 's/[aeuio]//g'`" + echo "$PREFIX$OUT$SUFFIX" + shift +done |