diff --git a/.bashrc b/.bashrc index 82d2104..0db2151 100644 --- a/.bashrc +++ b/.bashrc @@ -80,3 +80,50 @@ check () { printf '\033[30;101m%s\033[m\n' "Could not clone the repo" fi } + +timo_moulinette () { + subject="${1}" + ex="${2}" + if [ -z "${subject}" ]; then + echo "Must provide at least one argument. Exiting" + return 1 + fi + if [ -z "${ex}" ]; then + ex="$(basename "${PWD}")" + fi + git_base="https://git.timo.one/42berlin/piscine-timo-moulinette/raw/branch/master" + + test_file_name="$(find . -mindepth 1 -maxdepth 1 -name '*.c' -type f -exec basename {} \; | sed 's/\.c$/_test.c/g')" + if [ -z "${test_file_name}" ]; then + echo "Could not find any C files in the current directory. Exiting" + return 2 + fi + git_full="${git_base}/${subject}/${ex}/${test_file_name}" + echo "${git_full}" +} + +prev () { + ex="$(basename "${PWD}")" + ex_num="$(echo "${ex}" | cut -c3-)" + if [ -z "${1}" ]; then + next_ex_num="$(( ${ex_num} - 1 ))" + else + next_ex_num="${1}" + fi + builtin printf -v padded '%02d' "${next_ex_num}" + next_dir="ex${padded}" + builtin cd "../${next_dir}" +} + +next () { + ex="$(basename "${PWD}")" + ex_num="$(echo "${ex}" | cut -c3-)" + if [ -z "${1}" ]; then + next_ex_num="$(( ${ex_num} + 1 ))" + else + next_ex_num="${1}" + fi + builtin printf -v padded '%02d' "${next_ex_num}" + next_dir="ex${padded}" + builtin cd "../${next_dir}" +}