bopher-ng

A better Gopher client in pure Bash
git clone git://git.luxferre.top/bopher-ng.git
Log | Files | Refs | README | LICENSE

commit 3dd367c5fb518db10f8b5accb618730af28436d1
parent 6e0d3ac2d347d6d883ff12e3a1e35a337876edb9
Author: Luxferre <lux@ferre>
Date:   Wed, 29 Mar 2023 18:59:13 +0300

Improved handling %09-separated search URLs

Diffstat:
Mbopher-ng.sh | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/bopher-ng.sh b/bopher-ng.sh @@ -126,18 +126,22 @@ amclick() { # args: AM line[, forcedl], output: AM line(s) local rport="${fields[3]}" local sel="${fields[4]}" local input='' - if [[ 'I' == "$action" ]]; then + local puresel="${sel%%\%09*}" # extract the pure selector (w/o possible input) + if [[ "$sel" != "$puresel" ]]; then # check selector for %09, if so, extract the input string + input="${sel##$puresel\%09}" + fi + if [[ 'I' == "$action" && -z "$input" ]]; then read -p "${LINECLR}${CURSTART}Enter input for $rhost: " input fi [[ ! -z "$2" ]] && action='D' # force the download action if [[ 'D' == "$action" ]]; then # download - local fname="${sel##*/}" # pure-bash version of basename + local fname="${puresel##*/}" # pure-bash version of basename [[ -z "$fname" ]] && fname='dl.dat' # just make sure that it's not empty [[ ! -z "$input" ]] && fname="${fname}%09${input}.search.txt" - gophetch "$rhost" "$rport" "$sel" "$input" > "$BOPHER_DLDIR/$fname" + gophetch "$rhost" "$rport" "$puresel" "$input" > "$BOPHER_DLDIR/$fname" printf 'E\tDownloaded %s to %s\n' "$(amtogopher "$1")" "$BOPHER_DLDIR/$fname" elif [[ 'I' == "$action" || 'M' == "$action" || 'P' == "$action" ]]; then # text content - readarray -t lines < <(gophetch "$rhost" "$rport" "$sel" "$input") + readarray -t lines < <(gophetch "$rhost" "$rport" "$puresel" "$input") for line in "${lines[@]}"; do # iterate over every fetched line if [[ 'P' == "$action" ]]; then # generate a plaintext AM entry printf 'E\t%s\n' "${line%%$'\r'}" # remove a trailing CR if it's there @@ -235,7 +239,7 @@ amload() { # args: AM line[, forcedl] } clicklink() { # click the currently focused link - if (( $FOCUSLINEINDEX > -1 )); then + if [[ ! -z "$FOCUSLINEINDEX" ]] && (( $FOCUSLINEINDEX > -1 )); then AMHISTORY+=("$CURRENTAM") # update the history chain amload "${SCREENBUF[$FOCUSLINEINDEX]}" "$1" fi