1

Is it possible to get syntax highlighting for .gitignore files when using cat?

Update:

Tried sudo apt-get install python-pygments as suggested by @rovo but when using comments in the .gitignore it stops working.

Sample .gitignore (does not work):

# JetBrains IDEs
.idea

Sample .gitignore (works):

.idea

1 Answers1

2

Use pygmentize, e. g. by defining aliases like dog or pig!

Add this lines to ~/.bash_aliases (or perhaps ~/.bashrc):

alias dog='pygmentize -g'
alias pig='pygmentize -g -O style=colorful,linenos=1'

Afterwards restart your terminal or run source ~/.bashrc.

You might need to install python-pygments package:

sudo apt-get install python-pygments

Then you can run dog .gitgnore or pig .gitgnore

pygmentize - highlights the input file
Pygments is a generic syntax highlighter for general use in all kinds of software such as forum systems, wikis or other applications that need to prettify source code.

Murphy
  • 1,677
pLumo
  • 26,947