#!/usr/bin/env bash eprint() { echo -e >&2 "\x1B[1;31merror:\x1B[0m" $@ } info() { echo -e "\x1B[1minfo:\x1B[0m" $@ } info_n() { echo -en "\x1B[1minfo:\x1B[0m" $@ } print-help() { echo -e "\033[32mbasic\033[0m" echo -e "Thomas Forgione " echo -e "A script that automatically clones templates" echo print-usage } print-usage() { echo -e "\033[33mUSAGE:\033[0m" echo -e " \033[32mbasic init \033[0m initialize a template in the current directory" echo -e " \033[32mbasic init \033[0m initialize a template in the specified directory" } print-usage-and-exit() { print-usage exit $1 } git_clone() { info_n "downloading template..." GIT_TERMINAL_PROMPT=0 git clone $@ > /dev/null 2>&1 if [ $? -ne 0 ]; then echo >&2 eprint "failed to download template" exit 2 fi echo " done!" } init() { template=$1 case $template in "latex" | "beamer" | "marp") ;; *) eprint "template $template does not exist" print-usage-and-exit 1 ;; esac if [ $# -gt 1 ]; then name=$2 else name=. fi git_clone https://gitea.tforgione.fr/tforgione-basic/$1 $name rm -rf $name/.git } main() { arg=$1 shift case $arg in "init") init $@ ;; "help") print-help exit ;; ?*) eprint "command $arg does not exist" print-usage-and-exit 1 ;; "") print-help exit ;; esac } main $@