diff options
-rw-r--r-- | README.md | 4 | ||||
-rwxr-xr-x | gophed | 37 |
2 files changed, 33 insertions, 8 deletions
@@ -35,13 +35,13 @@ and `d`, which will be used as `gophed` commands. Once `gophed` has been initialised, you can start visiting some gopherholes: ``` - ./gophed / kalos.mine.nu 70 + ./gophed gopher://kalos.mine.nu ``` or equivalently: ``` - ./v / kalos.mine.nu 70 + ./v gopher://kalos.mine.nu ``` This command will download the corresponding resource, and print it on @@ -14,8 +14,8 @@ go () { usage() { printf '%s\n' \ 'usage:' \ - ' visit a resource:' \ - " $0 <path> <server> <port>" \ + ' visit a Gopher URL:' \ + " $0 <URL>" \ ' init links:' \ " $0 -i" \ ' show this help:' \ @@ -25,10 +25,35 @@ usage() { " !./g % LINE" \ 'to visit the resource at LINE, or:' \ " !./d % LINE" \ - 'to download the resource at LINE\n' + 'to download the resource at LINE\n'\ + " !./v URL" \ + 'to visit a Gopher URL' exit 0 } +goto_url(){ + 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)" + [ -z "$port" ] && port='70' + type=$(echo "$URL" | cut -s -d "/" -f 2) + [ -z "$type" ] && { + type='1' + sel="/" + go $sel $host $port + return + } + [ -n "${type#?}" ] && echo "Invalid Gopher URL" >&2 && exit 1 + ## Check if type is a valid one + 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 +} + + + trap cleanup INT QUIT HUP KILL ABRT TERM [ "$#" -lt 1 ] || [ "$1" = "-h" ] && usage @@ -46,8 +71,8 @@ fi 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" - cat "$SHOW" - | ed -p "$PROMPT" "$TMPFILE" + goto_url "$1" > "$TMPFILE" + while read line; do echo $line; done | ed -p "$PROMPT" "$TMPFILE" cleanup exit 0 fi @@ -62,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" - cat "$SHOW" - | ed -p "$PROMPT" "$TMPFILE" + while read line; do echo $line; done | ed -p "$PROMPT" "$TMPFILE" fi if [ "$script_name" = "d" ]; then DIR_RESOURCE="$(dirname "$RESOURCE")" |