{"id":20,"date":"2011-05-22T19:15:05","date_gmt":"2011-05-22T19:15:05","guid":{"rendered":"http:\/\/www.anattasoftware.com\/blog\/?p=19"},"modified":"2012-12-25T22:40:48","modified_gmt":"2012-12-25T22:40:48","slug":"smiley-shell-prompt-or-frown","status":"publish","type":"post","link":"https:\/\/tech.avant.net\/q\/smiley-shell-prompt-or-frown\/","title":{"rendered":"smiley shell prompt, or frown"},"content":{"rendered":"<p>I&#8217;ve been using the following command prompt for years<\/p>\n<pre class=\"sh_sh\">\nserver ~\/dir :) whoami\nvictor\nserver ~\/dir :) badcommand\n-bash: badcommand: command not found\nserver ~\/dir :( echo sorry\nsorry\nserver ~\/dir :) \n<\/pre>\n<p>It&#8217;s a smiley emoticon, but only when the previous command returned without error. If the exit code (stored in $?) returns any kind of error flag then the prompt is reversed.<\/p>\n<p>It&#8217;s silly, but surprisingly useful.<\/p>\n<p>Here&#8217;s how it works, in your .bashrc simply include the following<\/p>\n<pre class=\"sh_sh\">\n## set smiley cursor\nsmiley () { if [ $? == 0 ]; then echo ':)'; else echo ':('; fi; }\nexport PS1=\"[\u000033[01;31m]h[\u000033[01;34m] W $(smiley)[\u000033[00m] \"\n<\/pre>\n<p>The interesting point is that you can use bash functions within your PS1 environment variable. This opens up all kinds of interesting possibilities; you could display the total number of running process, cpu load, time, exit code, or even integrate with version control (like git or svn) to remind you of unsaved files.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been using the following command prompt for years server ~\/dir :) whoami victor server ~\/dir :) badcommand -bash: badcommand: command not found server ~\/dir :( echo sorry sorry server ~\/dir :) It&#8217;s a smiley emoticon, but only when the previous command returned without error. If the exit code (stored in $?) returns any kind [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,14],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":1,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":742,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/20\/revisions\/742"}],"wp:attachment":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}