From e6efda6ced378b88c8308630a0dc7900c9224bc3 Mon Sep 17 00:00:00 2001 From: Kim Date: Tue, 21 Sep 2021 20:35:16 +0200 Subject: [PATCH] add $TRASH_DIR --- trash.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/trash.sh b/trash.sh index cba07ad..07766ad 100644 --- a/trash.sh +++ b/trash.sh @@ -1,12 +1,14 @@ #!/bin/bash # Trash Functions -[ ! -d "$HOME"/.trash/ ] && mkdir "$HOME"/.trash/ -FILE_PATHS_FILE="$HOME/.trash/.filepaths" +TRASH_DIR="$HOME"/.trash + +[ ! -d "$TRASH_DIR" ] && mkdir "$TRASH_DIR" +FILE_PATHS_FILE="$TRASH_DIR/.filepaths" [ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE" trash_list() { - find "$HOME"/.trash/ ! -name ".filepaths" | tail -n +2 + find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2 } trash_put() { @@ -14,12 +16,12 @@ trash_put() { # Store old filepath for later restore echo "$FILE $(readlink -f "$FILE")" >>"$FILE_PATHS_FILE" done - mv -v $* "$HOME"/.trash/ + mv -v $* "$TRASH_DIR/" } trash_empty() { - echo "Delete all $(find "$HOME"/.trash/ ! -name ".filepaths" | tail -n +2 | wc -l) files in trash?" - \rm -irf "$HOME"/.trash/* && echo >"$FILE_PATHS_FILE" + echo "Delete all $(find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2 | wc -l) files in trash?" + \rm -irf "${TRASH_DIR/*}" && echo >"$FILE_PATHS_FILE" } trash_restore() { @@ -28,7 +30,7 @@ trash_restore() { OLD_PATH=$(grep "$FILE_TO_RESTORE" "$FILE_PATHS_FILE" | cut -d ' ' -f2) # Move file to old filepath - mv -v "$FILE_TO_RESTORE" "$OLD_PATH" + mv -v "${TRASH_DIR}/${FILE_TO_RESTORE}" "$OLD_PATH" # Replace / with \/ from string and remove filepath from file after move was successful sed -i "/${FILE_TO_RESTORE////\\/}/d" "$FILE_PATHS_FILE"