{"id":1707,"date":"2018-09-18T10:18:18","date_gmt":"2018-09-18T14:18:18","guid":{"rendered":"http:\/\/mossiso.com\/?p=1707"},"modified":"2018-09-18T10:23:28","modified_gmt":"2018-09-18T14:23:28","slug":"what-is-tput-sgr0-doin-in-my-bash-prompt","status":"publish","type":"post","link":"https:\/\/mossiso.com\/2018\/09\/18\/what-is-tput-sgr0-doin-in-my-bash-prompt\/","title":{"rendered":"What is ‘tput sgr0’ doin in my Bash prompt?"},"content":{"rendered":"
I have a new work computer, so this time around, I’m doing everything from scratch, because that’s the best way to learn.<\/p>\n
In playing with my Bash prompt, I used this site to generate the prompt:\u00a0http:\/\/bashrcgenerator.com\/<\/a><\/p>\n Another one that is great is here:\u00a0http:\/\/ezprompt.net\/<\/a><\/p>\n The prompt that is generated uses a command to clear the text color that I hadn’t seen before: My prompt (which I put in the ~\/.bash_profile file) is:<\/p>\n So, of course, I spent the next 40 minutes trying to figure out all I could about that command, and more specifically, what ‘sgr’ meant.<\/p>\n I first scoured Google search results. Mostly just information about tput. Then I took to the manual pages: So a Google search of ‘ISO-6429 SGR 39’ turns up an old 1990’s ECMA standardization for “Control Functions and Coded Character Sets”, Standard ECMA-48,\u00a0https:\/\/www.ecma-international.org\/publications\/files\/ECMA-ST\/Ecma-048.pdf<\/a><\/p>\n (More on ECMA history here:\u00a0https:\/\/www.ecma-international.org\/memento\/history.htm<\/a>) [sidenote: ECMA may sound familiar. ECMAScript. Wait isn’t that Javascript? See here:\u00a0https:\/\/medium.freecodecamp.org\/whats-the-difference-between-javascript-and-ecmascript-cba48c73a2b5<\/a>]<\/p>\n And there we go! Page 75 of the PDF (page 61 internally numbered), section 8.3.117!<\/p>\n SGR – SELECT GRAPHIC RENDITION<\/strong><\/p>\n And the 0 means = “default rendition (implementation-defined), cancels the effect of any preceding occurrence of SGR in the data stream regardless of the setting of the GRAPHIC RENDITION COMBINATION MODE (GRCM)”<\/p>\n To make things a little more readable, I made the color codes into variables:<\/p>\n And there we go. Much too much time learning stuff! And my prompt looks like this:<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n And all of that to figure out what ‘sgr’ means.<\/p>\n","protected":false},"excerpt":{"rendered":" I have a new work computer, so this time around, I’m doing everything from scratch, because that’s the best way to learn. In playing with my Bash prompt, I used this site to generate the prompt:\u00a0http:\/\/bashrcgenerator.com\/ Another one that is great is here:\u00a0http:\/\/ezprompt.net\/ The prompt that is generated uses a command to clear the text … Continue reading What is ‘tput sgr0’ doin in my Bash prompt?<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1708,"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,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[3,243,259,167],"tags":[236,296,297],"class_list":["post-1707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding","category-howto","category-systems-administration-technical","category-technical","tag-bash","tag-prompt","tag-terminal"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/mossiso.com\/wp-content\/uploads\/2018\/09\/Screen-Shot-2018-09-18-at-10.14.44-AM.png","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9wosP-rx","_links":{"self":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1707"}],"collection":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/comments?post=1707"}],"version-history":[{"count":6,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1707\/revisions"}],"predecessor-version":[{"id":1715,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/posts\/1707\/revisions\/1715"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media\/1708"}],"wp:attachment":[{"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/media?parent=1707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/categories?post=1707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mossiso.com\/wp-json\/wp\/v2\/tags?post=1707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}tput sgr0<\/code><\/p>\n
#PROMPT\n# To enter an emoji, while in insert mode type Ctrl-v, then enter the UTF8 code\n# for the emoji, ex. U26A1 (note, use capital letters), then type ESC key. You\n# can get a list of UTF8 emoji codes here: http:\/\/graphemica.com\/\nexport PS1=\"\\[\\033[38;5;39m\\]\\u\\[$(tput sgr0)\\]\\[\\033[38;5;15m\\]@\\[$(tput sgr0)\\]\\[\\033[38;5;229m\\]\\h\\[$(tput sgr0)\\]\\[\\033[38;5;15m\\] [\\[$(tput sgr0)\\]\\[\\033[38;5;76m\\]\\w\\[$(tput sgr0)\\]\\[\\033[38;5;15m\\]]\\n\\[$(tput sgr0)\\]\\[\\033[38;5;215m\\]\u26a1\\[$(tput sgr0)\\] \"\n<\/code><\/pre>\n
man tput<\/code>\u00a0was helpful in learning about what tput does. That led to
man terminfo<\/code>\u00a0and finally to
man ncurses<\/code>. None of those man pages define ‘sgr’, but ‘ncurses’ did give a better clue by stating that “The\u00a0 <\/span><\/span>ncurses<\/span>\u00a0 <\/span>library can exploit the capabilities of terminals which implement the ISO-6429 <\/span>SGR<\/span> 39 and <\/span>SGR<\/span> 49 controls”<\/span><\/p>\n
#PROMPT\n# To enter an emoji, while in insert mode type Ctrl-v, then enter the UTF8 code\n# for the emoji, ex. U26A1 (note, use capital letters), then type ESC key. You\n# can get a list of UTF8 emoji codes here: http:\/\/graphemica.com\/\nBLUE='\\[\\033[38;5;39m\\]'\nPALE_YELLOW='\\[\\033[38;5;229m\\]'\nRESET='\\[$(tput sgr0)\\]'\nGREEN='\\[\\033[38;5;76m\\]'\nexport PS1=\"${BLUE}\\u${RESET}@${PALE_YELLOW}\\h${RESET} [${GREEN}\\w${RESET}]\\n\u26a1${RESET} \"\n<\/code><\/pre>\n
<\/p>\n