Highlight syntax in 'less' command on source code. Colorful!!
# linux
sudo apt-get install source-highlight
# osx
brew install source-highlight
# osx only, for compatibility i have,
# if the file 'src-hilite-lesspipe.sh' not included, write it without line number:
# add the following into .bashrc
# example print-outs
# c code:
# python code
sweet. isn't it?
sudo apt-get install source-highlight
# osx
brew install source-highlight
# osx only, for compatibility i have,
sudo ln -s /usr/local/Cellar/source-highlight/3.1.8_2/bin/src-hilite-lesspipe.sh /usr/local/bin/
# if the file 'src-hilite-lesspipe.sh' not included, write it without line number:
1 #! /bin/sh
2
3 for source in "$@"; do
4 case $source in
5 *ChangeLog|*changelog)
6 source-highlight --failsafe -f esc --lang-def=changelog.lang --style-file=esc.style -i "$source" ;;
7 *Makefile|*makefile)
8 source-highlight --failsafe -f esc --lang-def=makefile.lang --style-file=esc.style -i "$source" ;;
9 *.tar|*.tgz|*.gz|*.bz2|*.xz)
10 lesspipe "$source" ;;
11 *) source-highlight --failsafe --infer-lang -f esc --style-file=esc.style -i "$source" ;;
12 esac
13 done
# add the following into .bashrc
### LESS ###
# Enable syntax-highlighting in less.
# brew install source-highlight
# First, add these two lines to ~/.bashrc
export LESSOPEN="| /usr/local/bin/src-hilite-lesspipe.sh %s"
export LESS=" -R "
alias less='less -m -N -g -i -J --underline-special --SILENT'
alias more='less'# example print-outs
# c code:
1 /*
2 * this is comment
3 */
4 #include
5
6 int main( int argc, char ** argv )
7 {
8 for (int i=0; i<10; i++)
9 {
10 printf("%d ", i);
11 }
12 for (int i=0; i<10; i++)
13 {
14 printf("%d ", i);
15 }
16
17 return 0;
18 }
# python code
1 #!/usr/bin/env python
2 import sys
3 def main(argv):
4 for x in range( len(sys.argv)-1 ):
5 print sys.argv[x+1]
6 print '+'.join(sys.argv[1:])
7
8 if __name__ == "__main__":
9 main(sys.argv[1:])
sweet. isn't it?
Labels: bash, less, linux, osx, syntax-coloring, syntax-detection
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home