From c7ce0136ce9bf765076efe1824410ffdf739ae78 Mon Sep 17 00:00:00 2001 From: jowi Date: Mon, 7 Oct 2024 11:33:56 -0400 Subject: [PATCH] feat: add option to move or copy file --- bin/dirclean.sh | 7 +++++-- lib/actions.sh | 6 +++++- lib/interface.sh | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bin/dirclean.sh b/bin/dirclean.sh index 81c057c..4ee7d63 100755 --- a/bin/dirclean.sh +++ b/bin/dirclean.sh @@ -14,15 +14,17 @@ function main() { directory=. log=false dry_run=false + copy=false # Read all positional arguments - while getopts ":hvlnd:" opt; do + while getopts ":hvlncd:" opt; do case ${opt} in h ) print_help ; exit 0 ;; v ) print_version "$version"; exit 0 ;; d ) directory=$OPTARG ; echo "Directory to organize: '$directory'" ;; l ) log=true ;; n ) dry_run=true ;; + c ) copy=true ;; \? ) print_invalid_opt "$OPTARG" ; exit 1 ;; : ) print_invalid_value "$OPTARG" ; exit 1 ;; esac @@ -35,8 +37,9 @@ function main() { # Organize if [[ $dry_run == false ]]; then - organize _mapping "$log" "$directory" + organize _mapping "$log" "$directory" "$copy" else + echo "-------" echo "Because this was a dry run, no modifications were completed." fi } diff --git a/lib/actions.sh b/lib/actions.sh index 45039ac..388afe0 100644 --- a/lib/actions.sh +++ b/lib/actions.sh @@ -71,7 +71,11 @@ function organize() { mkdir -p "$target_dir" if [[ -f "$key" || -d "$key" ]]; then - cp -r "$key" "$target_dir" + if [[ "$4" == false ]]; then + mv -r "$key" "$target_dir" + else + cp -r "$key" "$target_dir" + fi else echo "File '$key' does not exist -> Skipping" fi diff --git a/lib/interface.sh b/lib/interface.sh index 92dfb6b..8381537 100644 --- a/lib/interface.sh +++ b/lib/interface.sh @@ -7,6 +7,7 @@ function print_help() { -d, --directory Directory to organize. Default: current directory. -l, --log Enable logging. -n, --dry-run Perform dry-run to preview changes. + -c, --copy Copy instead of moving directories. ">&2 }