Skip to content

Instantly share code, notes, and snippets.

@RicherMans
Created May 23, 2017 08:07
Show Gist options
  • Save RicherMans/bb74a246f2d5c4463c07617dec672c6d to your computer and use it in GitHub Desktop.
Save RicherMans/bb74a246f2d5c4463c07617dec672c6d to your computer and use it in GitHub Desktop.
bashargs.sublime-snippet
<snippet>
<content><![CDATA[
# Arguments: ${1:arg}
function usage {
echo "Error, please use the following parameters:" # unknown option
echo "./$TM_FILENAME ${1/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][a-zA-Z0-9_]*)\s*(=[^,]*)?(,\s*|$)/(?2:-$2 /g} ..."
exit
}
[[ \$# -lt $2 ]] && usage
while [[ \$# -gt 1 ]]
do
key="\$1"
case \$key in
${1/(\A\s*,\s*\Z)|,?\s*([A-Za-z_][a-zA-Z0-9_]*)\s*(=[^,]*)?(,\s*|$)/(?2:\t-$2\)\n\t$2="\$2"\n\tshift\n\t;;\n/g}
*)
usage
;;
esac
shift # past argument or value
done
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>while</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.shell</scope>
<description>Adds default argparsing for bash</description>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment