This commit is contained in:
parent
8bf0080654
commit
a1230c71db
48
trash.sh
48
trash.sh
@ -6,44 +6,44 @@ FILE_PATHS_FILE="$HOME/.trash/.filepaths"
|
|||||||
[ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
|
[ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
|
||||||
|
|
||||||
trash_list() {
|
trash_list() {
|
||||||
find "$HOME"/.trash/
|
find "$HOME"/.trash/
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_put() {
|
trash_put() {
|
||||||
for FILE in $@; do
|
for FILE in $@; do
|
||||||
# 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 $* "$HOME"/.trash/
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_empty() {
|
trash_empty() {
|
||||||
echo "Delete all $(find "$HOME"/.trash/* | wc -l) files in trash?"
|
echo "Delete all $(find "$HOME"/.trash/* | wc -l) files in trash?"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
\rm -Ir $HOME/.trash/* && echo > "$FILE_PATHS_FILE"
|
\rm -Ir $HOME/.trash/* && echo >"$FILE_PATHS_FILE"
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_restore() {
|
trash_restore() {
|
||||||
for FILE_TO_RESTORE in "$@"; do
|
for FILE_TO_RESTORE in "$@"; do
|
||||||
# Get old filepath for restore
|
# Get old filepath for 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 "$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"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
trash_rm() {
|
trash_rm() {
|
||||||
for FILE_TO_REMOVE in "$@"; do
|
for FILE_TO_REMOVE in "$@"; do
|
||||||
if readlink -f "$FILE_TO_REMOVE" | grep "$HOME/.trash"; then
|
if readlink -f "$FILE_TO_REMOVE" | grep "$HOME/.trash"; then
|
||||||
\rm -Ir "$HOME"/.trash/"$FILE_TO_REMOVE" && sed -i "/$FILE_TO_REMOVE/d" "$FILE_PATHS_FILE"
|
\rm -Ir "$HOME"/.trash/"$FILE_TO_REMOVE" && sed -i "/$FILE_TO_REMOVE/d" "$FILE_PATHS_FILE"
|
||||||
else
|
else
|
||||||
echo "$FILE_TO_REMOVE is not in Trash." && false
|
echo "$FILE_TO_REMOVE is not in Trash." && false
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
alias trash='trash_put'
|
alias trash='trash_put'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user