Skip to content

Instantly share code, notes, and snippets.

@nandhp
Created September 22, 2011 21:31
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nandhp/1236119 to your computer and use it in GitHub Desktop.
lesspipe + source-highlight integration
#!/bin/sh
#
# .lessfilter - Custom rules for lesspipe
#
# GNU source-highlight
SRC=/usr/bin/source-highlight
SRCOPTS="-f esc --style-file=esc.style -i"
# Directory listings
if [ -d "$1" ]; then
ls -lh --color "$1"
exit 0
fi
# Custom rules
#case "$1" in
# *.extension)
# extension-handler "$1"
# exit 0
# ;;
#esac
# Otherwise, try source highlighting
# Based on /usr/share/source-highlight/src-hilite-lesspipe.sh
case "$1" in
*ChangeLog|*changelog)
[ -x "$SRC" ] && \
"$SRC" $SRCOPTS "$1" --lang-def=changelog.lang && exit 0
;;
*Makefile|*makefile)
[ -x "$SRC" ] && \
"$SRC" $SRCOPTS "$1" --lang-def=makefile.lang && exit 0
;;
*)
[ -x "$SRC" ] && \
"$SRC" $SRCOPTS "$1" --infer-lang && exit 0
;;
esac
# Process further with lesspipe
exit 1
@AaronDMarasco-VSI
Copy link

The CentOS 7 system lesspipe (/usr/bin/lesspipe.sh):

  • Requires executable bit on this script
  • Intercepts the directories before calling this, so that section is ignored

Otherwise, works great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment