5 ms·
There's also the "python-pygments" package which provides awesome syntax highlighting. You can alias it to ccat too: alias ccat='pygmentize -g'
by mavidser 11y ago
There's also the "python-pygments" package which provides awesome syntax highlighting. You can alias it to ccat too:
alias ccat='pygmentize -g'
- IgnotisAnon 11y agoI do the same. It's funny to see a program with the same name as my alias doing the same thing.
- klibertp 11y agoEspecially if you need something more than "JavaScript, Java, Ruby, Python, Go, and C" - pygments has a list of supported languages a tiny bit longer than that: http://pygments.org/languages/ http://pygments.org/languages/ True, it takes some time to highlight some files - for example 5k loc long Racket files or very long XML/HTML files - but it supports all the languages I use (or used or may use in the future), while this tool supports only one of the languages I use on a daily basis.
- a3n 11y agoBrilliant! While I was reading the ccat page I was wishing it was a colorized less, rather than a colorized cat. Then I thought to read the man page for less, because sometimes what you want is already there. And it does handle color, but only if they're escaped colors. Oh well. Then I saw your comment, tried pygmentize on a python script, and there's some nice colored code, that scrolled off the terminal. Then I piped that into less, just to be grumpy. Yep, it's all white ... but wait, what are all those escape characters? ... pygmentize -g myScript.py |less -r The colors! The colors! And in less, no less.
- rraval 11y agoJust a quick tip, you would want to use `less -R` (upper case R) instead. `less -r` allows all raw characters which makes it difficult for less to maintain screen appearance. From the man page: -R or --RAW-CONTROL-CHARS Like -r, but only ANSI "color" escape sequences are output in "raw" form. Unlike -r, the screen appearance is maintained correctly in most cases.
- gh02t 11y agoYou can use vimpager instead of less to get highlighting if you want.
- a3n 11y agoI usta do that, but there were occasional quirks. But then, I have occasional quirks and I'm still allowed out of the house.
- Splognosticus 11y agoYou might also want to take a look at less's input preprocessor, which could be used to automatically colorize source.
- woof 11y agoInstall src-hilite and use LESSOPEN: LESS=' -R ' LESSOPEN='| /usr/local/bin/src-hilite-lesspipe.sh %s'
- gvalkov 11y agoI have a small wrapper around `pygmentize -g` in my dotfiles that optionally overwrites the lexer based on the mime-type, as determined by `file`: https://github.com/gvalkov/dotfiles/blob/master/bin/cats https://github.com/gvalkov/dotfiles/blob/master/bin/cats
- progman 11y agoYes, brilliant! I read http://pygments.org/docs/styles http://pygments.org/docs/styles and other sites but I didn't find how I can change the default colors. Do I have to edit (clone) pygments or is there a config file?
- mavidser 11y agoPretty sure there's no config file, as of now. For what it's worth, here's[1] the file which describes the colors used in the source. List of colors[2]. [1] https://bitbucket.org/birkenfeld/pygments-main/src/a287342ee7165f50fdd54e3500be48256222cff6/pygments/formatters/terminal.py?at=default#cl-27 https://bitbucket.org/birkenfeld/pygments-main/src/a287342ee... [2] https://bitbucket.org/birkenfeld/pygments-main/src/a287342ee7165f50fdd54e3500be48256222cff6/pygments/console.py?at=default#cl-25 https://bitbucket.org/birkenfeld/pygments-main/src/a287342ee...
- progman 11y agoThanks!
- meandave 11y agoI got a tad further and detect if the file is markdown, if so i will display in lynx https://github.com/meandavejustice/dotfiles/blob/master/bin/ccat https://github.com/meandavejustice/dotfiles/blob/master/bin/...