From b7e7151bb0c883763cc821277f3a0b7314757300 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Tue, 31 Mar 2026 13:02:34 +0200 Subject: [PATCH] feat(bash): add `trash` function and directory with self-cleaning (#132) Reviewed-on: https://codeberg.org/vlw/dotfiles/pulls/132 --- .bash_aliases | 22 ++++++++++++++++++++++ .bash_profile | 3 +++ 2 files changed, 25 insertions(+) diff --git a/.bash_aliases b/.bash_aliases index a5e59fc..339f9dc 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -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 | # +-----+ diff --git a/.bash_profile b/.bash_profile index d6ca2ef..e11e366 100644 --- a/.bash_profile +++ b/.bash_profile @@ -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"