Skip to content

Instantly share code, notes, and snippets.

@jrhaberstroh
Created July 24, 2016 21:14
Show Gist options
  • Save jrhaberstroh/3e541ce3b8996a9be407dd28fbf096cb to your computer and use it in GitHub Desktop.
Save jrhaberstroh/3e541ce3b8996a9be407dd28fbf096cb to your computer and use it in GitHub Desktop.
#!/bin/bash
help()
{
sed --silent -e '/^: <<.*HELPDOC/,/^HELPDOC$/p' ${BASH_SOURCE[0]} | tail -n+2 | head -n-1
}
SRCDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
: <<'HELPDOC'
==================
newbash
==================
Creates a new bash document with my common bash options.
It makes me happy to do this.
usage:
newbash $1 Creates a new file ($1) with header and argparse set up
HELPDOC
trap help EXIT
: <<VARCHECK
${1?}
VARCHECK
trap - EXIT
cat <<'NEWBASH' > $1
#!/bin/bash
set -o nounset
set -o errexit
SRCDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
NEWBASH
chmod +x $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment