add confirm to rm-bg
This commit is contained in:
27
files/rm_bg
27
files/rm_bg
@@ -3,19 +3,42 @@ set -e
|
||||
function helpexit() {
|
||||
echo Delete files in background, by moving the to a temp folder first.
|
||||
echo This command is always recursive!
|
||||
echo ' passing -i will ask first'
|
||||
exit
|
||||
}
|
||||
|
||||
[[ -z "$1" ]] && helpexit
|
||||
[[ "$1" = "-h" ]] && helpexit
|
||||
|
||||
|
||||
CONFIRM=0
|
||||
for k in "$@"; do
|
||||
if [[ "$k" = "-i" ]]; then
|
||||
CONFIRM=1
|
||||
fi
|
||||
done
|
||||
|
||||
tempfolders=()
|
||||
for f in "$@"; do
|
||||
[[ -e "$f" ]] || {
|
||||
if [[ ! -e "$f" ]]; then
|
||||
if [[ "$f" = "-i" ]]; then continue; fi
|
||||
echo "$f" does not exist
|
||||
continue
|
||||
}
|
||||
fi
|
||||
d=$( abs-path $( dirname "$f" ) )/.rm_bg.$$
|
||||
if [[ $CONFIRM -eq 1 ]]; then
|
||||
echo "Delete '$f'?"
|
||||
read -r -p "Are you sure? [y/N] " response
|
||||
case "$response" in
|
||||
[yY][eE][sS]|[yY])
|
||||
true
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
mkdir -p "$d"
|
||||
mv "$f" "$d"/
|
||||
tempfolders+=( "$d" )
|
||||
|
||||
Reference in New Issue
Block a user