summaryrefslogtreecommitdiff
path: root/.local/bin/previewclean
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-04-27 09:42:41 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2024-04-27 09:42:41 -0400
commitd4b26da65c20df3559daa6379c27fef3dcbc400f (patch)
tree4555c80ed1ab6a187312e33be0487e1732e8fd88 /.local/bin/previewclean
parent3c823c638e3de31332b8966a2f1712c6bbb8d2b5 (diff)
parent26ec2e5dc6e8c2369ecb34b642db546327a8b7dd (diff)
Merge branch 'master' of github.com:ChausseBenjamin/dotfiles
Diffstat (limited to '.local/bin/previewclean')
-rwxr-xr-x.local/bin/previewclean10
1 files changed, 10 insertions, 0 deletions
diff --git a/.local/bin/previewclean b/.local/bin/previewclean
new file mode 100755
index 0000000..8b0a570
--- /dev/null
+++ b/.local/bin/previewclean
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+threshold="200000" # 200 MB
+previewdir="${XDG_CACHE_HOME:-$HOME/.cache}/lf"
+
+# Check if the total size of the preview directory exceeds the threshold
+# and remove the last viewed file until it doesn't
+while [ "$(du -s "$previewdir" | cut -f1)" -gt "$threshold" ]; do
+ rm -f "$(find "$previewdir" -type f -printf '%T+ %p\n' | sort | head -n1 | cut -d' ' -f2)"
+done