This commit is contained in:
parent
12f08870ef
commit
e6efda6ced
16
trash.sh
16
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"
|
||||
|
Loading…
Reference in New Issue
Block a user