diff options
Diffstat (limited to 'bin/init_year')
-rwxr-xr-x | bin/init_year | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/bin/init_year b/bin/init_year new file mode 100755 index 0000000..494c86f --- /dev/null +++ b/bin/init_year @@ -0,0 +1,76 @@ +#!/bin/sh -eu + +if [ "${1:-}" ]; then + _lang="$1" +fi + +if [ "${2:-}" ]; then + _year="$2" +else + _year=$( date +%Y ) +fi + +### FUNCTION ################################################################## + +rust() { + rust_dir="$1" + + ( + printf '%s\n%s\n' '[workspace]' 'members = [' + for day in $( seq 1 25 ); do + printf '# "day%02d",\n' "${day}" + done + echo ']' + ) > "${rust_dir}/Cargo.toml" + + unset rust_dir +} + +### MAIN ###################################################################### + +_dir="$( pwd )/${_year}" + +if ! [ -d "${_dir}" ]; then + read -p "Create directory '${_dir}'?: " _input + + case "${_input}" in + 'y' | 'Y') + mkdir "${_dir}" + ;; + *) + echo 'Okay, not doing anything then.' + exit 0 + ;; + esac + unset _input +fi + +[ "${_lang:-}" ] || read -p "Implementation language for '${_year}'?: " _lang + +if ! [ -d "${_dir}/${_lang}" ]; then + read -p "Create directory '${_dir}/${_lang}'?: " _input + case "${_input}" in + 'y' | 'Y') + mkdir "${_dir}/${_lang}" + ;; + *) + echo 'Okay, not doing that then.' + exit 0 + ;; + esac + unset _input +fi + +read -p "Run '${_lang}(\"${_dir}/${_lang}\")'?: " _input +case "${_input}" in + 'y' | 'Y') + ${_lang} "${_dir}/${_lang}" + ;; + *) + echo 'Okay, not doing that then.' + exit 0 + ;; +esac +unset _input + +unset _dir _lang _year |