trash-cli
trash-cli copied to clipboard
[Enhancement] size based trash-empty
It would be nice to be able to prune the trash content down to a total maximum size. The <days> input is great for time-based trash pruning, but i find that it would also be very helpful to have a <total size> based mechanism.
If I was more familiar with python I would consider creating a pull request .. 🤔 The logic could look something like this:
function emptyMaxSize(maxSize) {
trashItems.sortByDateDesc(); //newest first
totalSize = 0;
foreach(item in trashItems) {
if (totalSize > maxSize) {
delete(item)
} else {
totalSize += item.size;
}
}
}
Update
I ended up writing a shell script in the mean time.
#!/bin/bash
loc="$HOME/.local/share/Trash"
total=0
max=$((5 * 1024 * 1024 * 1024)) #5GiB
while read -r i; do
size="${i%$'\t'*}"
floc="${i##*$'\t'}"
total=$((total + size))
if [ $total -gt $max ]; then
info="${floc/\/files\//\/info\/}.trashinfo"
if [ -f "$info" ]; then
rm -rf "$floc" "$info"
else
echo "Warning: missing trashinfo $info"
fi
fi
done < <(ls -1t "$loc/files" | xargs -I "{}" du -abd 0 "$loc/files/{}";)
I am also interested in a feature like this.
What does the core developers / maintainers (@andreafrancia) say about that feature?
Would you accept pull requests for this?
I cannot decide until I see an actual PR.
You do not have to decide the PR now. But you should decide if you would accept a feature like this before some invest time in implementing this. That is the question about.
For a contributor it would be very frustrating investing time in implementation and then the maintainer refusing the work - not because of quality issues but of this-feature-do-not-fit-to-the-concept.
e.g. What would you say If I would implement colored output and created a PR for it? I assume you would reject that (without code review) just because this feature does not fit the concept and goal of trash-cli.
And if you not clear about what the feature is please ask the OP back.
If there is not code to review there is nothing to discuss about. I do not want potential contributors that will regret the investments they did because their pull request has not been merged. Anyway this feature is interesting. This does not mean I'm going to merge any pull request about it.
Dear @andreafrancia I think there is still a misunderstanding between us.
The question is not about code but about functionality. But between the lines I understand you that you would accept such a functionality in thrash-cli.