From 0c3baa45d4b8e376cd2213232f84bdc4a259bb98 Mon Sep 17 00:00:00 2001 From: thek4n Date: Wed, 9 Oct 2024 11:41:17 +0300 Subject: [PATCH] bash functions refactor --- home/user/.config/bash/functions | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/home/user/.config/bash/functions b/home/user/.config/bash/functions index 985f5a1..c7b42fb 100644 --- a/home/user/.config/bash/functions +++ b/home/user/.config/bash/functions @@ -15,12 +15,27 @@ lt() { } destroy() { - test -n "$1" || return 1 - test -e "$1" || return 1 + local -r filename="${1}" - echo -n "Sure want to destroy file '$1' with size $(du -hs "$1" | awk '{printf $1}') [y/N] " + if [[ ! -f "${filename}" ]]; then + echo "destroy: File '${filename}' not found" >&2 + return 1 + fi + + local filesize + filesize="$(du -hs "${filename}" | awk '{printf $1}')" + readonly filesize + + echo -n "Sure want to destroy file '${filename}' with size ${filesize} [y/N] " + + local response read -r response - [[ $response == [yY] ]] && shred -zun 25 "$1" + readonly response + if [[ ! "${response}" == [yY] ]]; then + return 1 + fi + + shred -zun 3 "${filename}" } workon() {