Files
crun/install.sh
T
2026-09-10 15:26:11 +02:00

57 lines
1.2 KiB
Bash

#!/bin/bash
BASHRC="$HOME/.bashrc"
MARKER_START="# >>> c-run setup >>>"
MARKER_END="# <<< c-run setup <<<"
# Crée le .bashrc s'il n'existe pas (cas très rare)
touch "$BASHRC"
# Supprime l'ancienne version de la fonction si elle existe
if grep -q "$MARKER_START" "$BASHRC"; then
sed -i "/$MARKER_START/,/$MARKER_END/d" "$BASHRC"
fi
# Ajoute la fonction à la fin du .bashrc
cat >> "$BASHRC" << 'EOF'
# >>> c-run setup >>>
c-run() {
if [ -z "$1" ]; then
echo "c-run: erreur: nom de fichier manquant" >&2
return 1
fi
local source_file="$1"
shift
local exec_file
exec_file=$(mktemp)
trap 'rm -f "$exec_file"' INT
gcc "$source_file" -o "$exec_file" "$@"
local gcc_status=$?
if [ $gcc_status -ne 0 ]; then
echo "--- c-run: la compilation a échoué (gcc a retourné le code $gcc_status) ---" >&2
rm -f "$exec_file"
trap - INT
return $gcc_status
fi
"$exec_file"
local exec_status=$?
rm -f "$exec_file"
trap - INT
return $exec_status
}
# <<< c-run setup <<<
EOF
# Recharge le .bashrc si on est bien dans un shell interactif
if [ -n "$BASH_VERSION" ]; then
source "$BASHRC"
fi
exit 0