diff --git a/templates/TEMPLATE.sh.tpl b/templates/TEMPLATE.sh.tpl index a30c70d8a5c6652f5de29c779d6ed12ce9a10e4f..a32d0988fde70fe71626d08003f06be8aa9f9305 100644 --- a/templates/TEMPLATE.sh.tpl +++ b/templates/TEMPLATE.sh.tpl @@ -27,15 +27,15 @@ # Treat unset variables as errors. set -u -program="`(file-name-nondirectory (buffer-file-name))`" -version="${1:version}" +PROGRAM="`(file-name-nondirectory (buffer-file-name))`" +VERSION="${1:version}" function usage() { cat <<EOF -\$program \$version, ${2:short description } +\$PROGRAM \$VERSION, ${2:short description } Usage: - \$program [OPTIONS] ${3:arguments} + \$PROGRAM [OPTIONS] ${3:arguments} EOF } @@ -43,7 +43,7 @@ function short_help() { cat <<EOF \$(usage) -For more details see \$program -h. +For more details see \$PROGRAM -h. EOF } @@ -51,9 +51,9 @@ function long_help() { cat <<EOF \$(usage) -\$program ${4:long description} +\$PROGRAM ${4:long description} -\$program accepts the following options: +\$PROGRAM accepts the following options: -q Quiet mode. @@ -70,7 +70,7 @@ EOF function version() { cat <<EOF -\$program, version \$version +\$PROGRAM, version \$VERSION +-----------------------------------------------------------------------+ | Copyright (C) `(format-time-string "%Y")`, Branko Majic <branko@majic.rs> | @@ -94,50 +94,50 @@ EOF # Set-up colours for message printing if we're not piping and terminal is # capable of outputting the colors. -_color_terminal=\$(tput colors 2>&1) -if [[ -t 1 ]] && (( _color_terminal > 0 )); then - _text_bold=\$(tput bold) - _text_white=\$(tput setaf 7) - _text_blue=\$(tput setaf 6) - _text_green=\$(tput setaf 2) - _text_yellow=\$(tput setaf 3) - _text_red=\$(tput setaf 1) - _text_reset=\$(tput sgr0) +_COLOR_TERMINAL=\$(tput colors 2>&1) +if [[ -t 1 ]] && (( _COLOR_TERMINAL > 0 )); then + _TEXT_BOLD=\$(tput bold) + _TEXT_WHITE=\$(tput setaf 7) + _TEXT_BLUE=\$(tput setaf 6) + _TEXT_GREEN=\$(tput setaf 2) + _TEXT_YELLOW=\$(tput setaf 3) + _TEXT_RED=\$(tput setaf 1) + _TEXT_RESET=\$(tput sgr0) else - _text_bold="" - _text_white="" - _text_blue="" - _text_green="" - _text_yellow="" - _text_red="" - _text_reset="" + _TEXT_BOLD="" + _TEXT_WHITE="" + _TEXT_BLUE="" + _TEXT_GREEN="" + _TEXT_YELLOW="" + _TEXT_RED="" + _TEXT_RESET="" fi # Set-up functions for printing coloured messages. function debug() { - if [[ $debug != 0 ]]; then - echo "\${_text_bold}\${_text_blue}[DEBUG]\${_text_reset}" "\$@" + if [[ $DEBUG != 0 ]]; then + echo "\${_TEXT_BOLD}\${_TEXT_BLUE}[DEBUG]\${_TEXT_RESET}" "\$@" fi } function info() { - if [[ $quiet == 0 ]]; then - echo "\${_text_bold}\${_text_white}[INFO] \${_text_reset}" "\$@" + if [[ $QUIET == 0 ]]; then + echo "\${_TEXT_BOLD}\${_TEXT_WHITE}[INFO] \${_TEXT_RESET}" "\$@" fi } function success() { - if [[ $quiet == 0 ]]; then - echo "\${_text_bold}\${_text_green}[OK] \${_text_reset}" "\$@" + if [[ $QUIET == 0 ]]; then + echo "\${_TEXT_BOLD}\${_TEXT_GREEN}[OK] \${_TEXT_RESET}" "\$@" fi } function warning() { - echo "\${_text_bold}\${_text_yellow}[WARN] \${_text_reset}" "\$@" >&2 + echo "\${_TEXT_BOLD}\${_TEXT_YELLOW}[WARN] \${_TEXT_RESET}" "\$@" >&2 } function error() { - echo "\${_text_bold}\${_text_red}[ERROR]\${_text_reset}" "\$@" >&2 + echo "\${_TEXT_BOLD}\${_TEXT_RED}[ERROR]\${_TEXT_RESET}" "\$@" >&2 } # Define error codes. @@ -145,8 +145,8 @@ SUCCESS=0 ERROR_ARGUMENTS=1 # Disable debug and quiet modes by default. -debug=0 -quiet=0 +DEBUG=0 +QUIET=0 # If no arguments were given, just show usage help. if [[ -z \${1-} ]]; then @@ -157,8 +157,8 @@ fi # Parse the arguments while getopts "qdvh" opt; do case "\$opt" in - q) quiet=1;; - d) debug=1;; + q) QUIET=1;; + d) DEBUG=1;; v) version exit "$SUCCESS";; h) long_help @@ -171,7 +171,7 @@ i=\$OPTIND shift \$(( i-1 )) # Quiet and debug are mutually exclusive. -if [[ \$quiet != 0 && \$debug != 0 ]]; then +if [[ \$QUIET != 0 && \$DEBUG != 0 ]]; then error "Quiet and debug options are mutually exclusive." exit "\$ERROR_ARGUMENTS" fi