|
|
|
@ -32,16 +32,16 @@ usage() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
goto_url(){ |
|
|
|
|
URL="$(echo $1 | sed 's,gopher://,,g')" |
|
|
|
|
URL="$(echo "$1" | sed 's,gopher://,,g')" |
|
|
|
|
hostport=$(echo "$URL" | cut -d "/" -f 1) |
|
|
|
|
host="$(echo $hostport | cut -d ":" -f 1)" |
|
|
|
|
port="$(echo $hostport | cut -s -d ":" -f 2)" |
|
|
|
|
host="$(echo "$hostport" | cut -d ":" -f 1)" |
|
|
|
|
port="$(echo "$hostport" | cut -s -d ":" -f 2)" |
|
|
|
|
[ -z "$port" ] && port='70' |
|
|
|
|
type=$(echo "$URL" | cut -s -d "/" -f 2) |
|
|
|
|
[ -z "$type" ] && { |
|
|
|
|
type='1' |
|
|
|
|
sel="/" |
|
|
|
|
go $sel $host $port |
|
|
|
|
go "$sel" "$host" "$port" |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
[ -n "${type#?}" ] && echo "Invalid Gopher URL" >&2 && exit 1 |
|
|
|
@ -49,12 +49,12 @@ goto_url(){ |
|
|
|
|
type="$(echo $type | sed -n '/^[0-9ITghis+]$/p')" |
|
|
|
|
[ -z "${type}" ] && echo "Invalid Gopher URL" >&2 && exit 1 |
|
|
|
|
sel=/$(echo "$URL" | cut -s -d "/" -f 3-) |
|
|
|
|
go $sel $host $port |
|
|
|
|
go "$sel" "$host" "$port" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trap cleanup INT QUIT HUP KILL ABRT TERM |
|
|
|
|
trap cleanup INT QUIT HUP ABRT TERM |
|
|
|
|
|
|
|
|
|
[ "$#" -lt 1 ] || [ "$1" = "-h" ] && usage |
|
|
|
|
|
|
|
|
@ -72,7 +72,7 @@ if [ "$script_name" = "gophed" ] || [ "$script_name" = "v" ]; then |
|
|
|
|
sel="$(printf '%s' "$1" | sed -r 's:/:+:g')" |
|
|
|
|
TMPFILE="$(mktemp "/tmp/gophed_${2}_${sel}_$3.XXXXXXXXXXXXXXXXXXX")" |
|
|
|
|
goto_url "$1" > "$TMPFILE" |
|
|
|
|
while read line; do echo $line; done | ed -p "$PROMPT" "$TMPFILE" |
|
|
|
|
while read -r line; do echo "$line"; done | ed -p "$PROMPT" "$TMPFILE" |
|
|
|
|
cleanup |
|
|
|
|
exit 0 |
|
|
|
|
fi |
|
|
|
@ -87,7 +87,7 @@ if [ "$script_name" = "g" ] || [ "$script_name" = "d" ]; then |
|
|
|
|
SEL="$(printf '%s' "$RESOURCE" | sed -r 's:/:+:g')" |
|
|
|
|
TMPFILE="$(mktemp "/tmp/gophed_${HOST}_${SEL}_$PORT.XXXXXXXXXXXXXXXXXXX")" |
|
|
|
|
go "$RESOURCE" "$HOST" "$PORT" > "$TMPFILE" |
|
|
|
|
while read line; do echo $line; done | ed -p "$PROMPT" "$TMPFILE" |
|
|
|
|
while read -r line; do echo "$line"; done | ed -p "$PROMPT" "$TMPFILE" |
|
|
|
|
fi |
|
|
|
|
if [ "$script_name" = "d" ]; then |
|
|
|
|
DIR_RESOURCE="$(dirname "$RESOURCE")" |
|
|
|
@ -98,7 +98,7 @@ if [ "$script_name" = "g" ] || [ "$script_name" = "d" ]; then |
|
|
|
|
cleanup |
|
|
|
|
exit 0 |
|
|
|
|
fi |
|
|
|
|
printf '%s: command not found\n' "$scriptname" |
|
|
|
|
printf '%s: command not found\n' "$script_name" |
|
|
|
|
|
|
|
|
|
cleanup |
|
|
|
|
|
|
|
|
|