1.在用戶 home目錄創建 ~/.lessfilter
touch ~/.lessfilter
2.添加腳本內容
#!/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";;
*)
if grep -q "#\!/bin/bash" "$1" 2> /dev/null; then
pygmentize -f 256 -l sh "$1"
else
exit 1
fi
esac
exit 0
3.設置環境變量 .bashrc
export LESS='-R'
export LESSOPEN='|~/.lessfilter %s'
4.賦予執行權限
chmod u+x ~/.lessfilter