5 if [[ -z ${XDG_CACHE_HOME:-} ]]; then
8 cache_dir
=$XDG_CACHE_HOME
11 if [[ ! -e $cache_dir ]]; then
12 echo "Can't find $cache_dir, exiting..."
16 if [[ -z ${CLEAN_CACHE_CONFIG:-} ]]; then
17 rc_path
="~/.config/moggers87/clean_cacherc"
19 rc_path
=$CLEAN_CACHE_CONFIG
22 expanded_path
=${rc_path/#\~/$HOME}
24 if [ -e $expanded_path ]; then
28 if [[ -z ${days:-} ]]; then
32 progname
=`basename $0`
35 echo "$progname [command]"
40 echo " Cleans $cache_dir of files that haven't been accessed in the last $days days. Deletes empty directories. Expects environment variables set in $rc_path. Set days to control what is considered old." |
fmt
43 echo " Same as clean, except it returns the list of files that would be removed rather than actually removing them" |
fmt
46 echo " Add an example config file to $rc_path if that path does not already exist" |
fmt
51 if [ -e $expanded_path ]; then
52 echo "$rc_path already exists, refusing to overwrite!"
55 mkdir
-p `dirname $expanded_path`
56 cat <<EOF > $expanded_path
57 # how many days old should something be before it's removed from the cache?
63 find $cache_dir -type f
-atime +$days -delete
64 find $cache_dir -type d
-empty -delete
68 find $cache_dir -type f
-atime +$days
78 if [ -n "$(type -t sub_${subcommand})" ]; then
81 echo "Error: '$subcommand' is not a valid command" >&2