TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to Set Up Git Completion and Repo State on OS X

29 点作者 jrobertfox大约 12 年前

7 条评论

aaronpk大约 12 年前
Couple typos:<p>"In the git-completion.bash file" should be "In the .git-completion.bash file"<p>"In the git-prompt.sh file" should be "In the .git-prompt.sh file"<p>Updating the permissions is not necessary.<p>Step 4 should also include adding<p><pre><code> source ~/.git-completion.bash source ~/.git-prompt.sh </code></pre> Step 5 you can add "Run . ~/.bash_profile" or "close and re-launch your terminal"<p>Thanks for the tips!
peff大约 12 年前
That prompt can be really slow, as it runs `__git_ps1` multiple times (through several branches of the conditional, and then for the final output). On my git.git repository, running `time __git_ps1` takes about .085s. If I hit the "cyan" condition in the prompt, we run it three times, and doing `time eval "echo \"$PS1"\""` takes about 0.263s, which feels noticeably laggy.<p>Changing it to cache the result, like this:<p><pre><code> export PS1=$LIGHT_GRAY"\u@\h"'$( g=$(__git_ps1 " (%s)") if [[ "$g" =~ \*\)$ ]] then echo "'$YELLOW'$g" elif [[ "$g" =~ \+\)$ ]] then echo "'$MAGENTA'$g" else echo "'$CYAN'$g" fi)'$BLUE" \w"$GREEN": " </code></pre> drops it back down to the .085s range.
hoov大约 12 年前
I have a couple other suggestions:<p>1. Put your dotfiles in GitHub<p>2. Consider using zsh -- the completion is great, and it's easy to build a great prompt. I know prompts are personal taste, but I'm enjoying mine: <a href="https://github.com/hoov/dotfiles/blob/master/zsh/prompts/prompt_hoov_setup" rel="nofollow">https://github.com/hoov/dotfiles/blob/master/zsh/prompts/pro...</a>
sighlent大约 12 年前
I'd also look at Mathias Bynens dotfiles repo.<p><a href="https://github.com/mathiasbynens/dotfiles" rel="nofollow">https://github.com/mathiasbynens/dotfiles</a>
heromat大约 12 年前
Just use zsh with oh-my-zsh (<a href="https://github.com/robbyrussell/oh-my-zsh" rel="nofollow">https://github.com/robbyrussell/oh-my-zsh</a>). Done.
评论 #5785502 未加载
r4um大约 12 年前
Additionally to GIT_PS1_SHOWDIRTYSTATE the following are useful<p><pre><code> export GIT_PS1_SHOWUPSTREAM="auto" export GIT_PS1_SHOWSTASHSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1</code></pre>
Osiris大约 12 年前
fish shell has some of this built in, such as the git prompt.<p>Here's a sample of my fish_prompt.fish<p><pre><code> function fish_prompt set last_status $status set_color $fish_color_cwd printf '%s' (prompt_pwd) set_color normal printf '%s ' (__fish_git_prompt) set_color normal end</code></pre>