mirror of
https://codeberg.org/vlw/dotfiles.git
synced 2026-04-12 23:29:39 +02:00
feat(bash): add trash function and directory with self-cleaning (#132)
Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/132
This commit is contained in:
parent
01e8e31df3
commit
b7e7151bb0
2 changed files with 25 additions and 0 deletions
|
|
@ -178,6 +178,28 @@ mvf () {
|
|||
ll $1
|
||||
}
|
||||
|
||||
# Move target to the trash directory and clean up expired items
|
||||
trash () {
|
||||
local days=30
|
||||
|
||||
# Create trash directory if it does not exist
|
||||
if [[ ! -d "$TRASH_DIR" ]]; then
|
||||
mkdir "$TRASH_DIR"
|
||||
echo "Created: $TRASH_DIR"
|
||||
fi
|
||||
|
||||
# Remove expired files
|
||||
find "$TRASH_DIR" -mindepth 1 -type f -mtime +"$days" -print0 | xargs -0 --no-run-if-empty rm -f --
|
||||
# Remove expired directories
|
||||
find "$TRASH_DIR" -mindepth 1 -type d -mtime +"$days" -print0 | xargs -0 --no-run-if-empty rm -rf --
|
||||
|
||||
# Move target to trash if specified
|
||||
if [ -e "$1" ]; then
|
||||
mv "$1" "$TRASH_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# +-----+
|
||||
# | Git |
|
||||
# +-----+
|
||||
|
|
|
|||
|
|
@ -23,3 +23,6 @@ export XDG_BIN_HOME="$HOME/.local/bin"
|
|||
export XDG_DATA_HOME="$HOME/.local/share"
|
||||
export XDG_CACHE_HOME="$HOME/.cache"
|
||||
export XDG_CONFIG_HOME="$HOME/.config"
|
||||
|
||||
# Use this directory for storing trashed items
|
||||
export TRASH_DIR="$XDG_DATA_HOME/Trash"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue