Moulinette params

This commit is contained in:
Timo Schmidt 2023-03-28 15:03:40 +02:00
parent 3b4068fac9
commit 00cf30350f
1 changed files with 41 additions and 36 deletions

77
.bashrc
View File

@ -3,17 +3,17 @@ alias v='vim'
alias ..='cd ..' alias ..='cd ..'
alias ...='cd ../..' alias ...='cd ../..'
alias tmux='tmux -2' alias tmux='tmux -2'
alias ft='cc -Wall -Wextra -Werror -o main -xc -- <(grep -v "////" *.c) && ./main; rm -f -- ./main; :' alias ft='cc -Wall -Wextra -Werror -o main -xc -- <(grep -v "////" *.c) && ./main ; rm -f -- ./main ; :'
alias ft2='cc -Wall -Wextra -Werror -o main -xc -- <(grep -v "////" *.c) && ./main' alias ft2='cc -Wall -Wextra -Werror -o main -xc -- <(grep -v "////" *.c) && ./main'
alias git='EDITOR=vim git' alias git='EDITOR=vim git'
alias cmatrix='cmatrix -cu3 -Cred' alias cmatrix='cmatrix -cu3 -Cred'
alias gca='git add -u && git commit -m *' alias gca='git add -u && git commit -m *'
alias watch='watch -cn.1' alias watch='watch -cn.1'
alias push='git push origin master; git push gitea master' alias push='git push origin master ; git push gitea master'
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 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'
jmp () { jmp () {
cd "$(find . -name "${1}" -not -wholename "*mouli*" -print -quit)" cd "$(find . -name "${1}" -not -wholename "*mouli*" -print -quit)"
if [ "${?}" = "0" ]; then if [ "${?}" = "0" ] ; then
cd "$(find .. -name "${1}" -not -wholename "*mouli*" -print -quit)" cd "$(find .. -name "${1}" -not -wholename "*mouli*" -print -quit)"
fi fi
} }
@ -22,45 +22,45 @@ xset r rate 200 60
PATH="${PATH}:/nfs/homes/tischmid/.local/bin" PATH="${PATH}:/nfs/homes/tischmid/.local/bin"
if [ -f ~/git-prompt.sh ]; then # if [ ! -f ~/git-prompt.sh ] ; then
. ~/git-prompt.sh # curl --silent --location 'https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh' -o "~/git-prompt.sh"
else # fi
source <(curl --silent --location 'https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh') #
fi # . ~/git-prompt.sh
# export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWDIRTYSTATE=1 # PS1='\[\033[31m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[m\] \[\033[33m\][\w]\[\033[m\]\[\033[36m\]$(__git_ps1 " (%s)")\[\033[m\]\n$ '
PS1='\[\033[31m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[m\] \[\033[33m\][\w]\[\033[m\]\[\033[36m\]$(__git_ps1 " (%s)")\[\033[m\]\n$ ' PS1='\[\033[31m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[m\] \[\033[33m\][\w]\[\033[m\]\[\033[36m\]\[\033[m\]\n$ '
##----------------------------------------------------- ##-----------------------------------------------------
## synth-shell-greeter.sh ## synth-shell-greeter.sh
if [ -f /nfs/homes/tischmid/.config/synth-shell/synth-shell-greeter.sh ] && [ -n "$( echo $- | grep i )" ]; then if [ -f /nfs/homes/tischmid/.config/synth-shell/synth-shell-greeter.sh ] && [ -n "$( echo $- | grep i )" ] ; then
: :
# source /nfs/homes/tischmid/.config/synth-shell/synth-shell-greeter.sh # source /nfs/homes/tischmid/.config/synth-shell/synth-shell-greeter.sh
fi fi
##----------------------------------------------------- ##-----------------------------------------------------
## synth-shell-prompt.sh ## synth-shell-prompt.sh
if [ -f /nfs/homes/tischmid/.config/synth-shell/synth-shell-prompt.sh ] && [ -n "$( echo $- | grep i )" ]; then if [ -f /nfs/homes/tischmid/.config/synth-shell/synth-shell-prompt.sh ] && [ -n "$( echo $- | grep i )" ] ; then
: :
# source /nfs/homes/tischmid/.config/synth-shell/synth-shell-prompt.sh # source /nfs/homes/tischmid/.config/synth-shell/synth-shell-prompt.sh
fi fi
##----------------------------------------------------- ##-----------------------------------------------------
## better-ls ## better-ls
if [ -f /nfs/homes/tischmid/.config/synth-shell/better-ls.sh ] && [ -n "$( echo $- | grep i )" ]; then if [ -f /nfs/homes/tischmid/.config/synth-shell/better-ls.sh ] && [ -n "$( echo $- | grep i )" ] ; then
: :
# source /nfs/homes/tischmid/.config/synth-shell/better-ls.sh # source /nfs/homes/tischmid/.config/synth-shell/better-ls.sh
fi fi
##----------------------------------------------------- ##-----------------------------------------------------
## alias ## alias
if [ -f /nfs/homes/tischmid/.config/synth-shell/alias.sh ] && [ -n "$( echo $- | grep i )" ]; then if [ -f /nfs/homes/tischmid/.config/synth-shell/alias.sh ] && [ -n "$( echo $- | grep i )" ] ; then
source /nfs/homes/tischmid/.config/synth-shell/alias.sh source /nfs/homes/tischmid/.config/synth-shell/alias.sh
fi fi
##----------------------------------------------------- ##-----------------------------------------------------
## better-history ## better-history
if [ -f /nfs/homes/tischmid/.config/synth-shell/better-history.sh ] && [ -n "$( echo $- | grep i )" ]; then if [ -f /nfs/homes/tischmid/.config/synth-shell/better-history.sh ] && [ -n "$( echo $- | grep i )" ] ; then
source /nfs/homes/tischmid/.config/synth-shell/better-history.sh source /nfs/homes/tischmid/.config/synth-shell/better-history.sh
fi fi
@ -70,7 +70,7 @@ check () {
DIR="/tmp/tmp_repo_$(date +%s)" DIR="/tmp/tmp_repo_$(date +%s)"
# If no URL, get it from current repo # If no URL, get it from current repo
if [ -z "${URL}" ]; then if [ -z "${URL}" ] ; then
URL="$(git remote get-url origin)" URL="$(git remote get-url origin)"
fi fi
@ -78,43 +78,44 @@ check () {
git clone --quiet "${URL}" "${DIR}" git clone --quiet "${URL}" "${DIR}"
# Only proceed if clone success # Only proceed if clone success
if [ -d "${DIR}" ]; then if [ -d "${DIR}" ] ; then
# Check the norm and print beautiful message # Check the norm and print beautiful message
norminette "${DIR}" && printf '\033[30;102m%s\033[m\n' "Norminette success" || printf '\033[30;101m%s\033[m\n' "Norminette fail!!!" norminette "${DIR}" && printf '\033[30 ;102m%s\033[m\n' "Norminette success" || printf '\033[30 ;101m%s\033[m\n' "Norminette fail!!!"
# Remove temp folder # Remove temp folder
rm -rf "${DIR}" rm -rf "${DIR}"
else else
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
} }
safe_guard_name () { safe_guard_name () {
printf '%s' "${1}" | tr \\'!@#$%^&*()_+~{}|:">[]?<, ./;=\t\-'\'\` '__________________________________' printf '%s' "${1}" | tr \\'!@#$%^&*()_+~{}|:">[]?<, ./ ;=\t\-'\'\` '__________________________________'
} }
timo_moulinette () { timo_moulinette () {
# Set params # Set params
subject="${1}" subject="${1}"
ex="${2}" ex="${2}"
extras="${3}"
# Arghandle # Arghandle
if [ -z "${subject}" ]; then if [ -z "${subject}" ] ; then
printf '%s\n' "Must provide at least one argument. Exiting" printf '%s\n' "Must provide at least one argument. Exiting"
return 1 return 1
fi fi
# If exercise was not provided, get it from current folder name # If exercise was not provided, get it from current folder name
if [ -z "${ex}" ]; then if [ -z "${ex}" ] ; then
ex="$(basename -- "${PWD}")" ex="$(basename -- "${PWD}")"
fi fi
# Search for a compiler # Search for a compiler
if command -v cc >/dev/null 2>&1; then if command -v cc >/dev/null 2>&1 ; then
CC="$(command -v cc)" CC="$(command -v cc)"
elif command -v gcc >/dev/null 2>&1; then elif command -v gcc >/dev/null 2>&1 ; then
CC="$(command -v gcc)" CC="$(command -v gcc)"
elif command -v clang >/dev/null 2>&1; then elif command -v clang >/dev/null 2>&1 ; then
CC="$(command -v clang)" CC="$(command -v clang)"
else else
printf '%s\n' "Could not find a compiler. Exiting" printf '%s\n' "Could not find a compiler. Exiting"
@ -127,7 +128,7 @@ timo_moulinette () {
file_name="$(find . -mindepth 1 -maxdepth 1 -name '*.c' -not -name '*mouli*' -type f -exec basename {} \; -quit)" file_name="$(find . -mindepth 1 -maxdepth 1 -name '*.c' -not -name '*mouli*' -type f -exec basename {} \; -quit)"
# If no C files found, exit # If no C files found, exit
if [ -z "${file_name}" ]; then if [ -z "${file_name}" ] ; then
printf '%s\n' "Could not find any C files in the current directory. Exiting" printf '%s\n' "Could not find any C files in the current directory. Exiting"
return 2 return 2
fi fi
@ -148,7 +149,7 @@ timo_moulinette () {
${CC} -dD -E -o "${file_name}.nocomments" -- "${file_name}" ${CC} -dD -E -o "${file_name}.nocomments" -- "${file_name}"
# Extract function definitions from preprocessed file and append semicolon # Extract function definitions from preprocessed file and append semicolon
prototypes="$(cat -- "${file_name}.nocomments" | grep -v '#' | grep ')$' | grep -v ' (' | grep -v ' ' | grep '[a-zA-Z0-9](' | grep -v 'int[[:space:]]\+main(' | sed 's/$/;/')" prototypes="$(cat -- "${file_name}.nocomments" | grep -v '#' | grep ')$' | grep -v ' (' | grep -v ' ' | grep '[a-zA-Z0-9](' | grep -v 'int[[:space:]]\+main(' | sed 's/$/ ;/')"
# Extract macros from file (ignore the ones with line continuations) # Extract macros from file (ignore the ones with line continuations)
macros="$(cat -- "${file_name}" | grep '^#' | grep -v '\\$')" macros="$(cat -- "${file_name}" | grep '^#' | grep -v '\\$')"
@ -159,7 +160,7 @@ timo_moulinette () {
# Write prototypes to beginning of testfile # Write prototypes to beginning of testfile
IFS=" IFS="
" "
for proto in ${prototypes}; do for proto in ${prototypes} ; do
printf '%s\n' "${proto}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c" printf '%s\n' "${proto}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}" mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
done done
@ -167,7 +168,7 @@ timo_moulinette () {
# Write macros to beginning of testfile # Write macros to beginning of testfile
IFS=" IFS="
" "
for macro in ${macros}; do for macro in ${macros} ; do
guard_name="$(safe_guard_name "${macro}")" guard_name="$(safe_guard_name "${macro}")"
# Endif include guard # Endif include guard
@ -193,21 +194,25 @@ timo_moulinette () {
${CC} -Wall -Wextra -Werror -o "${out_binary}" -xc -- *.c ${CC} -Wall -Wextra -Werror -o "${out_binary}" -xc -- *.c
err_code="${?}" err_code="${?}"
if [ ! "${err_code}" = 0 ]; then if [ ! "${err_code}" = 0 ] ; then
printf '%s\n' "Could not compile. Exiting" printf '%s\n' "Could not compile. Exiting"
return return
fi fi
# Delete testfile # Delete testfile
rm -f -- "${download_file_name}" if [ "$(printf '%s' "${extras}" | sed 's/keep-test//g')" = "${extras}" ] ; then
rm -f -- "${download_file_name}"
fi
# Run binary # Run binary
./${out_binary} ./${out_binary}
# rm -f -- "./${out_binary}" if [ "${?}" = "0" ] && [ "$(printf '%s' "${extras}" | sed 's/keep-binary//g')" = "${extras}" ] ; then
rm -f -- "./${out_binary}"
fi
} }
prev () { prev () {
if [ -z "${1}" ]; then if [ -z "${1}" ] ; then
ex="$(basename "${PWD}")" ex="$(basename "${PWD}")"
ex_num="$(printf '%s' "${ex}" | cut -c3-)" ex_num="$(printf '%s' "${ex}" | cut -c3-)"
next_ex_num="$(( ${ex_num} - 1 ))" next_ex_num="$(( ${ex_num} - 1 ))"
@ -221,7 +226,7 @@ prev () {
next () { next () {
# If no arg, calculate next num # If no arg, calculate next num
if [ -z "${1}" ]; then if [ -z "${1}" ] ; then
# Exercise name # Exercise name
ex="$(basename "${PWD}")" ex="$(basename "${PWD}")"