+unset iconv
+iconv() {
+ if [[ -z "$iconv" ]]; then
+ arg=$(printf "%s$(command iconv --help 2>/dev/null | \
+ sed -n 's/.*\(--.*-subst=\)\(FORMATSTRING\).*/\1\\033[7m?\\033[m/p' | \
+ tr \\n ' ')")
+ if [[ -n "$arg" ]]; then
+ iconv="command iconv -c $arg -t //TRANSLIT"
+ else
+ iconv="command iconv -c"
+ fi
+ fi
+ if $iconv "$@" > /dev/null 2>&1; then
+ msg "append $sep to filename to view the $2 encoded data"
+ $iconv "$@"
+ fi
+}
+
+msg () {
+ if [[ -n "$LESSQUIET" ]]; then
+ return
+ fi
+ echo "==> $@"
+}
+
+filetype () {
+ # wrapper for 'file' command
+ typeset name
+ name="$1"
+ if [[ "$1" = - ]]; then
+ dd bs=40000 count=1 > "$tmpdir/file" 2>/dev/null
+ set "$tmpdir/file" "$2"
+ name="$filen"
+ fi
+ typeset type
+ # type=" $(filecmd -b "$1")" # not supported by all versions of 'file'
+ type=$(filecmd "$1" | cut -d : -f 2-)
+ if [[ "$type" = " empty" ]]; then
+ # exit if file returns "empty" (e.g., with "less archive:nonexisting_file")
+ exit 1
+ elif [[ "$type" = *XML* && "$name" = *html ]]; then
+ type=" HTML document text"
+ elif [[ ("$type" = *HTML* || "$type" = *ASCII*) && "$name" = *xml ]]; then
+ type=" XML document text"
+ elif [[ "$type" != *lzip\ compressed* && ("$name" = *.lzma || "$name" = *.tlz) ]]; then
+ type=" LZMA compressed data"
+ elif [[ ("$type" = *Zip* || "$type" = *ZIP*) && ("$name" = *.jar || "$name" = *.xpi) ]]; then
+ type=" Zip compressed Jar archive"
+ elif [[ "$type" = *Microsoft\ Office\ Document* && ("$name" = *.ppt) ]]; then
+ type=" PowerPoint document"
+ elif [[ "$type" = *Microsoft\ Office\ Document* && ("$name" = *.xls) ]]; then
+ type=" Excel document"
+ fi
+ echo "$type"
+}
+