From 7bd6a03e91291b0437b9e4dd5549ad1f977dcc1b Mon Sep 17 00:00:00 2001 From: Luxferre Date: Tue, 4 Apr 2023 07:28:39 +0300 Subject: [PATCH] improved list2map.sh a bit --- tools/list2map.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/list2map.sh b/tools/list2map.sh index 08f6db0..44df30d 100644 --- a/tools/list2map.sh +++ b/tools/list2map.sh @@ -21,6 +21,7 @@ typequery() { # external command wrapper to fetch the file's MIME type while read -rs fpath; do # fully line-based operation ftype="$(typequery "$fpath")" # MIME type here bname="${fpath##*/}" # basename here + desc="$bname" # default to the basename [[ "$bname" == "$INDEXFILE" ]] && continue # skip index map etype=9 # default map entry type is binary until proven otherwise esel="${fpath##$RDIR}" # if RDIR is empty, they are the same @@ -29,7 +30,10 @@ while read -rs fpath; do # fully line-based operation esel="${esel}/${INDEXFILE}" # update the selector elif [[ "${ftype%%/*}" == 'text' ]]; then # update etype for text files etype=0 + read -rsd$'\r' desc < "$fpath" # read the first file line as the description/title + desc="${desc##*([[:blank:]])}" # remove leading whitespace + desc="${desc%%*([[:blank:]])}" # remove trailing whitespace fi # output the RFC-compliant Gophermap line - printf '%s%s\t%s\t%s\t%s\r\n' "$etype" "$bname" "$esel" "$THOST" "$TPORT" + printf '%s%s\t%s\t%s\t%s\r\n' "$etype" "$desc" "$esel" "$THOST" "$TPORT" done -- 2.45.2