Skip to content

Commit fef8843

Browse files
author
Nhoya
committed
Added control over errors, Added -r option to reset history
1 parent 0adb4bd commit fef8843

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

z0r

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ readonly YELLOW="\033[00;33m"
2222
readonly BOLD="\033[01m"
2323
readonly FINE="\033[0m"
2424

25-
ver='1.4'
25+
ver='1.5'
2626
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*\.[A-Za-z0-9\+&@%#/=~_|():?]+'
2727
is_z0r='http://z0r.it/[^ \n]'
2828
url=(http://$1)
@@ -34,9 +34,14 @@ LOGDIR=/$HOME/.z0r_logs
3434
#upload function (long -> short)
3535
shr(){
3636
short=$(curl $mode -L "http://z0r.it/yourls-api.php?signature=$apikey&action=shorturl&title=uploaded_with_z0r_script&keyword=$2&format=simply&url=$1"|awk -F '/' '{print$NF}')
37+
uc="$http://z0r.it/$short"
3738
if [ -n "$short" ]; then
38-
echo "http://z0r.it/$short" && echo "$(date +"%d-%h-%Y %H.%M.%S") - http://z0r.it/$short - $1">>$LOGDIR
39-
echo "http://z0r.it/$short" |xclip -selection clipboard
39+
if curl $mode -L "http://z0r.it/yourls-api.php?signature=$apikey&action=shorturl&title=uploaded_with_z0r_script&keyword=$2&format=simply&url=$1" |grep -q "Errore 406"; then
40+
echo -e $RED"Error 406 - URL not valid(try to use https instead of http)"$FINE
41+
else
42+
echo "http://z0r.it/$short" && echo "$(date +"%d-%h-%Y %H.%M.%S") - $uc - $1">>$LOGDIR
43+
echo "$uc" |xclip -selection clipboard
44+
fi
4045
else
4146
if [ -n "$2" ]; then
4247
echo -e $RED"custom URL already in use"$FINE
@@ -66,6 +71,7 @@ help(){
6671
echo " -d check dependencies"
6772
echo " -l show shorting history"
6873
echo " -m <long_URL1> <long_URL2> ... mass shorting"
74+
echo " -r reset history"
6975
echo -e $GREEN"======================================================================================"$FINE
7076

7177
}
@@ -80,7 +86,12 @@ mss(){
8086
mass=$(curl -s -L "http://z0r.it/yourls-api.php?signature=$apikey&action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$i"|awk -F '/' '{print$NF}')
8187
if wget --spider "$i" 2>/dev/null; then
8288
if [ -n "$mass" ] ; then
83-
echo "http://z0r.it/$mass" && echo "$(date +"%d-%h-%Y %H.%M.%S") - http://z0r.it/$mass - $i">>$LOGDIR
89+
if curl $mode -L "http://z0r.it/yourls-api.php?signature=$apikey&action=shorturl&title=uploaded_with_z0r_script&format=simply&url=$i" |grep -q "Errore 406"; then
90+
echo -e $RED"Error 406 - URL not valid(try to use https instead of http)"$FINE
91+
else
92+
93+
echo "http://z0r.it/$mass" && echo "$(date +"%d-%h-%Y %H.%M.%S") - http://z0r.it/$mass - $i">>$LOGDIR
94+
fi
8495
else
8596
echo -e $RED"Bad Request"$FINE
8697
fi
@@ -123,7 +134,7 @@ checkdep(){
123134

124135
#option parser
125136
opsparser(){
126-
while getopts ":hvlde:c:m:" opt; do
137+
while getopts ":hvlrde:c:m:" opt; do
127138
case "$opt" in
128139
h) help
129140
exit 0
@@ -153,6 +164,9 @@ while getopts ":hvlde:c:m:" opt; do
153164
echo -e $GREEN"======================================================================================================="$FINE
154165
exit 0
155166
;;
167+
r) echo "" > $LOGDIR
168+
exit 0
169+
;;
156170
\?) echo -e $RED"enter a valid option, use -h for help"$FINE
157171
exit 0
158172
;;

0 commit comments

Comments
 (0)