zshenv: switch preference order of lesspipe.sh vs lesspipe
authorMichael Prokop <mika@grml.org>
Mon, 22 Sep 2014 08:12:50 +0000 (10:12 +0200)
committerMichael Prokop <mika@grml.org>
Mon, 22 Sep 2014 09:26:27 +0000 (11:26 +0200)
The lesspipe script as shipped by the less package itself seems
to be better maintained nowadays than the lesspipe.sh script
as shipped with the grml-script-core package.

While lesspipe.sh supports the "less $archive:$file" workflow to
display a file inside an archive, which isn't supported by
lesspipe yet, it sadly fails on more common tasks like with our
dchange function on recent Debian versions. E.g. 'dchange vim'
just displays:

| ==> append : to filename to view the UTF-8 encoded data

on Debian/jessie instead of displaying content of
/usr/share/doc/vim/changelog.Debian.gz.

While at it make the check for lesspipe path agnostic,
thanks Frank Terbeck <ft@grml.org> for assistance.

etc/zsh/zshenv

index 57e45f2..bf6c819 100644 (file)
@@ -79,11 +79,14 @@ esac
 
 # less (:=pager) options:
 #  export LESS=C
-if [[ -x /usr/bin/lesspipe.sh ]] ; then
-    export LESSOPEN="|lesspipe.sh %s"
-elif [[ -x /usr/bin/lesspipe ]] ; then
+typeset -a lp; lp=( ${^path}/lesspipe(N) )
+if (( $#lp > 0 )) && [[ -x $lp[1] ]] ; then
     export LESSOPEN="|lesspipe %s"
+elif [[ -x /usr/bin/lesspipe.sh ]] ; then
+    export LESSOPEN="|lesspipe.sh %s"
 fi
+unset lp
+
 export READNULLCMD=${PAGER:-/usr/bin/pager}
 
 # allow zeroconf for distcc