{"id":3944,"date":"2021-05-07T02:08:33","date_gmt":"2021-05-07T02:08:33","guid":{"rendered":"https:\/\/www.gubatron.com\/blog\/?p=3944"},"modified":"2021-05-07T02:08:33","modified_gmt":"2021-05-07T02:08:33","slug":"how-to-enable-source-highlighting-when-doing-less-mycodefile-ext","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/how-to-enable-source-highlighting-when-doing-less-mycodefile-ext\/","title":{"rendered":"How to enable source highlighting when doing `less mycodefile.ext`"},"content":{"rendered":"<style>.gist table { margin-bottom: 0; }<\/style>\n<div style=\"tab-size: 8\" id=\"gist99413805\" class=\"gist\">\n<div class=\"gist-file\" translate=\"no\" data-color-mode=\"light\" data-light-theme=\"light\">\n<div class=\"gist-data\">\n<div class=\"js-gist-file-update-container js-task-list-container\">\n<div id=\"file-ubuntu_less_source_hightlighting-md\" class=\"file my-2\">\n<div id=\"file-ubuntu_less_source_hightlighting-md-readme\" class=\"Box-body readme blob tmp-p-5 tmp-p-xl-6 \"\n    style=\"overflow: auto\" tabindex=\"0\" role=\"region\"\n    aria-label=\"ubuntu_less_source_hightlighting.md content, created by gubatron on 04:47PM on November 12, 2019.\"\n  ><\/p>\n<article class=\"markdown-body entry-content container-lg\" itemprop=\"text\">\n<div class=\"markdown-heading\" dir=\"auto\">\n<h1 class=\"heading-element\" dir=\"auto\">How to enable source highlighting when doing <code>less mycodefile.ext<\/code><\/h1>\n<p><a id=\"user-content-how-to-enable-source-highlighting-when-doing-less-mycodefileext\" class=\"anchor\" aria-label=\"Permalink: How to enable source highlighting when doing less mycodefile.ext\" href=\"#how-to-enable-source-highlighting-when-doing-less-mycodefileext\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ol dir=\"auto\">\n<li>\n<p dir=\"auto\">Install <em>source-highlight<\/em><br \/>\n<code>sudo apt install source-highlight<\/code><\/p>\n<\/li>\n<li>\n<p dir=\"auto\">Configure it on your <code>.bash_profile<\/code><\/p>\n<\/li>\n<\/ol>\n<div class=\"highlight highlight-source-shell\" dir=\"auto\">\n<pre><span class=\"pl-en\">lessWithSourceHighlightSetup<\/span>() {\n  <span class=\"pl-c\"><span class=\"pl-c\">#<\/span> location of the script may vary<\/span>\n  src_hilite_pipe_script=<span class=\"pl-s\"><span class=\"pl-pds\">`<\/span>dpkg -L libsource-highlight-common <span class=\"pl-k\">|<\/span> grep lesspipe<span class=\"pl-pds\">`<\/span><\/span>\n  <span class=\"pl-k\">export<\/span> LESSOPEN=<span class=\"pl-s\"><span class=\"pl-pds\">\"<\/span>| <span class=\"pl-smi\">${src_hilite_pipe_script}<\/span> %s<span class=\"pl-pds\">\"<\/span><\/span>\n  <span class=\"pl-k\">export<\/span> LESS=<span class=\"pl-s\"><span class=\"pl-pds\">'<\/span> -R <span class=\"pl-pds\">'<\/span><\/span>\n}\n\n\nlessWithSourceHighlightSetup<\/pre>\n<\/div>\n<ol start=\"3\" dir=\"auto\">\n<li>Use it on any code file <code>less -N \/path\/to\/mycode.ext<\/code><\/li>\n<\/ol>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"https:\/\/i0.wp.com\/user-images.githubusercontent.com\/163977\/68692352-4119b780-056d-11ea-9051-a94ec3c12863.png?ssl=1\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/user-images.githubusercontent.com\/163977\/68692352-4119b780-056d-11ea-9051-a94ec3c12863.png?w=640&#038;ssl=1\" alt=\"Screen Shot 2019-11-12 at 9 55 32 AM\" style=\"max-width: 100%;\"><\/a><\/p>\n<\/article><\/div>\n<\/p><\/div>\n<\/div><\/div>\n<div class=\"gist-meta\">\n        <a href=\"https:\/\/gist.github.com\/gubatron\/cfcb12cf4840ab85eb1616a0dd628251\/raw\/dc585acae04e5beea756e0d243342d6458d749e6\/ubuntu_less_source_hightlighting.md\" style=\"float:right\" class=\"Link--inTextBlock\">view raw<\/a><br \/>\n        <a href=\"https:\/\/gist.github.com\/gubatron\/cfcb12cf4840ab85eb1616a0dd628251#file-ubuntu_less_source_hightlighting-md\" class=\"Link--inTextBlock\"><br \/>\n          ubuntu_less_source_hightlighting.md<br \/>\n        <\/a><br \/>\n        hosted with &#10084; by <a class=\"Link--inTextBlock\" href=\"https:\/\/github.com\">GitHub<\/a>\n      <\/div>\n<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>How to enable source highlighting when doing less mycodefile.ext Install source-highlight sudo apt install source-highlight Configure it on your .bash_profile lessWithSourceHighlightSetup() { # location of the script may vary src_hilite_pipe_script=`dpkg -L libsource-highlight-common | grep lesspipe` export LESSOPEN=&#8221;| ${src_hilite_pipe_script} %s&#8221; export LESS=&#8217; -R &#8216; } lessWithSourceHighlightSetup Use it on any code file less -N \/path\/to\/mycode.ext view [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,43],"tags":[183,1644,1643],"class_list":["post-3944","post","type-post","status-publish","format-standard","hentry","category-code","category-linux","tag-bash","tag-highlighting","tag-less"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-11C","jetpack-related-posts":[{"id":176,"url":"https:\/\/www.gubatron.com\/blog\/emacs-php-pon-esto-en-emacs\/","url_meta":{"origin":3944,"position":0},"title":"emacs + php ? (pon esto en .emacs)","author":"gubatron","date":"July 12, 2005","format":false,"excerpt":"Si estas trabajando en PHP con emacs, recomiendo que tengas esto al final de tu archivo ~\/.emacs (require 'php-mode) (global-font-lock-mode 1 t) (define-key esc-map \"g\" 'goto-line) Carga el modo php Por defecto tienes fon-lock-mode puesto, asi que vas a tener syntax highlighting apenas abras el archivo. Y para hacer goto-line,\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1324,"url":"https:\/\/www.gubatron.com\/blog\/html-5-is-out-and-about\/","url_meta":{"origin":3944,"position":1},"title":"HTML 5 is out and about","author":"gubatron","date":"July 11, 2009","format":false,"excerpt":"I believe that the <canvas>, <audio>and <video> tags will make the web a pretty exciting place. A lot of Flash components will be rewritten or converted into Javascript+HTML5 Object components making available more reusable elements for a graphical and interactive web, all being open sourced (javascript) and with no extra\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":590,"url":"https:\/\/www.gubatron.com\/blog\/emacs-pocket-guide\/","url_meta":{"origin":3944,"position":2},"title":"Emacs Pocket Guide","author":"gubatron","date":"September 12, 2007","format":false,"excerpt":"I wrote this a long long time ago when I was learning emacs, then pasted it on linuxmachos.org, but that site is down atm. So here's for future reference EMACS POCKET GUIDE Ctrl+g Cancels anything (useful for n00bs) == Saving == Ctrl+x s Save buffer (buffer a.k.a filez) Ctrl+x Ctrl+w\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75,"url":"https:\/\/www.gubatron.com\/blog\/upgrades-a-wedoit4youcom-emacs-tips\/","url_meta":{"origin":3944,"position":3},"title":"Upgrades a wedoit4you.com \/ eMacs Tips","author":"gubatron","date":"December 19, 2004","format":false,"excerpt":"Hemos clasificado todo nuestro contenido de Reviews\/Articulos\/Noticias en Categorias. Las categorias se fueron creando a medida que revisabamos todo nuestro contenido, que ya sobrepasa las 500 publicaciones. Aun esta por pulirse un poco el look de como accedemos a estas categorias, y ahora si conseguimos el tiempo y el habito\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":63,"url":"https:\/\/www.gubatron.com\/blog\/vaciando-el-buffer\/","url_meta":{"origin":3944,"position":4},"title":"Vaciando el Buffer","author":"gubatron","date":"December 10, 2004","format":false,"excerpt":"Este post es un poco para desahogar algunos consejos y tips que he querido tener anotados, y que mejor lugar que el blog, donde mis notas personales pueden ayudar a otros. En mi \u00faltimas asignaciones profesionales he tenido que trabajar en ambientes 100% Linux, esto me ha hecho refrescar viejas\u2026","rel":"","context":"In &quot;Gubatron&quot;","block_context":{"text":"Gubatron","link":"https:\/\/www.gubatron.com\/blog\/category\/gubatron\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3276,"url":"https:\/\/www.gubatron.com\/blog\/why-it-only-took-me-less-than-2-minutes-to-believe-in-bitcoin\/","url_meta":{"origin":3944,"position":5},"title":"Why it only took me less than 2 minutes to believe in Bitcoin","author":"gubatron","date":"April 30, 2014","format":false,"excerpt":"Seeing is believing. I don't care what Warren Buffet or all the Bitcoin nay sayers think, I care about how real, useful and freeing Bitcoin is today even in its infancy. Just stare at any random minute of Blockchain transactions in realtime and you will see that Bitcoin is not\u2026","rel":"","context":"In &quot;BitCoin&quot;","block_context":{"text":"BitCoin","link":"https:\/\/www.gubatron.com\/blog\/category\/bitcoin-2\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=3944"}],"version-history":[{"count":1,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3944\/revisions"}],"predecessor-version":[{"id":3945,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3944\/revisions\/3945"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=3944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=3944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=3944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}