Last active
April 15, 2025 04:14
-
Star
(101)
You must be signed in to star a gist -
Fork
(14)
You must be signed in to fork a gist
-
-
Save BretFisher/6f688dde0122399efdca5a9d26100437 to your computer and use it in GitHub Desktop.
On macOS: Install pygmentize and alias pcat for shell code syntax highlighting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first install pygmentize to the mac OS X or macOS system with the built-in python | |
sudo easy_install Pygments | |
# then add alias to your ~/.bash_profile or ~/.bashrc or ~/.zshrc etc. | |
alias pcat='pygmentize -f terminal256 -O style=native -g' |
I randomly came across this gist. But man, this is just fantastic!!!!!!!!!
Thanks a lot for the idea and alias.
Thanks indeed...this is great!!
This is awesome! Thank you
Found this one while learning your course about Docker!
Thanks for the course and this gist too!
Found this one while learning your course about Docker too! -- Thank you, much appreciated!
Yeah me too Docker course :))
Was looking for something like this. Thanks!
Delicious.
Thanks, It's great :)
I've stopped using pcat years ago, and now use bat: https://github.com/sharkdp/bat
I was about to install the Pygments
but now going to give a shot to bat
I've stopped using pcat years ago, and now use bat: https://github.com/sharkdp/bat
Greate advice. Thanks.
thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, your pcat command is great stuff.
But I should show people how to install Pygments with Python3 (it's faster than Python2, which means faster bootup and faster colorizing, in other words it takes less time to run the pygmentize command).
First, install python2 and python3 properly via Homebrew as follows:
Then, to install Pygments, I just ran:
Now the
pygmentize
command is available. Voila. :-)Thanks again for your great pygmentize options alias! 👍 It got me started with pygmentize!
Also a note for others, regarding this command:
alias pcat='pygmentize -f terminal256 -O style=native -g'
pygmentize -L styles
lists all styles, if you don't like thestyle=native
theme used above. Personally, I use:alias pcat='pygmentize -f terminal256 -O style=monokai -g'
As for the command itself, it's correctly setup (I checked via
pygmentize -h
). There's really nothing else that needs configuring. It's saying: "Output to 256-color terminal, use the Native color-style/theme, and Guess what format the source code is based on file extension."Regarding the styles, most of them are not good for terminal (due to things like black text on a black background). But here's a list of the best ones for terminal (and the absolute best ones are
monokai
andnative
):