-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmvfem.sh
executable file
·111 lines (107 loc) · 3.07 KB
/
mvfem.sh
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
#
## @file mvfem.sh
## @brief Rename a downloaded Femjoy zip archive that contains two model names
## @remark New filename uses only one model's name so it will work with femzip
## @author Ronald Joe Record (rr at ronrecord dot com)
## @copyright Copyright (c) 2014, Ronald Joe Record, all rights reserved.
## @date Written 9-Aug-2014
## @version 1.0.1
##
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall the
# authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the Software or the use or other dealings in
# the Software.
#
D=$HOME/Downloads
## @fn usage()
## @brief Display command line usage options
## @param none
##
## Exit the program after displaying the usage message and example invocations
usage() {
printf "\nUsage: mvfem [-ridu] -m Model1 -p Model2"
printf "\n\tRename Femjoy zip archive from:"
printf "\n\t\tModel1_Model2_Photographer_Set_whatever.zip to"
printf "\n\t\tModel1_Photographer_Set_whatever.zip"
printf "\nWhere:"
printf "\n\t-r reverses the roles of Model1 and Model2"
printf "\n\t-i replaces %%2e with ."
printf "\n\t-d tells you what it would do"
printf "\n\t-u displays this usage message\n"
exit 1
}
DOT=
ECHO=
REVERSE=
while getopts m:p:rdiu flag; do
case $flag in
d)
ECHO=1;
;;
i)
DOT=1;
;;
r)
REVERSE=1;
;;
m)
M="$OPTARG";
;;
p)
P="$OPTARG";
;;
u)
usage;
;;
?)
usage;
;;
esac
done
cd "$D"
for i in "$M"*"$P"_*.zip
do
[ -f "$i" ] || {
printf "$i is not a regular file. Skipping.\n"
continue
}
if [ "$DOT" ]
then
T=`echo "$i" | sed -e "s/\%2e/\./g"`
if [ "$ECHO" ]
then
echo "mv $i $T"
echo ""
else
mv "$i" "$T"
fi
else
if [ "$REVERSE" ]
then
T=`echo "$i" | sed -e "s/${M}, ${P}_/${P}_/"`
else
T=`echo "$i" | sed -e "s/${M}, ${P}_/${M}_/"`
fi
if [ "$ECHO" ]
then
printf "mv $i $T\n"
else
mv "$i" "$T"
fi
fi
done