rename commands & check for empty argument list

master
KatolaZ 7 years ago
parent bdfe168ec8
commit da1b7d1640

@ -19,20 +19,24 @@ usage() {
printf " $0 -h\n" printf " $0 -h\n"
printf "\n" printf "\n"
printf "In a gopher page, just type:\n" printf "In a gopher page, just type:\n"
printf " !./visit %% LINE\n" printf " !./g %% LINE\n"
printf "to visit the resource at LINE, or:\n" printf "to visit the resource at LINE, or:\n"
printf " !./dl %% LINE\n" printf " !./d %% LINE\n"
printf "to download the resource at LINE\n\n" printf "to download the resource at LINE\n\n"
exit 0 exit 0
} }
trap cleanup INT QUIT HUP KILL ABRT TERM trap cleanup INT QUIT HUP KILL ABRT TERM
if [ $# -lt 1 ]; then
usage
fi
if [ "$1" = "-h" ]; then usage; fi if [ "$1" = "-h" ]; then usage; fi
if [ "$1" = "-i" ]; then if [ "$1" = "-i" ]; then
ln -s $0 visit ln -s $0 g
ln -s $0 dl ln -s $0 d
exit 0 exit 0
fi fi
@ -44,7 +48,7 @@ if [ "${script_name}" = "gophed" ]; then
go "$1" "$2" "$3" > $TMPFILE go "$1" "$2" "$3" > $TMPFILE
cat show - show | ed $TMPFILE cat show - show | ed $TMPFILE
fi fi
if [ "${script_name}" = "visit" ]; then if [ "${script_name}" = "g" ]; then
LINE=$(awk "{if (NR == $2) print \$0;}" $1) LINE=$(awk "{if (NR == $2) print \$0;}" $1)
RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2) RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2)
HOST=$(echo "$LINE" | cut -d ' ' -f 3) HOST=$(echo "$LINE" | cut -d ' ' -f 3)
@ -54,7 +58,7 @@ if [ "${script_name}" = "visit" ]; then
go "$RESOURCE" "$HOST" "$PORT" > $TMPFILE go "$RESOURCE" "$HOST" "$PORT" > $TMPFILE
cat show - show | ed $TMPFILE cat show - show | ed $TMPFILE
fi fi
if [ "${script_name}" = "dl" ]; then if [ "${script_name}" = "d" ]; then
LINE=$(awk "{if (NR == $2) print \$0;}" $1) LINE=$(awk "{if (NR == $2) print \$0;}" $1)
RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2) RESOURCE=$(echo "$LINE" | cut -d ' ' -f 2)
HOST=$(echo "$LINE" | cut -d ' ' -f 3) HOST=$(echo "$LINE" | cut -d ' ' -f 3)

Loading…
Cancel
Save