]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
less: Add all the nice features to less we usually have.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jun 2010 19:24:08 +0000 (21:24 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 3 Jun 2010 19:24:08 +0000 (21:24 +0200)
Add lesspipe.sh with profile configuration.
Remove --with-secure which disables important features.

pkgs/core/less/less.nm
pkgs/core/less/less.sh [new file with mode: 0644]
pkgs/core/less/lesspipe.sh [new file with mode: 0644]

index b17d8ce54ff12aeb6512cae60b573bba37f2776a..103472326cda241932f9a6f027f7a4024786ff64 100644 (file)
@@ -46,4 +46,14 @@ endef
 
 PKG_TARBALL    = $(THISAPP).tar.gz
 
-CONFIGURE_OPTIONS += --with-secure --with-regex=pcre
+CONFIGURE_OPTIONS += --sysconfdir=/etc --with-regex=pcre
+
+CFLAGS += -D_GNU_SOURCE
+
+define STAGE_INSTALL_CMDS
+       -mkdir -pv $(BUILDROOT)/etc/profile.d
+       install -v -m 755 $(DIR_SOURCE)/less.sh $(BUILDROOT)/etc/profile.d
+
+       -mkdir -pv $(BUILDROOT)/usr/bin
+       install -v -m 755 $(DIR_SOURCE)/lesspipe.sh $(BUILDROOT)/usr/bin
+endef
diff --git a/pkgs/core/less/less.sh b/pkgs/core/less/less.sh
new file mode 100644 (file)
index 0000000..a7569fb
--- /dev/null
@@ -0,0 +1,2 @@
+# less initialization script (sh)
+[ -x /usr/bin/lesspipe.sh ] && export LESSOPEN="|/usr/bin/lesspipe.sh %s"
diff --git a/pkgs/core/less/lesspipe.sh b/pkgs/core/less/lesspipe.sh
new file mode 100644 (file)
index 0000000..3d67505
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# To use this filter with less, define LESSOPEN:
+# export LESSOPEN="|/usr/bin/lesspipe.sh %s"
+
+lesspipe() {
+  case "$1" in
+  *.[1-9n]|*.man|*.[1-9n].bz2|*.man.bz2|*.[1-9].gz|*.[1-9]x.gz|*.man.gz|*.[1-9].xz|*.[1-9]x.xz|*.man.xz)
+       case "$1" in
+               *.gz)   DECOMPRESSOR="gunzip -c" ;;
+               *.bz2)  DECOMPRESSOR="bunzip2 -c" ;;
+               *)      DECOMPRESSOR="cat" ;;
+       esac
+       if $DECOMPRESSOR -- "$1" | file - | grep -q troff; then
+               if echo "$1" | grep -q ^/; then #absolute path
+                       man -- "$1" | cat -s
+               else
+                       man -- "./$1" | cat -s
+               fi
+       else
+               $DECOMPRESSOR -- "$1"
+       fi ;;
+  *.tar) tar tvvf "$1" ;;
+  *.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1" ;;
+  *.tar.xz) tar Jtvvf "$1" ;;
+  *.xz) xz -dc -- "$1" ;;
+  *.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf - ;;
+  *.[zZ]|*.gz) gzip -dc -- "$1" ;;
+  *.bz2) bzip2 -dc -- "$1" ;;
+  *.lzma) lzma -c -d -- "$1" ;;
+  *.zip|*.jar|*.nbm) zipinfo -- "$1" ;;
+  *.rpm) rpm -qpivl --changelog -- "$1" ;;
+  *.cpi|*.cpio) cpio -itv < "$1" ;;
+  *.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif)
+   if [ -x /usr/bin/identify ]; then
+     identify "$1"
+   elif [ -x /usr/bin/gm ]; then
+     gm identify "$1"
+   else
+     echo "No identify available"
+     echo "Install ImageMagick or GraphicsMagick to browse images"
+   fi ;;
+  *)
+       case "$1" in
+               *.gz)   DECOMPRESSOR="gunzip -c" ;;
+               *.bz2)  DECOMPRESSOR="bunzip2 -c" ;;
+               *.xz)   DECOMPRESSOR="unxz -c" ;;
+       esac
+       if [ ! -z $DECOMPRESSOR ] ; then
+               $DECOMPRESSOR -- "$1" ;
+       fi
+  esac
+}
+
+if [ -d "$1" ] ; then
+       /bin/ls -alF -- "$1"
+else
+       lesspipe "$1" 2> /dev/null
+fi