blob: cdaf697c09c45871139b0d35e90655e4a6ba141b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/bin/bash
OLDIFS=$IFS
IFS=$'\n' # make newlines the only separator
declare -a exprs=("\\\"([^\\\"]+)\\\"|“\1”" "\?|?" "\:|:" "\*|**" ">|>" "<|<" "\|||")
sedexpr=""
grepexpr="("
for i in "${exprs[@]}"; do
sedexpr+="s|"$i"|g; "
grepexpr+="$( cut -d '|' -f 1 <<< "$i" )|"
done
sedexpr="${sedexpr::-1}"
grepexpr="${grepexpr::-1})"
for path in $(find "$(pwd)" -type f); do
file=$( basename "$path" )
[[ ! $( grep -E "$grepexpr" 2>/dev/null <<< "$file" ) ]] && continue
while true; do
question="The following command is about to run: $ mv \"$file\" \"$( sed -r "$sedexpr" <<< "$file" )\""$'\n'"Is this okay [y/n]? "
read -p "$question" yn
case $yn in
[Yy]* ) mv "$file" "$( sed -r "$sedexpr" <<< "$file" )"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
done
IFS=$OLDIFS
# YOU CAN MAKE THE FILES GLOBAL THOUGH BY JUST REMOVING THE basename CLAUSE, SO DO THAT IF YOU GET ANNOYED AGAIN
# MAKE IT WORK WITH DIRECTORIES, AS WELL AS ABSOLUTE FILEPATHS (currently you have to run it from the folder of the offending song)
|