Working implementation of quickdel

This commit is contained in:
Eric Torres 2022-10-01 11:12:37 -07:00
parent 0eefceac9f
commit 243b5207bf

View File

@ -20,7 +20,7 @@ WHITE_BOLD=$'\e[1;37m'
RESET=$'\e[0;0m' RESET=$'\e[0;0m'
declare -a extra_fd_opts declare -a extra_fd_opts
declare typeopt='file' declare -a typeopts
# ========== Helper functions ========== # ========== Helper functions ==========
function help() { function help() {
@ -92,12 +92,12 @@ function delete() {
while true; do while true; do
case "${1}" in case "${1}" in
'-d' | '--directories-only') '-d' | '--directories-only')
typeopt='directory' typeopts+=(--type directory)
shift shift
continue continue
;; ;;
'-e' | '--empty-only') '-e' | '--empty-only')
typeopt='empty' typeopts+=(--type empty)
shift shift
continue continue
;; ;;
@ -130,7 +130,7 @@ while true; do
continue continue
;; ;;
'-f' | '--files-only') '-f' | '--files-only')
typeopt='file' typeopts+=(--type file)
shift shift
continue continue
;; ;;
@ -150,7 +150,7 @@ while true; do
continue continue
;; ;;
'-l' | '--links-only') '-l' | '--links-only')
typeopt='symlink' typeopts+=(--type symlink)
shift shift
continue continue
;; ;;
@ -174,14 +174,13 @@ done
# Interpret options # Interpret options
if [[ -z "$*" ]]; then if [[ -z "$*" ]]; then
echo 'Please enter patterns of filenames to delete' help
exit 1
fi fi
declare -a files pattern_results declare -a files pattern_results
for pattern in "$@"; do for pattern in "$@"; do
readarray -d $'\n' -t pattern_results <<< "$(find_specific "$typeopt" "$pattern" "${extra_fd_opts[@]}")" readarray -d $'\n' -t pattern_results <<< "$(fd "${DEFAULT_FD_OPTS[@]}" "${extra_fd_opts[@]}" "${typeopts[@]}" "$pattern")"
files+=("${pattern_results[@]}") files+=("${pattern_results[@]}")
done done