minor edits on variable quoting

master 0.1
KatolaZ 6 years ago
parent aa624aff7c
commit fdeee8ccf2
  1. 10
      README.md
  2. 18
      gophed

@ -44,8 +44,14 @@ or equivalently:
./v gopher://kalos.mine.nu ./v gopher://kalos.mine.nu
``` ```
This command will download the corresponding resource, and print it on This command will download the corresponding resource. If you want to
output with line numbers. An excerpt is reported below: print it on output with line numbers, just give the command:
```
%n [ENTER]
```
and you should see something like:
``` ```
... ...

@ -32,16 +32,16 @@ usage() {
} }
goto_url(){ goto_url(){
URL="$(echo $1 | sed 's,gopher://,,g')" URL="$(echo "$1" | sed 's,gopher://,,g')"
hostport=$(echo "$URL" | cut -d "/" -f 1) hostport=$(echo "$URL" | cut -d "/" -f 1)
host="$(echo $hostport | cut -d ":" -f 1)" host="$(echo "$hostport" | cut -d ":" -f 1)"
port="$(echo $hostport | cut -s -d ":" -f 2)" port="$(echo "$hostport" | cut -s -d ":" -f 2)"
[ -z "$port" ] && port='70' [ -z "$port" ] && port='70'
type=$(echo "$URL" | cut -s -d "/" -f 2) type=$(echo "$URL" | cut -s -d "/" -f 2)
[ -z "$type" ] && { [ -z "$type" ] && {
type='1' type='1'
sel="/" sel="/"
go $sel $host $port go "$sel" "$host" "$port"
return return
} }
[ -n "${type#?}" ] && echo "Invalid Gopher URL" >&2 && exit 1 [ -n "${type#?}" ] && echo "Invalid Gopher URL" >&2 && exit 1
@ -49,12 +49,12 @@ goto_url(){
type="$(echo $type | sed -n '/^[0-9ITghis+]$/p')" type="$(echo $type | sed -n '/^[0-9ITghis+]$/p')"
[ -z "${type}" ] && echo "Invalid Gopher URL" >&2 && exit 1 [ -z "${type}" ] && echo "Invalid Gopher URL" >&2 && exit 1
sel=/$(echo "$URL" | cut -s -d "/" -f 3-) 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 [ "$#" -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')" sel="$(printf '%s' "$1" | sed -r 's:/:+:g')"
TMPFILE="$(mktemp "/tmp/gophed_${2}_${sel}_$3.XXXXXXXXXXXXXXXXXXX")" TMPFILE="$(mktemp "/tmp/gophed_${2}_${sel}_$3.XXXXXXXXXXXXXXXXXXX")"
goto_url "$1" > "$TMPFILE" 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 cleanup
exit 0 exit 0
fi fi
@ -87,7 +87,7 @@ if [ "$script_name" = "g" ] || [ "$script_name" = "d" ]; then
SEL="$(printf '%s' "$RESOURCE" | sed -r 's:/:+:g')" SEL="$(printf '%s' "$RESOURCE" | sed -r 's:/:+:g')"
TMPFILE="$(mktemp "/tmp/gophed_${HOST}_${SEL}_$PORT.XXXXXXXXXXXXXXXXXXX")" TMPFILE="$(mktemp "/tmp/gophed_${HOST}_${SEL}_$PORT.XXXXXXXXXXXXXXXXXXX")"
go "$RESOURCE" "$HOST" "$PORT" > "$TMPFILE" 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 fi
if [ "$script_name" = "d" ]; then if [ "$script_name" = "d" ]; then
DIR_RESOURCE="$(dirname "$RESOURCE")" DIR_RESOURCE="$(dirname "$RESOURCE")"
@ -98,7 +98,7 @@ if [ "$script_name" = "g" ] || [ "$script_name" = "d" ]; then
cleanup cleanup
exit 0 exit 0
fi fi
printf '%s: command not found\n' "$scriptname" printf '%s: command not found\n' "$script_name"
cleanup cleanup

Loading…
Cancel
Save