From c4ee895e27a12dfd20749fa7079cbcbd4f14cc2c Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Thu, 17 Jan 2013 14:51:45 +0100 Subject: [PATCH] Syntax colorization when opening in less --- .bashrc | 3 +++ lessfilter.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 lessfilter.sh diff --git a/.bashrc b/.bashrc index 0436cd9..d448584 100644 --- a/.bashrc +++ b/.bashrc @@ -105,6 +105,9 @@ alias tail='tail -n $((${LINES:-`tput lines 2>/dev/null||echo -n 12`} - 2))' # + support ANSI colors export LESS="-FX -R" +# Syntax coloring with pygments in less, when opening source files +export LESSOPEN='|~/code/dotfiles/lessfilter.sh %s' + # nautilus file manager in browser mode without destkop management alias nautile='nautilus --no-desktop --browser' diff --git a/lessfilter.sh b/lessfilter.sh new file mode 100755 index 0000000..2d224b0 --- /dev/null +++ b/lessfilter.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# Use Pygments to get syntax colorization in less +# export LESS=" -R" +# export LESSOPEN='|~/code/dotfiles/lessfilter %s' + +case "$1" in + *.awk|*.groff|*.java|*.js|*.m4|*.php|*.pl|*.pm|*.pod|*.sh|\ + *.ad[asb]|*.asm|*.inc|*.[ch]|*.[ch]pp|*.[ch]xx|*.cc|*.hh|\ + *.lsp|*.l|*.pas|*.p|*.xml|*.xps|*.xsl|*.axp|*.ppd|*.pov|\ + *.diff|*.patch|*.py|*.rb|*.sql|*.ebuild|*.eclass) + pygmentize -f 256 "$1";; + .bashrc|.bash_aliases|.bash_environment) + pygmentize -f 256 -l sh "$1" + ;; + *) + grep "#\!/bin/bash" "$1" > /dev/null + if [[ "$?" -eq "0" ]]; then + pygmentize -f 256 -l sh "$1" + else + exit 1 + fi +esac + +exit 0 +