Created
October 21, 2016 23:17
-
-
Save rindeal/ee0d4859f417a9e29f2439ba7a3d233e to your computer and use it in GitHub Desktop.
`fold` command wrapper which performs text wrapping and optionally commenting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
opts="" | |
comment=0 | |
nocomment=0 | |
while getopts bchsVw: opt; do | |
case $opt in | |
b) | |
opts="$opts -b" | |
;; | |
c) | |
comment=1 | |
;; | |
h) | |
opts="$opts --help" | |
nocomment=1 | |
;; | |
s) | |
opts="$opts -s" | |
;; | |
V) | |
opts="$opts --version" | |
nocomment=1 | |
;; | |
w) | |
opts="$opts -w $OPTARG" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
/usr/bin/fold -sw80 $opts "$@" | if [ ${comment}${nocomment} -eq 10 ]; then /usr/bin/awk '{print "# "$0;}'; else /bin/cat ; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment