Skip to content

Instantly share code, notes, and snippets.

@timbirk
Last active June 20, 2018 09:40
Show Gist options
  • Save timbirk/b22aeb3afebce443c02dcdf62dbbf52c to your computer and use it in GitHub Desktop.
Save timbirk/b22aeb3afebce443c02dcdf62dbbf52c to your computer and use it in GitHub Desktop.
Following sets everything up to colorise less output.
# Pre-requisite
pip install pygments
cat << EOF > ~/.lessfilter
#!/bin/sh
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
EOF
chmod u+x ~/.lessfilter
echo export LESS='-R' >> ~/.bashrc
echo export LESSOPEN='|~/.lessfilter %s' >> ~/.bashrc
# Close and re-open terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment