From 2b30a0334c9b677983093ccca053bf16aa3e9204 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Wed, 19 Feb 2020 16:37:18 +0100 Subject: [PATCH] Adds basic --- bin/basic | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 bin/basic diff --git a/bin/basic b/bin/basic new file mode 100755 index 0000000..b360b11 --- /dev/null +++ b/bin/basic @@ -0,0 +1,93 @@ +#!/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 $@