Skip to content

Commit

Permalink
feat: add option to move or copy file
Browse files Browse the repository at this point in the history
  • Loading branch information
JowiAoun committed Oct 7, 2024
1 parent 402cc6d commit c7ce013
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions bin/dirclean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion lib/actions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit c7ce013

Please sign in to comment.