{"id":12389,"date":"2019-03-26T22:14:23","date_gmt":"2019-03-26T22:14:23","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12389"},"modified":"2019-03-26T22:14:59","modified_gmt":"2019-03-26T22:14:59","slug":"bat-a-cat-clone-with-syntax-highlighting-and-git-integration","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/bat-a-cat-clone-with-syntax-highlighting-and-git-integration\/","title":{"rendered":"Bat \u2013 A Cat Clone with Syntax Highlighting and Git Integration"},"content":{"rendered":"<p><strong>Bat<\/strong>\u00a0is a\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>\u00a0clone with advance syntax highlighting for a large number of programming and markup languages and it also comes with\u00a0<strong>Git<\/strong>\u00a0integration to show file modifications. Its other features include automatic paging, file concatenation, themes for syntax highlighting and various styles for presenting output.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/cat-command-output-with-syntax-highlighting-or-color\/\" target=\"_blank\" rel=\"noopener\">ccat \u2013 Show \u2018cat Command\u2019 Output with Syntax Highlighting or Colorizing<\/a><\/p>\n<p>In addition, you can also add new syntaxes \/ language definitions, themes and set a custom pager. In this article, we will show how to install and use a\u00a0<strong>Bat<\/strong>\u00a0(cat clone) in Linux.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/learn-linux-cat-command-and-tac-command\/\" target=\"_blank\" rel=\"noopener\">How to Use \u2018cat\u2019 and \u2018tac\u2019 Commands with Examples in Linux<\/a><\/p>\n<h3>How to Install Bat (A cat clone) in Linux<\/h3>\n<p>On\u00a0<strong>Debian<\/strong>\u00a0and other Debian-based Linux distributions, you can download the latest\u00a0<code>.deb<\/code>\u00a0package from the\u00a0<a href=\"https:\/\/github.com\/sharkdp\/bat\/releases\" target=\"_blank\" rel=\"nofollow noopener\">release page<\/a>\u00a0or use the following the\u00a0<a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget command<\/a>\u00a0to download and install it as shown.<\/p>\n<pre>$ wget https:\/\/github.com\/sharkdp\/bat\/releases\/download\/v0.8.0\/bat_0.8.0_amd64.deb\r\n$ sudo dpkg -i bat_0.8.0_amd64.deb\r\n<\/pre>\n<p>On\u00a0<strong>Arch Linux<\/strong>, you can install it from the\u00a0<a href=\"https:\/\/www.archlinux.org\/packages\/community\/x86_64\/bat\/\" target=\"_blank\" rel=\"nofollow noopener\">Community repository<\/a>\u00a0as shown.<\/p>\n<pre>$ sudo pacman -S bat\r\n<\/pre>\n<p>After installing\u00a0<strong>bat<\/strong>, simply run it in the same way you normally run\u00a0<a href=\"https:\/\/www.tecmint.com\/13-basic-cat-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">cat command<\/a>, for example, the following command will display the specified file content with syntax highlighting.<\/p>\n<pre>$ bat bin\/bashscripts\/sysadmin\/topprocs.sh\r\n<\/pre>\n<div id=\"attachment_30956\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/view-a-file-using-bat.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30956\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/view-a-file-using-bat.png\" sizes=\"auto, (max-width: 858px) 100vw, 858px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/view-a-file-using-bat.png 858w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/view-a-file-using-bat-768x566.png 768w\" alt=\"View a File with Syntax Highlighting\" width=\"858\" height=\"632\" aria-describedby=\"caption-attachment-30956\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30956\" class=\"wp-caption-text\">View a File with Syntax Highlighting<\/p>\n<\/div>\n<p>To display multiple files at ones, use the following command.<\/p>\n<pre>$ bat domains.txt hosts\r\n<\/pre>\n<div id=\"attachment_30957\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/display-multiple-files-using-bat.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30957\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/display-multiple-files-using-bat.png\" alt=\"Display Multiple Files Content\" width=\"692\" height=\"325\" aria-describedby=\"caption-attachment-30957\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30957\" class=\"wp-caption-text\">Display Multiple Files Content<\/p>\n<\/div>\n<p>You can only print a specified range of lines (for example print lines 13 to 24 only) for a file or each file, using the\u00a0<code>--line-range<\/code>\u00a0switch as shown.<\/p>\n<pre>$ bat --line-range 13:24 bin\/bashscripts\/sysadmin\/topprocs.sh\r\n<\/pre>\n<div id=\"attachment_30958\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/print-a-specified-range-of-lines.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30958\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/print-a-specified-range-of-lines.png\" alt=\"Print Specified Range of Lines\" width=\"706\" height=\"272\" aria-describedby=\"caption-attachment-30958\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30958\" class=\"wp-caption-text\">Print Specified Range of Lines<\/p>\n<\/div>\n<p>To show all supported language names and file extensions, use the\u00a0<strong>\u2013list-languages<\/strong>\u00a0option.<\/p>\n<pre>$ bat --list-languages\r\n<\/pre>\n<div id=\"attachment_30959\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/list-all-supported-languages-for-syntax-highlighting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30959\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/list-all-supported-languages-for-syntax-highlighting.png\" alt=\"List Supported Languages for Syntax Highlighting\" width=\"666\" height=\"632\" aria-describedby=\"caption-attachment-30959\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30959\" class=\"wp-caption-text\">List Supported Languages for Syntax Highlighting<\/p>\n<\/div>\n<p>Then explicitly set a language for syntax highlighting using the\u00a0<code>-l<\/code>\u00a0switch.<\/p>\n<pre>$ bat -l Python httpie\/setup.py\r\n<\/pre>\n<div id=\"attachment_30960\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/set-language-for-syntax-highlighting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30960\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/set-language-for-syntax-highlighting.png\" alt=\"Set Language for Syntax Highlighting\" width=\"666\" height=\"587\" aria-describedby=\"caption-attachment-30960\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30960\" class=\"wp-caption-text\">Set Language for Syntax Highlighting<\/p>\n<\/div>\n<p>You can also read from stdin as in this example.<\/p>\n<pre>$ ls -l | bat\r\n<\/pre>\n<div id=\"attachment_30961\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/read-from-stdin.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30961\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/read-from-stdin.png\" sizes=\"auto, (max-width: 952px) 100vw, 952px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/read-from-stdin.png 952w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/read-from-stdin-768x523.png 768w\" alt=\"Read from Stdin Output\" width=\"952\" height=\"648\" aria-describedby=\"caption-attachment-30961\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30961\" class=\"wp-caption-text\">Read from Stdin Output<\/p>\n<\/div>\n<p>To see a list of available themes for syntax highlighting, use the\u00a0<code>--list-themes<\/code>\u00a0option.<\/p>\n<pre>$ bat --list-themes\r\n<\/pre>\n<div id=\"attachment_30962\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/list-available-themes-for-syntax-highlighting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-30962\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/list-available-themes-for-syntax-highlighting.png\" sizes=\"auto, (max-width: 832px) 100vw, 832px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/list-available-themes-for-syntax-highlighting.png 832w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2018\/10\/list-available-themes-for-syntax-highlighting-768x598.png 768w\" alt=\"List Themes for Syntax Highlighting\" width=\"832\" height=\"648\" aria-describedby=\"caption-attachment-30962\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-30962\" class=\"wp-caption-text\">List Themes for Syntax Highlighting<\/p>\n<\/div>\n<p>After you have picked a theme to use, enable it with the\u00a0<code>--theme<\/code>\u00a0option.<\/p>\n<pre>$ bat --theme=Github\r\n<\/pre>\n<p>Note that these settings will be lost after a reboot, to make the changes permanent, export the\u00a0<strong>BAT_THEME<\/strong>environment variable in the file\u00a0<strong>~\/.bashrc<\/strong>\u00a0(user specific) or\u00a0<strong>\/etc\/bash.bashrc<\/strong>\u00a0(system-wide) by adding the following line in it.<\/p>\n<pre>export BAT_THEME=\"Github\"\r\n<\/pre>\n<p>To only show line numbers without any other decorations, use the\u00a0<code>-n<\/code>\u00a0switch.<\/p>\n<pre>$ bat -n domains.txt hosts\r\n<\/pre>\n<p>Bat uses\u00a0<strong>\u201cless\u201d<\/strong>\u00a0as the default pager. However, you can specify when to use the pager, with the\u00a0<code>--paging<\/code>\u00a0and the possible values include\u00a0<strong>*auto*<\/strong>,\u00a0<strong>never<\/strong>\u00a0and\u00a0<strong>always<\/strong>.<br \/>\n$ bat \u2013paging always<\/p>\n<p>In addition, you can define the pager using the\u00a0<strong>PAGER<\/strong>\u00a0or\u00a0<strong>BAT_PAGER<\/strong>\u00a0(this takes precedence) environment variables, in a similar fashion as the\u00a0<strong>BAT_THEME env<\/strong>\u00a0variable, as explained above. Setting these variables with empty values disables the pager.<\/p>\n<p>For more information on how to use or customize\u00a0<strong>bat<\/strong>, type\u00a0<strong>man bat<\/strong>\u00a0or go to its Github Repository:\u00a0<a href=\"https:\/\/github.com\/sharkdp\/bat\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/sharkdp\/bat<\/a>.<\/p>\n<h5>Summary<\/h5>\n<p><strong>Bat<\/strong>\u00a0is a user-friendly cat clone with syntax highlighting and git integration. Share your thoughts about it, with us via the feedback form below. If you have come across any similar CLI utilities out there, let us know as well.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/bat-a-cat-clone-with-syntax-highlighting\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Bat\u00a0is a\u00a0cat command\u00a0clone with advance syntax highlighting for a large number of programming and markup languages and it also comes with\u00a0Git\u00a0integration to show file modifications. Its other features include automatic paging, file concatenation, themes for syntax highlighting and various styles for presenting output. Read Also:\u00a0ccat \u2013 Show \u2018cat Command\u2019 Output with Syntax Highlighting or Colorizing &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/bat-a-cat-clone-with-syntax-highlighting-and-git-integration\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Bat \u2013 A Cat Clone with Syntax Highlighting and Git Integration&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12389","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12389"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12389\/revisions"}],"predecessor-version":[{"id":12391,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12389\/revisions\/12391"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}