add double quotes

This commit is contained in:
Kim Oliver Drechsel 2021-09-21 18:24:38 +02:00
parent 1f7aa0130a
commit 859b3cdfa0

View File

@ -1,49 +1,50 @@
#!/bin/bash #!/bin/bash
# Trash Functions # Trash Functions
[ ! -d $HOME/.trash/ ] && mkdir $HOME/.trash/ [ ! -d "$HOME"/.trash/ ] && mkdir "$HOME"/.trash/
FILEPATHS_FILE="$HOME/.trash/.filepaths" FILE_PATHS_FILE="$HOME/.trash/.filepaths"
[ ! -f $FILEPATHS_FILE ] && touch $FILEPATHS_FILE [ ! -f "$FILE_PATHS_FILE" ] && touch "$FILE_PATHS_FILE"
trash-list() { trash_list() {
ls -lrth $HOME/.trash/ ls -lrth "$HOME"/.trash/
} }
trash-put() { trash_put() {
for i in "$@"; do for i in "$@"; do
# Store old filepath for later restore # Store old filepath for later restore
echo "$i $(readlink -f $i)" >> $FILEPATHS_FILE echo "$i $(readlink -f $i)" >> "$FILE_PATHS_FILE"
done done
mv -uv $* $HOME/.trash/ mv -uv "$*" "$HOME"/.trash/
} }
trash-empty() { trash_empty() {
echo "Delete all $(ls -l $HOME/.trash/* | wc -l) files in trash?" echo "Delete all $(find "$HOME"/.trash/* | wc -l) files in trash?"
\rm -Ir $HOME/.trash/* && echo > $FILEPATHS_FILE # shellcheck disable=SC2086
\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
OLDPATH=$(grep $FILE_TO_RESTORE $FILEPATHS_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 $OLDPATH 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" $FILEPATHS_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" $FILEPATHS_FILE \rm -Ir "$HOME"/.trash/"$FILE_TO_REMOVE" && sed -i "/$FILE_TO_REMOVE/d" "$FILE_PATHS_FILE"
else else
echo "$i is not in Trash." && false echo "$i is not in Trash." && false
fi fi
done done
} }
alias trash='trash-put' alias trash='trash_put'
alias rm='echo "This is not the command you are looking for. Use \rm instead"; false' alias rm='echo "This is not the command you are looking for. Use \rm instead"; false'