{"id":440,"date":"2022-10-30T22:56:08","date_gmt":"2022-10-30T14:56:08","guid":{"rendered":"http:\/\/madapapa.com\/wordpress\/?p=440"},"modified":"2022-11-02T18:26:28","modified_gmt":"2022-11-02T10:26:28","slug":"etczshrc","status":"publish","type":"post","link":"http:\/\/madapapa.com\/wordpress\/?p=440","title":{"rendered":"\/etc\/zshrc"},"content":{"rendered":"<p>\u7528\u6700\u7b80\u6d01\u7684\u65b9\u5f0f\uff0c\u5728prompt\u91cc\u5b9e\u73b0git branch\u7684\u4fe1\u606f<\/p>\n<p>\u589e\u52a0parse_git_branch\u51fd\u6570<\/p>\n<p>final version<\/p>\n<pre><code class=\"language-plain_text\">parse_git_branch() {\n     git branch 2&gt; \/dev\/null | sed -e '\/^[^*]\/d' -e 's\/* \\(.*\\)\/ (\\1)\/'\n}\n\nPS1=&quot;%F{12}%D%d~%#&gt;%f%F{red}\\$(parse_git_branch)%f&quot;\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/10\/16671426688897.jpg\" alt=\"\" \/><\/p>\n<h2><a id=\"zsh-prompt%E7%9A%84%E7%AE%80%E5%8D%95%E7%94%9F%E6%88%90%E5%99%A8\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>ZSH prompt\u7684\u7b80\u5355\u751f\u6210\u5668<\/h2>\n<p><a href=\"https:\/\/zsh-prompt-generator.site\/\">https:\/\/zsh-prompt-generator.site\/<\/a><\/p>\n<h2><a id=\"zsh%E7%8E%B0%E5%AE%9Egit-branch%E7%9A%84%E5%8F%A6%E5%A4%96%E4%B8%80%E7%A7%8D%E6%96%B9%E6%B3%95\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>ZSH\u73b0\u5b9egit branch\u7684\u53e6\u5916\u4e00\u79cd\u65b9\u6cd5<\/h2>\n<p>autoload -Uz vcs_info<br \/>\nprecmd_vcs_info() { vcs_info }<br \/>\nprecmd_functions+=( precmd_vcs_info )<br \/>\nsetopt prompt_subst<br \/>\n#RPROMPT=$vcs_info_msg_0_<br \/>\nPS1=&quot;%F{cyan}%D%d~%#&gt;%f&quot;$vcs_info_msg_0_<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/madapapa.com\/wordpress\/wp-content\/uploads\/2022\/11\/16672008121300.jpg\" alt=\"\" \/><\/p>\n<h2><a id=\"reference\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>reference<\/h2>\n<p><a href=\"https:\/\/coderwall.com\/p\/fasnya\/add-git-branch-name-to-bash-prompt\">add git branch name to bash prompt<\/a><\/p>\n<p><a href=\"https:\/\/scriptingosx.com\/2019\/07\/moving-to-zsh-06-customizing-the-zsh-prompt\/\">https:\/\/scriptingosx.com\/2019\/07\/moving-to-zsh-06-customizing-the-zsh-prompt\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u6700\u7b80\u6d01\u7684\u65b9\u5f0f\uff0c\u5728prompt\u91cc\u5b9e\u73b0git branch\u7684\u4fe1\u606f \u589e\u52a0parse_git_branch\u51fd\u6570 final version parse_git_branch() { git branch 2&gt; \/dev\/null | sed -e &#8216;\/^[^*]\/d&#8217; -e &#8216;s\/* \\(.*\\)\/ (\\1)\/&#8217; } PS1=&quot;%F{12}%D%d~%#&gt;%f%F{red}\\$(parse_git_branch)%f&quot; ZSH prompt\u7684\u7b80\u5355\u751f\u6210\u5668 https:\/\/zsh-prompt-generator.site\/ ZSH\u73b0\u5b9egit branch\u7684\u53e6\u5916\u4e00\u79cd\u65b9\u6cd5 autoload -Uz vcs_info precmd_vcs_info() { vcs_info } precmd_functions+=( precmd_vcs_info ) setopt prompt_subst #RPROMPT=$vcs_info_msg_0_ PS1=&quot;%F{cyan}%D%d~%#&gt;%f&quot;$vcs_info_msg_0_ reference add git branch name to bash prompt https:\/\/scriptingosx.com\/2019\/07\/moving-to-zsh-06-customizing-the-zsh-prompt\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[5,11],"tags":[],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-linux","category-tech"],"_links":{"self":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=440"}],"version-history":[{"count":6,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/440\/revisions"}],"predecessor-version":[{"id":451,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/440\/revisions\/451"}],"wp:attachment":[{"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/madapapa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}