7 ms·
Ccat – syntax highlighting cat
- deleted 11y ago[deleted]
- alfiedotwtf 11y agoNot to diminish OP's project, but I pipe most things to vim to get all my standard highlighting goodness: cat file_name | vi -
- mfontani 11y agoto avoid the "useless use of cat", I find this approach most welcome at the end of a long pipe, i.e.: grep ... files | sed ... | awk ... | vim -
- oops 11y agoI do something similar except with "view" aka "vi -R" aka read-only mode. A couple things I like about "view": 1. No warning screen when using "view file.c" if you or someone else happens to have the same file open for editing. 2. No "unsaved changes" prompt when quitting "view -" (or in other words, no need to force-quit with :q!) Edit: Also worth noting is that "view file.c" vs "cat file.c |view -" gives vim a better chance of getting the syntax highlighting right since it knows the file extension.
- deleted 11y ago[deleted]
- klibertp 11y agoMandatory mention: Emacs works here as well, but is less practical because of longer startup times.
- albinoloverats 11y agoI've been using source-highlight[1] to achieve the same result. [edit]: alias ccat="source-highlight --out-format=esc --style-file=/usr/share/source-highlight/esc.style --failsafe -i " I'll have to see how this compares. [1]: http://www.gnu.org/software/src-highlite/ http://www.gnu.org/software/src-highlite/
- mavidser 11y agoThere'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.
- xupybd 11y agoBeen using this for a while http://www.vim.org/scripts/script.php?script_id=4325 http://www.vim.org/scripts/script.php?script_id=4325
- amelius 11y agoI'm so glad my brain does the syntax highlighting for me.
- chrisan 11y agoSome people also say they are glad/happy to code in Notepad.exe Brains do a lot of things, but there is a limit somewhere or at the very least a trade off of speed. Simple things like syntax highlighting can help you find what you are looking for faster.
- codychan 11y agoWhy not use `less` instead of `cat`? Besides it is very easy to use `pygmentize` and `source-highlight` to get syntax highlighting result.
- tanderson92 11y agoalias ccat='supercat' (http://supercat.nosredna.net/ http://supercat.nosredna.net/) My dad and I wrote virtually this same tool 8 or 10 years ago. The program uses arbitrary regular expressions to match and colorize any file you desire to write a set of rules for. And it ships with some common rules too. This was before pygmentize was very popular (or around at all). Those who don't google search are doomed to reinvent..
- hurin 11y ago> Those who don't google search are doomed to reinvent.. Not to be critical - but you are also forcing people to reinvent by having a custom-rule parser, rather than wrapping an existing lexer library.
- _lce0 11y ago> Those who don't google search are doomed to reinvent.. the duckduckgo team agrees ;)
- kmfrk 11y agoBig fan of hicat myself: https://github.com/rstacruz/hicat https://github.com/rstacruz/hicat.
- kerny 11y agoI'm using vimcat for this. Available as part of vimpager https://github.com/rkitover/vimpager https://github.com/rkitover/vimpager
- shurcooL 11y agoThis is pretty cool, and nice demo gif. Thanks for making it! Honestly, the biggest advantage for me over all other proposed alternatives is that it's a pure Go binary, so I can just do this: go get -u github.com/jingweno/ccat On any of my machines. One predictable command will fetch the source, all dependencies and build it without any configuration. I use Go as my primary development language, so I'm more likely to have it installed than any other tools that are not go-gettable.
- Dakuan 11y agonot right now you cant
- DblPlusUngood 11y agoAnother solution for machines with vim installed: vim -u /usr/share/vim/vim73/macros/less.vim <file> less.vim makes vim behave like less with syntax highlighting.
- MikeTLive 11y agoonly two days back i added this alias: alias vless=/usr/share/vim/vim73/macros/less.sh after finding it on a search for a colorized pager
- tomweingarten 11y agoI'd just hoped someone would make this last week! Only I was hoping it would be named catfancier: https://twitter.com/tomweingarten/status/592751132788838401 https://twitter.com/tomweingarten/status/592751132788838401
- deleted 11y ago[deleted]
- beberlei 11y agoThis is unfortunate, there is already a "ccat" command short for "ccrypt cat" installable through "ccrypt" on debian based systems.
- userbinator 11y agoSeeing as it also reads multiple files and/or standard input, I am reminded of this: http://harmful.cat-v.org/cat-v/ http://harmful.cat-v.org/cat-v/ "cat isn't for printing files with line numbers, it isn't for compressing multiple blank lines, it's not for looking at non-printing ASCII characters, it's for concatenating files." Why not make it just a syntax highlighting filter? Or is the "cat" functionality too trivial to be factored out, and thus it has grown to include other things? I suppose it's a bit of a philosophical question...
- smorrow 11y agoMaybe it's like grep. `grep asterisk` is different from `cat asterisk |grep`, in that it knows which file it's in and which line number of that file the match is on.
- rtz12 11y agoI thought the same thing. There is literally no reason to reimplement cat in a tool for highlighting source code.
- AdmiralAsshat 11y agoDo people cat sourcecode to read it? For anything larger than a five line shell script, I'd assume one would open it in vim or emacs.
- a3n 11y agoMy synapses, my circumstances and random() sometimes lead me to use any of cat, less, vim, view, grep and probably others that don't come to mind at the moment.
- pankajdoharey 11y agoWhat i usually have done for years is this : sudo apt-get install python-pygments; alias ccat='pygmentize' then : ccat program.js ccat loader.rb #etc...
- kiddico 11y agoI've always used vimcat. It's pretty damn slow, but I don't mind.
- tekromancr 11y agoSame here! I never had issues with it being slow, however. Maybe I just haven't tried to vimcat a file that was large enough to matter.
- kiddico 11y agoAnything over like 20 lines for me takes a second or so. Then again the machine is like 175 miles away and its a core 2 duo... so I suppose that's reasonable.
- ryanartecona 11y agoHuge missed opportunity to name this thing `scat`, and claim the poop emoji as a logo.
- deleted 11y ago[deleted]
- prakashk 11y agoI use the highlight package[1] that comes with Debian/Ubuntu. With that: highlight -O ansi file.ext | less -R highlight -O xterm256 file.ext | less -R highlight can also convert the input to other formats: HTML, XHTML, RTF, LaTeX, TeX, BBCode or SVG. An alternative to `less -R` is the `most` pager [2]. [1] https://packages.debian.org/jessie/highlight https://packages.debian.org/jessie/highlight [2] https://packages.debian.org/jessie/most https://packages.debian.org/jessie/most
- boomlinde 11y agoA syntax highlighting pager might be more useful to me. cat is a tool that I only use for plumbing, and I rarely want coloring control codes anywhere but stdout.