@@ -11,7 +11,7 @@ aqua=$(echo -en "\e[36m")
11
11
lightgreen=$( echo -en " \e[92m" )
12
12
Normal=' \033[0m'
13
13
Black=' \033[0;30m' # Black
14
- Red=' \033[0;31m' # Red
14
+ Red=$ '\033 [0;31m' # Red
15
15
Green=' \033[0;32m' # Green
16
16
Yellow=' \033[0;33m' # Yellow
17
17
Blue=' \033[0;34m' # Blue
@@ -205,6 +205,9 @@ function url_encode() {
205
205
206
206
# rclone_progress_bar -> progress_bar -> Print dowload link.
207
207
upload () {
208
+ if [[ $KSAUOPT_ADD_RAND_STR == true ]]; then
209
+ add_random_string " $( basename " $file " ) "
210
+ fi
208
211
echo " Initializing process, might take up to 10 seconds..."
209
212
rclone_progress_bar
210
213
wait
@@ -221,12 +224,17 @@ upload() {
221
224
222
225
help () {
223
226
echo "
224
- ${aqua} Usage : ksau [OPTION]... [FILE]...${normal}
227
+ ${aqua} Usage : ksau [-r] [OPTION]... [FILE]...${normal}
228
+
229
+ ${aqua} Options:${normal}
230
+ -r Add random string to the end of filename when uploading
231
+
232
+ Note that all options must be passed ${Red} BEFORE${normal} other arguments.
225
233
226
234
${aqua} upload [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
227
235
on index.
228
236
229
- ${aqua} upload -r [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
237
+ ${aqua} upload [FILE] [FOLDER]${normal} : Uploads the given file to the given folder
230
238
but with new filename with random strings
231
239
at last (before extension if present).
232
240
@@ -287,18 +295,27 @@ version() {
287
295
echo " ${orange}${KSAU_VERSION_STRING} ${normal} "
288
296
}
289
297
298
+ KSAUOPT_ADD_RAND_STR=false
299
+
300
+ while getopts " r" opt; do
301
+ case $opt in
302
+ r)
303
+ KSAUOPT_ADD_RAND_STR=true
304
+ ;;
305
+ ? )
306
+ # Getopts already print error for us so just exit
307
+ exit 1
308
+ ;;
309
+ esac
310
+ done
311
+
312
+ # Remove all args parsed by getopts
313
+ shift $(( OPTIND - 1 ))
314
+
290
315
if [[ $1 == " upload" ]]; then
291
- if [[ $2 == " -r" ]]; then
292
- shift
293
- readonly file=" $2 "
294
- readonly u_folder=" $3 "
295
- add_random_string $( basename " $file " )
296
- upload
297
- else
298
- readonly file=" $2 "
299
- readonly u_folder=" $3 "
300
- upload
301
- fi
316
+ readonly file=" $2 "
317
+ readonly u_folder=" $3 "
318
+ upload
302
319
elif [[ $1 == " setup" ]]; then
303
320
setup
304
321
elif [[ $1 == " dependencies" ]]; then
0 commit comments