tag:blogger.com,1999:blog-5541296000399974369.post6655069957799986185..comments2024-03-09T02:51:27.612-05:00Comments on Peter Eisentraut's Blog: Adding Color to the Console: Code Syntax Highlighting with less and source-highlightAnonymoushttp://www.blogger.com/profile/02849480732923051923noreply@blogger.comBlogger26125tag:blogger.com,1999:blog-5541296000399974369.post-31247349813183053522014-01-13T04:29:28.698-05:002014-01-13T04:29:28.698-05:00This is cool! Thanks :)This is cool! Thanks :)Anihttps://www.blogger.com/profile/09016215367013182386noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-28396167873813475632013-05-20T16:56:07.373-04:002013-05-20T16:56:07.373-04:00I've never used that at the end of a pipe, and...I've never used that at the end of a pipe, and that was not the original idea... :)bettohttps://www.blogger.com/profile/16462664783219149049noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-70135194837054196472013-05-10T12:36:37.394-04:002013-05-10T12:36:37.394-04:00did you ever get this to work with less at the end...did you ever get this to work with less at the end of a pipe? I've wasted most of my morning trying to figure this one out, lole_dub_kendohttps://www.blogger.com/profile/02238237769619521251noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-59371627427175381782012-02-22T19:07:28.725-05:002012-02-22T19:07:28.725-05:00An additional tip is to put
zrun source-highlight...An additional tip is to put<br /><br />zrun source-highlight ...<br /><br />into the .lessfilter file, to handle compressed files as well.Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-69845750687308510412011-07-04T01:47:39.582-04:002011-07-04T01:47:39.582-04:00Alternatively, you can use less.vim, a pager with ...Alternatively, you can use less.vim, a pager with less keybindings but with the color syntax highlighting of vim:<br />http://huyz.us/2011/a-less-like-pager-with-color-syntax-highlighting/huyzhttp://huyz.us/noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-47701976132254039992011-03-09T22:15:07.048-05:002011-03-09T22:15:07.048-05:00Thanks much for the info.
Using the info here, and...Thanks much for the info.<br />Using the info here, and especially at Lorenzo Bettini's source-highlighting page on gnu.org, I simply used the following to do syntax-highlighting in less: <br /><br />export LESS=" -R "<br />export LESSOPEN="| /home/ali/bin/src-hilite-lesspipe.sh %s"<br /><br />where /home/ali/bin/src-hilite-lesspipe.sh is just my own trivial mod of <br />/usr/share/source-highlight/src-hilite-lesspipe.sh<br />to have it skip my large readme files:<br /><br /> case $source in<br /> *readme) <br /> ;; # NOP<br /><br />Otherwise, the large, text files do slow down excessively.<br />The above works for even cscope.<br /><br />Now I finally understand why 'less' has not incorporated this feature! :-)<br /><br />thanks,<br />AliAli Baharhttp://internetdog.orgnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-60341067972591464362009-07-28T05:44:08.184-04:002009-07-28T05:44:08.184-04:00It looks like Debian package is pretty old... I al...It looks like Debian package is pretty old... I always suggest to download the .tar.gz source from the GNU site and compile it (as long as you have installed the libboost_regex dev package from Debian, the compilation is smooth)bettohttps://www.blogger.com/profile/16462664783219149049noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-21538694689894867632009-07-27T14:38:04.534-04:002009-07-27T14:38:04.534-04:00Hello betto. Thanks for your help.
In Debian stab...Hello betto. Thanks for your help. <br />In Debian stable / testing / unstable the source-highlight versions are 2.x and I think that don't support --infer-lang option (it doesn't appear in man page). So, I have developed a "patch":<br />#!/bin/sh<br /><br />FILE="$1"<br />EXTENSION=${FILE##*.}<br />NAME=${FILE%.*}<br /><br />if [ "$NAME" = "$EXTENSION" ]; then<br /> EXTENSION=""<br />fi<br /><br />if [ "$EXTENSION" = "" ]; then<br /> source-highlight --src-lang=shell -fesc -oSTDOUT "$1" 2>/dev/null<br />else<br /> source-highlight -fesc -oSTDOUT "$1" 2>/dev/null<br />fiGodohttp://godest.vivencias.netnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-18490103260183195442009-07-26T07:01:20.187-04:002009-07-26T07:01:20.187-04:00If you use --infer-lang option, and the shell scri...If you use --infer-lang option, and the shell script starts with the #!/bin/sh then source-highlight will highlight it as a shell script no matter what its extension is (you may want to take a look at the file src-hilite-lesspipe.sh distributed with source-highlight.<br />Hope this helps :-)<br />Lorenzobettohttps://www.blogger.com/profile/16462664783219149049noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-59779960222833594812009-07-25T09:07:59.734-04:002009-07-25T09:07:59.734-04:00@Luca Invernizzi,
I would advise against the --fa...@Luca Invernizzi,<br /><br />I would advise against the --failsafe option. The trick is that if the lessfilter exits with a nonzero status, then lesspipe itself will handle the file, and that includes niceties that such automatically unpacking gzip and archive files. If you use source-highlight --failsafe, then lesspipe will assume that the lessfilter has succeeded in its job, and you will see the garbled literal gzipped (or whatever) content.Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-7755196092080973522009-07-24T16:00:05.922-04:002009-07-24T16:00:05.922-04:00If I want to look up a shell file, foo, and its na...If I want to look up a shell file, foo, and its name doesn't end with .sh, less doesn't highlight it. All working fine if filename is ended with .sh. So, is it possible to add a default option? Something like: all files are shell files although their filenames are not ended with .sh<br /><br />Thanks.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-6409482773906924202009-07-19T13:30:18.335-04:002009-07-19T13:30:18.335-04:00@betto,
Yeah, I think I saw that when I was first...@betto,<br /><br />Yeah, I think I saw that when I was first trying this out, but somehow didn't like the solution so much. I think it's more or less equivalent, though.Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-56320980802293650952009-07-18T04:30:04.508-04:002009-07-18T04:30:04.508-04:00Hi
I'm glad you're using source-highlight ...Hi<br />I'm glad you're using source-highlight :-)<br />source-highlight already ships a script (and some documentation) to work with less:<br />http://www.gnu.org/software/src-highlite/source-highlight.html#Using-source_002dhighlight-with-lessbettohttps://www.blogger.com/profile/16462664783219149049noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-42208837096779312522009-07-13T06:45:00.086-04:002009-07-13T06:45:00.086-04:00@BooXteR,
I don't think "view" real...@BooXteR,<br /><br />I don't think "view" really accomplishes the same thing. For example, viewing html, pdf, or odt with "view" shows the text, not the source. Of course you can switch to raw, but it's not the default. Also, it doesn't actually use any colors, when I try it.<br /><br />Of course the main problem is that "less" is hard-wired into my fingers. :-)Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-71010372778615863542009-07-13T06:40:04.793-04:002009-07-13T06:40:04.793-04:00@Anonymous/Robert,
I guess I don't look at th...@Anonymous/Robert,<br /><br />I guess I don't look at that many large files. It could be a problem, I admit.Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-72438113707680991422009-07-13T06:36:18.023-04:002009-07-13T06:36:18.023-04:00@Anonymous,
There's me trying to do the world...@Anonymous,<br /><br />There's me trying to do the world a favour by not spamming the feeds with superlong articles, and within minutes someone complains. :-) So now it's back to the full article.Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-15748588550394295752009-07-13T06:35:10.783-04:002009-07-13T06:35:10.783-04:00@Sam,
Ubuntu has a new major upstream version, so...@Sam,<br /><br />Ubuntu has a new major upstream version, so perhaps the invocation was changed. I will investigate that.Anonymoushttps://www.blogger.com/profile/02849480732923051923noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-77945188854620174942009-07-13T02:44:19.964-04:002009-07-13T02:44:19.964-04:00"Why don't you use 'view' for vie..."Why don't you use 'view' for viewing text files? :)" - another reason is that vi(ew) can't cope with large files. It probably tries to load whole file into memory and it doesn't work for bigger sizes.<br />RobertAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-21641080084908989022009-07-12T16:25:43.737-04:002009-07-12T16:25:43.737-04:00Another tool (that I believe supports more file fo...Another tool (that I believe supports more file formats?) is <a href="http://pygments.org/" rel="nofollow">Pygments</a>. On Debian it provides the "pygmentize" tool that be used just like source-highlight.<br /><br />However, it's written in Python, so it may be a little slower than source-highlight, written in C++.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-32068693693147441712009-07-12T15:06:13.623-04:002009-07-12T15:06:13.623-04:00BooXteR - if you ask me - because according to my ...BooXteR - if you ask me - because according to my knowledge view doesn't offer as good support for files changing on-the-fly (like logs which I usually analyse with less). I haven't found anything better than less.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-71837888187973368292009-07-12T08:38:49.268-04:002009-07-12T08:38:49.268-04:00JFTR: It's broken on Debian UnstableJFTR: It's broken on Debian UnstableAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-65494940656464548322009-07-12T04:56:07.867-04:002009-07-12T04:56:07.867-04:00Why don't you use 'view' for viewing t...Why don't you use 'view' for viewing text files? :)Ihar Hrachyshkahttps://www.blogger.com/profile/17567409313713423950noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-69526042037734374772009-07-12T04:49:31.273-04:002009-07-12T04:49:31.273-04:00Well,
please keep in mind that adding lesspipe to ...Well,<br />please keep in mind that adding lesspipe to less will slow down operations on large files a lot.<br />When I am operating on big log files (for me few GB means big) jumping to the end (G) without lesspipe is instant, whereas after enabling lesspipe takes several seconds. Actually my lesspipe is much more trivial than source-highligt, so I would expect delays much more noticeable. Note that for smaller files (like most source codes, html pages or something) things will probably work as a charm. In my case I would probably create shell script (named probably pretty-less.sh), which would invoke source-highlight, then pass it to less -R. Not as automatic as described solution, but would suit my needs better.<br />Regards,<br />RobertAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-91504306039318643592009-07-11T19:39:26.381-04:002009-07-11T19:39:26.381-04:00Awesome! I confirm that it needs -i on Ubuntu.
Plu...Awesome! I confirm that it needs -i on Ubuntu.<br />Plus, if you use --failsafe, you shouldn't need to redirect stderrAnonymoushttps://www.blogger.com/profile/14516621663285758407noreply@blogger.comtag:blogger.com,1999:blog-5541296000399974369.post-56828904061783409462009-07-11T18:50:49.429-04:002009-07-11T18:50:49.429-04:00Only the first few lines of your post shows up on ...Only the first few lines of your post shows up on planet.debian.org. You may want to look into that.Anonymousnoreply@blogger.com