#!/usr/bin/env bash # ERR Trap Inheritance by shell functions, command substitutions, and subshells. set -E # Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error. set -e # Treats the use of undefined variables as an error, causing the script to exit. set -u # Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails. set -o pipefail # Cleaup script. trap cleanup SIGINT SIGTERM ERR EXIT # Get the script location and cd to it. script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) # Usage error message. usage() { cat <&2 -e "${1-}" } # Script exit implementation. die() { local msg=$1 local code=${2-1} # default exit status 1 msg "\033[0;31m$msg\033[0m" exit "$code" } # Parameter parsing implementation. parse_params() { flag=0 param='' while :; do case "${1-}" in -h | --help) usage ;; -v | --verbose) set -x ;; --no-color) NO_COLOR=1 ;; -p | --param) # Project flag param="${2-}" [[ -z "$param" ]] && die "Error: -p option requires a value." shift ;; -?*) die "Unknown option: $1" ;; *) break ;; esac shift done args=("$@") # All positional arguments (as separate strings) # Check required params [[ -z "${param-}" ]] && die "Required parameter project -p missing." # Check required arguments # [[ ${#args[@]} -eq 0 ]] && die "Missing script arguments" return 0 } # ----- Script Start ----- # Parse parameters and setup colors for script. parse_params "$@" setup_colors # Create the specified folder mkdir -p "${param}" # Copy the required files from Athena/code cp ~/eg/dev/dev-c/C.gitignore "$param/.gitignore" cp ~/eg/README.md "$param/README.md" cp ~/eg/dev/dev-c/Makefile "$param/Makefile" cp ~/eg/dev/license/LICENSE_MIT.md "$param/LICENSE" # Create src and tests subfolders mkdir -p "$param/src" mkdir -p "$param/tests" mkdir -p "$param/include" # Change directory to the created folder cd "${param}" # Run ctags for C (not C++) ctags -R --c-kinds=+p --fields=+iaS --extras=+q /usr/include msg "${GREEN}Initialization and ctags generation complete for folder: $param ${NOFORMAT}" exit 0