-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create logging, provide mapping
- Loading branch information
Showing
3 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# shellcheck disable=SC1091 | ||
source ./lib/interface.sh | ||
|
||
LOG_DIR=logs | ||
|
||
# Create a mapping of current file & directory positions, and their new position. | ||
function create_mapping() { | ||
# declare -A dir_map | ||
declare -n mapping="$1" | ||
|
||
cd "$1" || exit 1; | ||
cd "$2" || exit 1; | ||
|
||
files=$(ls) | ||
|
||
echo "$files" | ||
while IFS= read -r line; do | ||
if [[ -f "$line" ]]; then | ||
# extension="${line##*.}" | ||
|
||
mapping["$line"]="someDir/$line" #TODO: define a new directory based on extension | ||
|
||
# echo "$line -> ${mapping[$line]}" | ||
|
||
elif [[ -d "$line" ]]; then | ||
mapping["$line"]="directories/$line" | ||
|
||
# echo "$line -> ${mapping[$line]}" | ||
|
||
else | ||
print_invalid_file_or_dir "$line" ; exit 1 | ||
fi | ||
done <<< "$files" | ||
} | ||
|
||
function organize() { | ||
echo "Organize" #TODO | ||
# shellcheck disable=SC2178 | ||
declare -n mapping="$1" | ||
|
||
current_datetime=$(date +"%Y-%m-%d-%H:%M:%S") | ||
|
||
echo "Organizing..." | ||
|
||
if [[ "$2" == true && ! -d $LOG_DIR ]]; then | ||
mkdir $LOG_DIR | ||
fi | ||
|
||
for key in "${!mapping[@]}"; do | ||
echo "$key -> ${mapping[$key]}" | tee -a "$LOG_DIR/$current_datetime.log" | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters