Skip to content

Commit ee1ca2c

Browse files
committed
Prune temp files manually
Add a utility to prune the temp files manually. By default this would be history older then seven days but can be adjusted through a command line option. Originally intended to be used in a cron job for systems that either don't reboot often or are not configured to erase the `/tmp`/ folder on reboot.
1 parent 63cfb33 commit ee1ca2c

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ Reopen your most recent file:
8282
$ vim $( ls /tmp/vim-anywhere | sort -r | head -n 1 )
8383
```
8484

85+
To clean up your history (for systems that do not reboot often) you can run the `bin/prune` command (possibly from `cron`).
86+
87+
Remove history older than seven days (default):
88+
89+
```bash
90+
$ ~/.vim-anywhere/bin/prube
91+
```
92+
93+
Remove history older then *one* day:
94+
95+
```bash
96+
$ ~/.vim-anywhere/bin/prube -m +1
97+
```
98+
99+
Remove **all** history:
100+
101+
```bash
102+
$ ~/.vim-anywhere/bin/prube -a
103+
```
104+
105+
To run this every day (at 2 AM) you can add this to your crontab:
106+
107+
```crontab
108+
0 2 * * * $HOME/.vim-anywhere/bin/prune
109+
```
110+
85111
## Why?
86112

87113
I use Vim for _almost_ everything. I wish I didn't have to say _almost_. My

bin/prune

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
#
3+
# vim-anywhere-prune - Prune unused temprary files
4+
# Author: Chris Knadler
5+
# Homepage: https://www.github.com/cknadler/vim-anywhere
6+
#
7+
# Removes old temprary files
8+
9+
###
10+
# defs
11+
###
12+
13+
ALL=1
14+
mtime="+7"
15+
16+
###
17+
# opts
18+
###
19+
20+
while getopts ":am:v" opt; do
21+
case "$opt" in
22+
a) ALL=0 ;;
23+
m) mtime="$OPTARG" ;;
24+
v) set -x ;;
25+
\?) echo "Invalid option: -$OPTARG" >&2 ;;
26+
esac
27+
done
28+
29+
###
30+
# run
31+
###
32+
33+
TMPFILE_DIR=/tmp/vim-anywhere
34+
35+
if [[ $ALL == 0 ]]; then
36+
find $TMPFILE_DIR -type f -exec rm -f {} \;
37+
else
38+
find $TMPFILE_DIR -type f -mtime "$mtime" -exec rm -f {} \;
39+
fi

0 commit comments

Comments
 (0)