This commit is contained in:
parent
12f08870ef
commit
e6efda6ced
16
trash.sh
16
trash.sh
@ -1,12 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Trash Functions
|
# Trash Functions
|
||||||
|
|
||||||
[ ! -d "$HOME"/.trash/ ] && mkdir "$HOME"/.trash/
|
TRASH_DIR="$HOME"/.trash
|
||||||
FILE_PATHS_FILE="$HOME/.trash/.filepaths"
|
|
||||||
|
[ ! -d "$TRASH_DIR" ] && mkdir "$TRASH_DIR"
|
||||||
|
FILE_PATHS_FILE="$TRASH_DIR/.filepaths"
|
||||||
[ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
|
[ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
|
||||||
|
|
||||||
trash_list() {
|
trash_list() {
|
||||||
find "$HOME"/.trash/ ! -name ".filepaths" | tail -n +2
|
find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_put() {
|
trash_put() {
|
||||||
@ -14,12 +16,12 @@ trash_put() {
|
|||||||
# Store old filepath for later restore
|
# Store old filepath for later restore
|
||||||
echo "$FILE $(readlink -f "$FILE")" >>"$FILE_PATHS_FILE"
|
echo "$FILE $(readlink -f "$FILE")" >>"$FILE_PATHS_FILE"
|
||||||
done
|
done
|
||||||
mv -v $* "$HOME"/.trash/
|
mv -v $* "$TRASH_DIR/"
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_empty() {
|
trash_empty() {
|
||||||
echo "Delete all $(find "$HOME"/.trash/ ! -name ".filepaths" | tail -n +2 | wc -l) files in trash?"
|
echo "Delete all $(find "$TRASH_DIR" ! -name ".filepaths" | tail -n +2 | wc -l) files in trash?"
|
||||||
\rm -irf "$HOME"/.trash/* && echo >"$FILE_PATHS_FILE"
|
\rm -irf "${TRASH_DIR/*}" && echo >"$FILE_PATHS_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_restore() {
|
trash_restore() {
|
||||||
@ -28,7 +30,7 @@ trash_restore() {
|
|||||||
OLD_PATH=$(grep "$FILE_TO_RESTORE" "$FILE_PATHS_FILE" | cut -d ' ' -f2)
|
OLD_PATH=$(grep "$FILE_TO_RESTORE" "$FILE_PATHS_FILE" | cut -d ' ' -f2)
|
||||||
|
|
||||||
# Move file to old filepath
|
# 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
|
# Replace / with \/ from string and remove filepath from file after move was successful
|
||||||
sed -i "/${FILE_TO_RESTORE////\\/}/d" "$FILE_PATHS_FILE"
|
sed -i "/${FILE_TO_RESTORE////\\/}/d" "$FILE_PATHS_FILE"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user