summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-06-18 03:10:18 +0000
committerMike Frysinger <vapier@gentoo.org>2005-06-18 03:10:18 +0000
commitfc95c1636a33d284ac15ae7fe8f6588e7551daef (patch)
tree4d2b70460c74c18cfbbb8f7db238587ad46ae3fe /sys-apps/less/files
parentbump to gcc-4.0.1_rc2 snapshot (diff)
downloadgentoo-2-fc95c1636a33d284ac15ae7fe8f6588e7551daef.tar.gz
gentoo-2-fc95c1636a33d284ac15ae7fe8f6588e7551daef.tar.bz2
gentoo-2-fc95c1636a33d284ac15ae7fe8f6588e7551daef.zip
Import ideas from Redhats lesspipe.sh and add support for more files.
(Portage version: 2.0.51.22-r1)
Diffstat (limited to 'sys-apps/less/files')
-rw-r--r--sys-apps/less/files/lesspipe.sh120
1 files changed, 83 insertions, 37 deletions
diff --git a/sys-apps/less/files/lesspipe.sh b/sys-apps/less/files/lesspipe.sh
index 4710daa9f6ba..d7c9072fcfa6 100644
--- a/sys-apps/less/files/lesspipe.sh
+++ b/sys-apps/less/files/lesspipe.sh
@@ -5,40 +5,86 @@
trap 'exit 0' PIPE
-F=$1 # so we can use "set" later to play with positional params
-
-case "$F" in
- *.tar.bz2) tar tjvvf "$F" 2>/dev/null ;;
- *.tar.gz) tar tzvvf "$F" 2>/dev/null ;;
- *.tar.z) tar tzvvf "$F" 2>/dev/null ;;
- *.tar.Z) tar tzvvf "$F" 2>/dev/null ;;
- *.tar) tar tvvf "$F" 2>/dev/null ;;
- *.tbz2) tar tjvvf "$F" 2>/dev/null ;;
- *.tbz) tar tjvvf "$F" 2>/dev/null ;;
- *.tgz) tar tzvvf "$F" 2>/dev/null ;;
- *.bz2) bzip2 -dc "$F" 2>/dev/null ;;
- *.z) gzip -dc "$F" 2>/dev/null ;;
- *.Z) gzip -dc "$F" 2>/dev/null ;;
- *.zip) unzip -l "$F" 2>/dev/null ;;
- *.rpm) rpm -qilp --changelog "$F" 2>/dev/null ;;
- *.rar) unrar l "$F" 2>/dev/null ;;
-
- *.[1-9] | *.n | *.man)
- [[ $(file -L "$F") == *troff* ]] && \
- groff -S -s -p -t -e -Tascii -mandoc "$F" 2>/dev/null ;;
-
- *.[1-9].gz | *.n.gz | *.man.gz)
- [[ $(gzip -dc "$F" 2>/dev/null | file -) == *troff* ]] && \
- gzip -dc "$F" 2>/dev/null | groff -S -s -p -t -e -Tascii -mandoc ||
- gzip -dc "$F" 2>/dev/null ;;
-
- # keep this *after* testing for gzipped troff
- *.gz) gzip -dc "$F" 2>/dev/null ;;
-
- *)
- set -- $(file -L "$F")
- if [[ $2 == Linux/* || $3 == Linux/* || $2 == ELF || $3 == ELF ]]; then
- strings "$F"
- fi
- ;;
-esac
+guesscompress() {
+ case "$1" in
+ *.gz) echo "gunzip -c" ;;
+ *.bz2) echo "bunzip2 -c" ;;
+ *) echo "cat" ;;
+ esac
+}
+
+lesspipe() {
+ local DECOMPRESSOR=""
+
+ case "$match" in
+
+ ### Man pages ###
+ *.[0-9n]|*.man|\
+ *.[0-9n].bz2|*.man.bz2|\
+ *.[0-9n].gz|*.man.gz)
+ DECOMPRESSOR=$(guesscompress "$match")
+ if [[ $($DECOMPRESSOR -- "$1" | file -) == *troff* ]] ; then
+ if [[ $1 == /* ]] ; then
+ man -- "$1"
+ else
+ man -- "./$1"
+ fi
+ else
+ $DECOMPRESSOR -- "$1"
+ fi
+ ;;
+
+ ### Tar files ###
+ *.tar) tar tvvf "$1" ;;
+ *.tar.bz2|*.tbz2|*.tbz) tar tjvvf "$1" ;;
+ *.tar.gz|*.tgz|*.tar.z) tar tzvvf "$1" ;;
+
+ ### Misc archives ###
+ *.bz2) bzip2 -dc -- "$1" ;;
+ *.gz|*.z) gzip -dc -- "$1" ;;
+ *.zip) unzip -l "$1" ;;
+ *.rpm) rpm -qpivl --changelog -- "$1" ;;
+ *.cpi|*.cpio) cpio -itv < "$1" ;;
+ *.rar) unrar l -- "$1" ;;
+ *.ace) unace l -- "$1" ;;
+ *.arj) unarj l -- "$1" ;;
+ *.cab) cabextract -l -- "$1" ;;
+
+ ### Media ###
+ *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif|*.bmp)
+ if type -p identify > /dev/null ; then
+ identify "$1"
+ else
+ echo "Please emerge imagemagick in order"
+ echo "to view info about images"
+ fi
+ ;;
+ *.avi|*.mpeg|*.mpg|*.mov|*.qt|*.wmv|*.asf|*.rm)
+ # XXX: anyone have a better command ?
+ file -L -- "$1"
+ ;;
+
+ ### Everything else ###
+ *)
+ # Maybe we didn't match due to case issues ...
+ if [[ ${recur} == 0 ]] ; then
+ recur=1
+ match=$(echo $1 | tr '[:upper:]' '[:lower:]')
+ lesspipe "$1"
+ fi
+
+ local out=$(file -L -- "$1")
+ if [[ ${out} == *ELF* || ${out} == *a.out* ]] ; then
+ strings -- "$1"
+ fi
+ ;;
+ esac
+}
+
+if [[ -d $1 ]] ; then
+ ls -alF -- "$1"
+else
+ recur=0
+ match=$1
+ lesspipe "$1" 2> /dev/null
+fi