Skip to content

Commit a385302

Browse files
author
Nhoya
committed
Added -l option for history, added error when custom link is already in use, minor fixes
1 parent dbac0f4 commit a385302

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

z0r

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

25-
ver='1.2'
25+
ver='1.3'
2626
regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*\.[-A-Za-z0-9\+&@#/%=~_|():?]+'
2727
is_z0r='http://z0r.it/[^ \n]'
2828
url=(http://$1)
2929
mode=-s
3030
dep=(curl awk xclip wget)
3131
apikey=4e4b657a91
32+
LOGDIR=/$HOME/.z0r_logs
3233
#upload function (long -> short)
3334
shr(){
3435
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}')
35-
echo "http://z0r.it/$short"
36+
if [ -n "$short" ]; then
37+
echo "http://z0r.it/$short" && echo "$(date +"%d-%h-%Y %H.%M.%S") - http://z0r.it/$short - $1">>$LOGDIR
3638
echo "http://z0r.it/$short" |xclip -selection clipboard
39+
else
40+
if [ -n "$2" ]; then
41+
echo -e $RED"custom URL already in use"$FINE
42+
fi
43+
fi
3744
}
3845
#expand function (short -> long)
3946
expand(){
@@ -54,8 +61,9 @@ help(){
5461
echo " Available Options:"
5562
echo " -e <short_URL> expand URL (short -> long)"
5663
echo " -h display this page"
57-
echo " -c<short_URL> display numbers of clicks"
64+
echo " -c <short_URL> display numbers of clicks"
5865
echo " -d check dependencies"
66+
echo " -l show shorting history"
5967
echo -e $GREEN"======================================================================================"$FINE
6068

6169
}
@@ -100,7 +108,7 @@ done
100108

101109
#option parser
102110
opsparser(){
103-
while getopts ":hvde:c:" opt; do
111+
while getopts ":hvlde:c:" opt; do
104112
case "$opt" in
105113
h) help
106114
exit 0
@@ -121,6 +129,11 @@ while getopts ":hvde:c:" opt; do
121129
v) echo $ver
122130
exit 0
123131
;;
132+
l) echo -e $GREEN"====================================================LOGs==============================================="$FINE
133+
cat $LOGDIR
134+
echo -e $GREEN"======================================================================================================="$FINE
135+
exit 0
136+
;;
124137
\?) echo -e $RED"enter a valid option, use -h for help"$FINE
125138
exit 0
126139
;;

0 commit comments

Comments
 (0)