next and prev functions for 42
This commit is contained in:
parent
3977a076f8
commit
7e887018c1
47
.bashrc
47
.bashrc
|
@ -80,3 +80,50 @@ check () {
|
||||||
printf '\033[30;101m%s\033[m\n' "Could not clone the repo"
|
printf '\033[30;101m%s\033[m\n' "Could not clone the repo"
|
||||||
fi
|
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}"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue