WolfgangMehner / bash-support

Edit Bash scripts in Vim/gVim. Insert code snippets, run, check, and debug the code and look up help.
91 stars 15 forks source link

Issue with editing template to have default value show up in skel correctly.. #3

Open Guyverix opened 1 year ago

Guyverix commented 1 year ago

I have run into a bit of trouble with the Template file. I am attempting to add a hard coded set of default values into the skeleton that is created with a new file. Overall the issue is minor, as it is more of a format problem than a real code bug. It is just frustrating as it makes the generated skeleton look sloppy.

Here is what I am attempting to add:

== Skeleton.script-set == nomenu, below ==
#set -o nounset                        # Treat unset variables as an error
#set -o pipefai                        # Any non-zero exits in pipes fail
#set -e                                # Any non-zero exit is a failure
#canonicalpath=`readlink -f $0`                 # Breaks Mac due to readlink differences
#canonicaldirname=`dirname ${canonicalpath}`/.. # Breaks Mac
#samedirname=`dirname ${canonicalpath}`         # Breaks Mac

usage() {
  cat << EOF

EOF
}

while getopts "hx" OPTION; do
  case ${OPTION} in
    h) usage ; exit 0 ;;
    x) export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'; set -x ;;
    *) echo "Unexpected argument given.  Try -h.  Used: $@ ; exit 2 ;;
  esac    # --- end of case ---
done
== ENDTEMPLATE ==

And this is what the generated output looks like:

usage() {
        cat << EOF

                EOF
}

while getopts "hx" OPTION; do
case ${OPTION} in
h) usage ; exit 0 ;;
x) export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'; set -x ;;
*) echo "Unexpected argument given.  Try -h.  Used: $@ ; exit 2 ;;
esac    # --- end of case ---
done

As you can see, I loose some formatting and gain goofed up indents in other areas. What would be the correct way to deal with this in the Template file?

Guyverix commented 1 year ago

I guess I should clarify a bit. My scripts always have a help system, and an option to debug. Thats why I am attempting to add to the skeleton generation rather than trying to build into the menu system to add manually every time I build out a new script.