#!/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