summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-01-24 17:06:18 +0000
committerKatolaZ <katolaz@freaknet.org>2019-01-24 17:06:18 +0000
commitacd8a0891086e1f7bfbf0cb4a17aa3f9ab21f118 (patch)
treec3ca79cf2be8725dc9b9017252692d4edb4f2442
parent380c0ef20abcd95477e4e690deb7840be95d9a98 (diff)
fix a few minor things -- thanks tfurrows
-rwxr-xr-xgophed21
1 files changed, 11 insertions, 10 deletions
diff --git a/gophed b/gophed
index c15e780..e512d25 100755
--- a/gophed
+++ b/gophed
@@ -22,27 +22,28 @@ usage() {
" $0 -h" \
'' \
'In a gopher page, just type:' \
- " !./g %% LINE" \
+ " !./g % LINE" \
'to visit the resource at LINE, or:' \
- " !./d %% LINE" \
+ " !./d % LINE" \
'to download the resource at LINE\n'
exit 0
}
trap cleanup INT QUIT HUP KILL ABRT TERM
-[ "$#" -lt 1 ] || [ "$1" = -h ] && usage
+[ "$#" -lt 1 ] || [ "$1" = "-h" ] && usage
-if [ "$0" = gophed ] && [ "$1" = -i ]; then
+script_name="$(basename "$0")"
+
+if [ "${script_name}" = "gophed" ] && [ "$1" = "-i" ]; then
ln -sf "$0" g
ln -sf "$0" d
ln -sf "$0" v
exit 0
fi
-script_name="$(basename "$0")"
-if [ "$script_name" = gophed ] || [ "$script_name" = v ]; then
+if [ "$script_name" = "gophed" ] || [ "$script_name" = "v" ]; then
sel="$(printf '%s' "$1" | sed -r 's:/:+:g')"
TMPFILE="$(mktemp "/tmp/gophed_${2}_${sel}_$3.XXXXXXXXXXXXXXXXXXX")"
go "$1" "$2" "$3" > "$TMPFILE"
@@ -51,19 +52,19 @@ if [ "$script_name" = gophed ] || [ "$script_name" = v ]; then
exit 0
fi
-if [ "$script_name" = g ] || [ "$script_name" = d ]; then
- LINE="$(awk "{if (NR == '$2') print '$0';}" "$1")"
+if [ "$script_name" = "g" ] || [ "$script_name" = "d" ]; then
+ LINE=$(awk "{if (NR == $2) print \$0;}" $1)
RESOURCE="$(printf '%s' "$LINE" | cut -d ' ' -f 2)"
HOST="$(printf '%s' "$LINE" | cut -d ' ' -f 3)"
PORT="$(printf '%s' "$LINE" | awk -F ' ' '{ match($4,/[[:digit:]]+/); print substr($4,RSTART,RLENGTH) }')"
- if [ "$script_name" = g ]; then
+ if [ "$script_name" = "g" ]; then
SEL="$(printf '%s' "$RESOURCE" | sed -r 's:/:+:g')"
TMPFILE="$(mktemp "/tmp/gophed_${HOST}_${SEL}_$PORT.XXXXXXXXXXXXXXXXXXX")"
go "$RESOURCE" "$HOST" "$PORT" > "$TMPFILE"
cat "$SHOW" - | ed -p "$PROMPT" "$TMPFILE"
fi
- if [ "$script_name" = d ]; then
+ if [ "$script_name" = "d" ]; then
DIR_RESOURCE="$(dirname "$RESOURCE")"
printf 'Download %s in %s\n' "$RESOURCE" "$HOST$RESOURCE"
mkdir -p "$HOST/$DIR_RESOURCE"