#!/usr/bin/env bash
help_text="
usage: gen_bash [options] <filename>
-h : This help text.
-b : Basic bash script only.
"
help_line="Generates a bash script from a template"
web_desc_line="Generates a bash script from a template"
basic_yn=n
case $1 in
-h|--help)
echo "$help_text"
exit
;;
-b|--basic)
basic_yn=y
shift
;;
esac
new_file="$1"
if [[ "$1" == "" ]]; then
echo "Error: no filename provided"
echo "$help_text"
exit 1
fi
if [[ -f "$new_file" ]]; then
echo "Error: file: $1 already exists"
exit 1
fi
if [[ $basic_yn == y ]]; then
cat "$B/bash-basic-script-example" | sed "s/<<FILENAME>>/$1/" > "$new_file"
else
cat "$B/bash-script-example" > "$new_file"
fi
chmod +x "$new_file"
read -p "Edit $1? c - code, g - gvim, n - No [cgN]: " cgn
case ${cgn^} in
C)
code "$new_file"
;;
G)
gvim "$new_file"
;;
esac