{"id":1303,"date":"2016-03-18T10:44:57","date_gmt":"2016-03-18T08:44:57","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=1303"},"modified":"2016-03-18T10:48:54","modified_gmt":"2016-03-18T08:48:54","slug":"bash-tips-3-colour-your-terminal","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-3-colour-your-terminal\/","title":{"rendered":"Bash tips &#038; tricks [ep. 3]: Colour your terminal!"},"content":{"rendered":"<p>This is the third epidose of a <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-1-personal-accounts-permissions\/\">small series<\/a>.<\/p>\n<p><strong>Description:<\/strong><\/p>\n<p>The days of monochrome green-on-black screens are over, in a remote shell\u00a0 terminal you can have something fancier!<\/p>\n<p><strong>BAD:<\/strong><\/p>\n<p><a href=\"https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_nocolor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"  wp-image-1304 alignnone\" src=\"https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_nocolor.png\" alt=\"bash_prompt_nocolor\" width=\"288\" height=\"52\" \/><\/a><\/p>\n<p><strong>GOOD:<\/strong><\/p>\n<p>Define a series of variables as shortcuts for color escape codes, there are plenty of examples on internet.<\/p>\n<pre class=\"lang:sh decode:true \">        colblk='\\033[0;30m' # Black - Regular\r\n        colred='\\033[0;31m' # Red\r\n        colgrn='\\033[0;32m' # Green\r\n        colylw='\\033[0;33m' # Yellow\r\n        colblu='\\033[0;34m' # Blue\r\n        colpur='\\033[0;35m' # Purple\r\n        colcyn='\\033[0;36m' # Cyan\r\n        colwht='\\033[0;37m' # White\r\n        colbblk='\\033[1;30m' # Black - Bold\r\n        colbred='\\033[1;31m' # Red\r\n        colbgrn='\\033[1;32m' # Green\r\n        colbylw='\\033[1;33m' # Yellow\r\n        colbblu='\\033[1;34m' # Blue\r\n        colbpur='\\033[1;35m' # Purple\r\n        colbcyn='\\033[1;36m' # Cyan\r\n        colbwht='\\033[1;37m' # White\r\n        colublk='\\033[4;30m' # Black - Underline\r\n        colured='\\033[4;31m' # Red\r\n        colugrn='\\033[4;32m' # Green\r\n        coluylw='\\033[4;33m' # Yellow\r\n        colublu='\\033[4;34m' # Blue\r\n        colupur='\\033[4;35m' # Purple\r\n        colucyn='\\033[4;36m' # Cyan\r\n        coluwht='\\033[4;37m' # White\r\n        colbgblk='\\033[40m'   # Black - Background\r\n        colbgred='\\033[41m'   # Red\r\n        colbggrn='\\033[42m'   # Green\r\n        colbgylw='\\033[43m'   # Yellow\r\n        colbgblu='\\033[44m'   # Blue\r\n        colbgpur='\\033[45m'   # Purple\r\n        colbgcyn='\\033[46m'   # Cyan\r\n        colbgwht='\\033[47m'   # White\r\n        colrst='\\033[0m'    # Text Reset\r\n<\/pre>\n<p>Use them whenever you need to highlight the output of a script, and eventually integrate them in a<a href=\"https:\/\/www.ludovicocaldara.net\/dba\/smart-bash-prompt\/\"> smart prompt (like the one I&#8217;ve blogged about sometimes ago)<\/a>.<a href=\"https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_color1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1327\" src=\"https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_color1.png\" alt=\"bash_prompt_color\" width=\"942\" height=\"56\" srcset=\"https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_color1.png 942w, https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_color1-300x18.png 300w, https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_color1-500x30.png 500w, https:\/\/www.ludovicocaldara.net\/dba\/wp-content\/uploads\/2016\/03\/bash_prompt_color1-900x54.png 900w\" sizes=\"auto, (max-width: 942px) 100vw, 942px\" \/><\/a><\/p>\n<p>The <em>echo<\/em> builtin command requires <em>-e<\/em> in order to make the colours work. When reading files, <em>cat<\/em> works, <em>less<\/em> requires <em>-r. <\/em><em>vi<\/em> may work with some hacking, but it&#8217;s not worth to spend too much time, IMHO.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the third epidose of a small series. Description: The days of monochrome green-on-black screens are over, in a remote shell\u00a0 terminal you can have something fancier! BAD: GOOD: Define a series of variables as shortcuts for color escape &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-3-colour-your-terminal\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/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":[5,132],"tags":[],"class_list":["post-1303","post","type-post","status-publish","format-standard","hentry","category-linux","category-triblog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=1303"}],"version-history":[{"count":3,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1303\/revisions"}],"predecessor-version":[{"id":1328,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1303\/revisions\/1328"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=1303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=1303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=1303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}