dotfiles/bin/basic

94 lines
1.7 KiB
Plaintext
Raw Normal View History

2020-02-19 15:37:18 +00:00
#!/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 <thomas@forgione.fr>"
echo -e "A script that automatically clones templates"
echo
print-usage
}
print-usage() {
echo -e "\033[33mUSAGE:\033[0m"
echo -e " \033[32mbasic init <latex|beamer|marp>\033[0m initialize a template in the current directory"
echo -e " \033[32mbasic init <latex|beamer|marp> <directory>\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 $@