diff --git a/README.md b/README.md index 55425d6..f33a043 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,32 @@ Reopen your most recent file: $ vim $( ls /tmp/vim-anywhere | sort -r | head -n 1 ) ``` +To clean up your history (for systems that do not reboot often) you can run the `bin/prune` command (possibly from `cron`). + +Remove history older than seven days (default): + +```bash +$ ~/.vim-anywhere/bin/prune +``` + +Remove history older then *one* day: + +```bash +$ ~/.vim-anywhere/bin/prune -m +1 +``` + +Remove **all** history: + +```bash +$ ~/.vim-anywhere/bin/prune -a +``` + +To run this every day (at 2 AM) you can add this to your crontab: + +```crontab +0 2 * * * $HOME/.vim-anywhere/bin/prune +``` + ## Why? I use Vim for _almost_ everything. I wish I didn't have to say _almost_. My diff --git a/bin/prune b/bin/prune new file mode 100755 index 0000000..1b36182 --- /dev/null +++ b/bin/prune @@ -0,0 +1,39 @@ +#!/bin/bash +# +# vim-anywhere-prune - Prune unused temprary files +# Author: Chris Knadler +# Homepage: https://www.github.com/cknadler/vim-anywhere +# +# Removes old temprary files + +### +# defs +### + +ALL=1 +mtime="+7" + +### +# opts +### + +while getopts ":am:v" opt; do + case "$opt" in + a) ALL=0 ;; + m) mtime="$OPTARG" ;; + v) set -x ;; + \?) echo "Invalid option: -$OPTARG" >&2 ;; + esac +done + +### +# run +### + +TMPFILE_DIR=/tmp/vim-anywhere + +if [[ $ALL == 0 ]]; then + find $TMPFILE_DIR -type f -exec rm -f {} \; +else + find $TMPFILE_DIR -type f -mtime "$mtime" -exec rm -f {} \; +fi