chiark / gitweb /
Great reorganization.
[profile] / bin / lesspipe.sh
diff --git a/bin/lesspipe.sh b/bin/lesspipe.sh
new file mode 100755 (executable)
index 0000000..70d76d3
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+# This is a preprocessor for 'less'.  It is used when this environment
+# variable is set:   LESSOPEN="|lesspipe.sh %s"
+
+lesspipe() {
+  case "$1" in
+  *.tar) tar tvvf $1 2>/dev/null ;; # View contents of .tar and .tgz files
+  *.tgz|*.tar.gz|*.tar.Z|*.tar.z) gzip -dc $1 | tar tvvf - 2>/dev/null ;;
+  *.tar.bz2) bzip2 -dc $1 | tar tvvf - 2>/dev/null ;;
+  *.zip) unzip -l $1 2>/dev/null ;;
+  *.[1-9n]|*.man)
+    groff -te -Tascii -mandoc $1 ;;
+  *.[1-9].gz|*.man.gz)
+    gzip -dc $1 | groff -te -Tascii -mandoc ;;
+  *.Z|*.z|*.gz) gzip -dc $1  2>/dev/null ;; # View compressed files correctly
+  *.bz2) bzip2 -dc $1  2>/dev/null ;; # View compressed files correctly
+#  *) FILE=`file -L $1` ; # Check to see if binary, if so -- view with 'strings'
+#    FILE1=`echo $FILE | cut -d ' ' -f 2`
+#    FILE2=`echo $FILE | cut -d ' ' -f 3`
+#    if [ "$FILE1" = "Linux/i386" -o "$FILE2" = "Linux/i386" \
+#         -o "$FILE1" = "ELF" -o "$FILE2" = "ELF" ]; then
+#      strings $1
+#    fi ;;
+  esac
+}
+
+lesspipe $1