improved list2map.sh a bit

This commit is contained in:
Luxferre
2023-04-04 07:28:39 +03:00
parent 8060459dc7
commit 7bd6a03e91
+5 -1
View File
@@ -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