Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7 Added more special cases to extarrange script. #34

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scripts/extarrange
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ require() {
}

require fd
require egrep
require grep

declare -A special_cases=(
['^*.(tar.*|tbz)$']='tar'
['\.(tar.*|tbz)$']='tar'
['\.(rar|rev|r00|r01)$']='rar'
['\.(doc.*|odt|pages|rtf|wpd|wps)$']='doc'
['\.(img|jpg|png)$']='img'
['\.(mp3|wav)$']='mp3'
# TODO: Add your own pattern here for similar file types appropriately
# Refer https://regex101.com/ & https://github.com/ziishaned/learn-regex/ for explaination and writing patterns
# These (regex) are same as ones used in sed command
Expand All @@ -21,13 +25,15 @@ fd -tf -d1 \
| while read file; do
folder="$PWD/${file##*.}"
for regex in "${!special_cases[@]}"; do
(echo "$file" | egrep -q "$regex") && {
(echo "$file" | grep -Eq "$regex") && {
folder="$PWD/${special_cases[$regex]}"
break
}
done

if [ ! -d "$folder" ]
then
mkdir -p "$folder"
fi
mv "$file" "$folder"
done