{"id":37,"date":"2017-02-03T13:56:15","date_gmt":"2017-02-03T05:56:15","guid":{"rendered":"https:\/\/www.unama.space\/?p=37"},"modified":"2020-04-18T01:54:09","modified_gmt":"2020-04-17T17:54:09","slug":"%e5%80%8b%e4%ba%ba%e5%8c%96%e4%bd%a0%e7%9a%84bash-prompt","status":"publish","type":"post","link":"https:\/\/unama.website\/?p=37","title":{"rendered":"\u500b\u4eba\u5316\u4f60\u7684Bash Prompt"},"content":{"rendered":"<p>\u6700\u8fd1\u5728\u7814\u7a76Bash Prompt\u7684\u5448\u73fe\u65b9\u5f0f\u8207\u984f\u8272\u8a2d\u5b9a<\/p>\n<h2><strong>\u9996\u5148\u8981\u5148\u77e5\u9053\u986f\u793a\u8cc7\u8a0a\u7684\u65b9\u5f0f\uff1a<\/strong><\/h2>\n<ul>\n<li>\\u: current username<\/li>\n<li>\\h: hostname up to the first ., \\H: full hostname<\/li>\n<li>\\w: current working directory, \\W: same, but only the basename<\/li>\n<li>$(__git_ps1 &#8220;%s&#8221;): your current git branch if you&#8217;re in a git directory, otherwise nothing<\/li>\n<li>\\$: if the effective UID is 0: #, otherwise $<\/li>\n<li>\\d: the date in &#8220;Weekday Month Date&#8221; format (e.g., &#8220;Tue May 26&#8221;)<\/li>\n<li>\\t: the current time in 24-hour HH:MM:SS format, \\T: same, but 12-hour format, \\@: same, but in 12-hour am\/pm format<\/li>\n<li>\\n: newline<\/li>\n<li>\\r: carriage return<\/li>\n<li>\\\\: backslash<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><strong>\u984f\u8272\uff1a<\/strong><\/h2>\n<p class=\"\">\u6211\u5011\u8981\u5c07\u984f\u8272\u8272\u78bc\u653e\u5728<strong>\\[\\em\\]<\/strong>\u4e2d\u9593\uff0c\u50cf<strong>\\[\\e[\u2039\u8272\u78bc\u203am\\]<\/strong><\/p>\n<p>\u8272\u78bc\u9078\u64c7\u53ef\u53c3\u8003<a href=\"http:\/\/misc.flogisoft.com\/bash\/tip_colors_and_formatting\">\u9019<\/a><\/p>\n<h2><strong>\u958b\u59cb\u8a2d\u5b9a\uff1a<\/strong><\/h2>\n<p>username: unama<\/p>\n<p>hostname: notebook<\/p>\n<p>\u4f8b\u5982\u5c07\u4e0b\u5217\u9019\u884c\u52a0\u5165<strong>~\/.bashrc<\/strong><\/p>\n<pre class=\"theme:dark-terminal lang:sh range:1 decode:true\">PS1='\\u@\\h \\w \\$ '<\/pre>\n<p>\u4e26\u5230<strong>~\/<\/strong>\u57f7\u884c<\/p>\n<pre class=\"lang:sh range:1 decode:true\">$ source .bashrc<\/pre>\n<p>\u5c31\u6703\u986f\u793a<\/p>\n<pre class=\"theme:dark-terminal lang:sh range:1 decode:true\">unama@notebook ~ $\n<\/pre>\n<p>\u5982\u679c\u8981\u52a0\u984f\u8272\u5247\u5728\u8981\u8b8a\u8272\u7684\u8cc7\u8a0a\u524d\u52a0<strong>\\[\\e[\u2039\u8272\u78bc\u203am\\]<\/strong>\u5373\u53ef<\/p>\n<p>ex.<\/p>\n<pre class=\"theme:dark-terminal lang:sh range:1 decode:true\">PS1='[\\033[01;32m\\]\\u@\\h\\[\\033[01;33m\\]\\w\\[\\033[01;31m\\]&gt;\\[\\033[00m\\]'<\/pre>\n<p>&nbsp;<\/p>\n<h2><strong>\u986f\u793aGit Branch<\/strong><\/h2>\n<pre class=\"theme:dark-terminal lang:sh range:1 decode:true\">PS1='\\u@\\h \\w$(__git_ps1 \"(%s)\") \\$ '<\/pre>\n<p>\u5982\u679c\u51fa\u73fe\u4ee5\u4e0b\u932f\u8aa4\u8a0a\u606f<\/p>\n<pre class=\"theme:dark-terminal lang:sh range:1 decode:true\">-bash: __git_ps1: command not found<\/pre>\n<p>\u53ef\u4ee5\u8a66\u8457\u57f7\u884c<\/p>\n<pre class=\"lang:sh range:1-2 decode:true \">curl -o ~\/.git-prompt.sh \\\n    https:\/\/raw.githubusercontent.com\/git\/git\/master\/contrib\/completion\/git-prompt.sh<\/pre>\n<pre class=\"lang:sh range:1 decode:true\">source ~\/.git-prompt.sh\n<\/pre>\n<h2>2017.2.7<\/h2>\n<p><a href=\"http:\/\/www.thegeekstuff.com\/2008\/09\/bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie\/\">bash-shell-ps1-10-examples-to-make-your-linux-prompt-like-angelina-jolie<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5728\u7814\u7a76Bash Prompt\u7684\u5448\u73fe\u65b9\u5f0f\u8207\u984f\u8272\u8a2d\u5b9a \u9996\u5148\u8981\u5148\u77e5\u9053\u986f\u793a\u8cc7\u8a0a\u7684\u65b9\u5f0f\uff1a \\u: current username \\h: hostname up t&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/unama.website\/?p=37\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts\/37"}],"collection":[{"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=37"}],"version-history":[{"count":13,"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions"}],"predecessor-version":[{"id":51,"href":"https:\/\/unama.website\/index.php?rest_route=\/wp\/v2\/posts\/37\/revisions\/51"}],"wp:attachment":[{"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unama.website\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}