diff --git a/README.md b/README.md index f0a8a07..0619720 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,12 @@ The default cache path is set to `$TMPDIR/c.cache`. You can change this with: $ export C_CACHE_PATH="/tmp/the_cache" ``` +### Clear cache +You can clear the cache with the `--clear-cache` flag: +```bash +$ c --clear-cache +``` + # Contributing Feel free to submit any ideas, questions, or problems by reporting an issue. Or, if you're feeling a bit brave, submit a pull request. :grimacing: diff --git a/c b/c index 3621cb9..452dca8 100755 --- a/c +++ b/c @@ -11,6 +11,7 @@ fi help_msg() { >&$1 echo "Usage: $(basename "$0") [program_arguments]" + >&$1 echo " $(basename "$0") --clear-cache" >&$1 echo 'Execute C programs from the command line.' >&$1 echo >&$1 echo ' Ex: c main.c' @@ -36,6 +37,17 @@ cleanup() { [[ "$1" == "--help" || "$1" == "-h" ]] && { help_msg 1; exit 0; } [[ "$#" -lt 1 ]] && { help_msg 2; exit 2; } +# get cache location +if [[ -n "$C_CACHE_PATH" ]]; then + tmproot="$C_CACHE_PATH" +else + [[ -z "$TMPDIR" ]] && TMPDIR="/tmp" + tmproot="$TMPDIR/c.cache.$USER" +fi + +# Hadle --clear-cache +[[ "$1" == "--clear-cache" ]] && { rm -rf "$tmproot"; exit 0; } + # ensure our $CC and $CXX variables are set [[ -z "$CC" ]] && CC=cc [[ -z "$FC" ]] && FC=gfortran @@ -76,13 +88,7 @@ else fi fi -# get cache location -if [[ -n "$C_CACHE_PATH" ]]; then - tmproot="$C_CACHE_PATH" -else - [[ -z "$TMPDIR" ]] && TMPDIR="/tmp" - tmproot="$TMPDIR/c.cache.$USER" -fi +# create cache location mkdir -p "$tmproot" chmod 700 "$tmproot"