You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
alias goto-trash-can='mv --force -t ~/.local/share/Trash/files '
|
|
alias mv2trash='goto-trash-can'
|
|
|
|
prompt_to_wipe() {
|
|
read -rp "Type 'wipe' to confirm deletion: " response
|
|
if [[ "$response" == "wipe" ]]; then
|
|
return 0 # user chose to wipe
|
|
else
|
|
return 1 # user did not choose to wipe
|
|
fi
|
|
}
|
|
|
|
wipe-and-shred-file-permanently() {
|
|
if ! prompt_to_wipe; then
|
|
echo "Aborting..."
|
|
return 0
|
|
fi
|
|
shred -z -v -u $@
|
|
}
|
|
empty-the-file-contents() {
|
|
if [[ -z "$1" ]]; then
|
|
echo "Usage: empty-the-file-contents <filename>"
|
|
return 1
|
|
fi
|
|
|
|
if ! prompt_to_wipe; then
|
|
echo "Aborting..."
|
|
return 0
|
|
fi
|
|
|
|
local filename="$1"
|
|
local need_sudo=""
|
|
|
|
# Check if file exists
|
|
if [[ ! -e "$filename" ]]; then
|
|
echo "Error: File '$filename' does not exist." >&2
|
|
return 1
|
|
fi
|
|
|
|
# Check if current user owns the file
|
|
if [[ ! -O "$filename" ]]; then
|
|
echo "You don't own '$filename'. Trying with sudo..."
|
|
need_sudo="sudo"
|
|
fi
|
|
|
|
# Empty the file while preserving permissions
|
|
$need_sudo truncate -s 0 "$filename" && echo "Successfully emptied '$filename'." || {
|
|
echo "Failed to empty '$filename'." >&2
|
|
return 1
|
|
}
|
|
}
|
|
|
|
|