diff --git a/.bashrc b/.bashrc index fdfdd92..2644228 100644 --- a/.bashrc +++ b/.bashrc @@ -14,8 +14,56 @@ alias push='git push origin master ; git push gitea master' alias francinette=/nfs/homes/tischmid/francinette/tester.sh alias paco=/nfs/homes/tischmid/francinette/tester.sh alias norm='alacritty -e sh -c '\''git rev-parse --show-toplevel || { echo "Exiting in 5" ; sleep 1 ; echo "Exiting in 4" ; sleep 1 ; echo "Exiting in 3" ; sleep 1 ; echo "Exiting in 2" ; sleep 1 ; echo "Exiting in 1" ; sleep 1 ; } && cd "$(git rev-parse --show-toplevel)" && watch -cn.5 date \&\& norminette -R CheckForbiddenSourceHeader'\'' & disown' -# alias zellij='zellij options --disable-mouse-mode' -alias z='zellij' +alias AH='cd /nfs/homes/tischmid/repos/42cursus/libft' +alias z='\zellij options --disable-mouse-mode' +alias zellij='\zellij options --disable-mouse-mode' + +__ftest_file () { + file="${1}" + tmp_dir="${2}" + + test_file_name="$($(type -P basename) -- "${file%.c}_test.c")" + test_file="$(find "${tmp_dir}" -name "${test_file_name}" -type f)" + if [ -z "${test_file}" ]; then + printf '\033[31m%s\033[m\n' "No test file for file '${file}'" + return 1 + fi + ${test_file} +} + +ftest () { + err="0" + if [ -z "${tmp_dir}" ]; then + tmp_dir="$(mktemp -dt -- '42tests-tischmid.XXXXXXXX')" + git clone --quiet 'https://git.timo.one/42berlin/42tests-tischmid.git' "${tmp_dir}" + fi + if [ -z "${@}" ]; then + for file in $(find . -mindepth 1 -type f -name '*.c'); do + __ftest_file "${file}" "${tmp_dir}" || err="1" + done + else + while [ -z "${1}" ]; do + if [ -f "${1}" ]; then + __ftest_file "${1}" "${tmp_dir}" || err="1" + else + printf '\033[31m%s\033[m\n' "File ${1} does not exist" + fi + shift + done + fi + rm -rf -- "/tmp/42tests-tischmid.*" + unset -v -- "tmp_dir" + return -- "${err}" +} + +dapt () { + ACTION="${1}" + shift + CMD="RUN apt ${ACTION} -yy ${@}" + echo "${CMD}" >> ~/repos-other/docker/Dockerfile + docker build -t ubuntu-bloated ~/repos-other/docker/ + docker rmi $(docker images -f "dangling=true" -q) 2>/dev/null +} norminette () { version="$($(type -P norminette) -v | cut -d" " -f2)" @@ -83,27 +131,27 @@ fi check () { # Set params - URL="${1}" - DIR="/tmp/tmp_repo_$(date +%s)" + URL="${1}" + DIR="/tmp/tmp_repo_$(date +%s)" # If no URL, get it from current repo - if [ -z "${URL}" ] ; then - URL="$(git remote get-url origin)" - fi + if [ -z "${URL}" ] ; then + URL="$(git remote get-url origin)" + fi # Clone in temp folder - git clone --quiet "${URL}" "${DIR}" + git clone --quiet "${URL}" "${DIR}" # Only proceed if clone success - if [ -d "${DIR}" ] ; then - # Check the norm and print beautiful message - norminette -R CheckForbiddenSourceHeader "${DIR}" && printf '\033[30;102m%s\033[m\n' "Norminette success" || printf '\033[30;101m%s\033[m\n' "Norminette fail!!!" + if [ -d "${DIR}" ] ; then + # Check the norm and print beautiful message + norminette -R CheckForbiddenSourceHeader "${DIR}" && printf '\033[30;102m%s\033[m\n' "Norminette success" || printf '\033[30;101m%s\033[m\n' "Norminette fail!!!" # Remove temp folder - rm -rf "${DIR}" - else - printf '\033[30;101m%s\033[m\n' "Could not clone the repo" - fi + rm -rf "${DIR}" + else + printf '\033[30;101m%s\033[m\n' "Could not clone the repo" + fi } safe_guard_name () { @@ -223,7 +271,7 @@ timoulinette () { printf '%s\n' "Could not compile. Exiting" return fi - + # Delete testfile if [ "$(printf '%s' "${extras}" | sed 's/keep-test//g')" = "${extras}" ] ; then rm -f -- "${download_file_name}" @@ -284,3 +332,5 @@ clone42 () { printf '%s\n' "Could not clone repo!" fi } + +export MAIL='timo42@proton.me'