[英]show git modifications on the command prompt within windows git-bash
[英]Git-Bash *Prompt itself* Slow
我一直在努力制作自己的 git-bash 提示符。 但是,当加载我的提示符(在 ~/.bashrc 中设置)时,并且在每个后续命令之后,它只需要半秒多一点,所以我的输入有时没有注册/“溢出”当键入 mutriple命令迅速。 强制赦免代码; 在我清理愚蠢的做事方式之前,我只想把它全部记录下来。 这是 function 的一部分,它显示了提示,promptFunc: (git branch 和 #commits ahead/behind,代码并不重要,只要它是加载需要一段时间的原因;如果你找到更好的仅用数字和向上/向下箭头来显示这一点的方法,让我知道,我是 bash 菜鸟)。
local branch=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3-`
if [ $branch ]; then
status=`git status -sb`
read ahead behind <<<${status//[^0-9]/ }
if [ ! -z "$ahead" ] && [ -z "$behind" ] && [[ $status == *"behind"* ]]; then
behind="$ahead"
ahead=""
fi
if [ ! -z "$ahead" ]; then ahead="↑$ahead"; fi
if [ ! -z "$behind" ]; then behind="↓$behind"; fi
git_branch="\[\033[1;36m\]git:(\[\033[0;35m\]$branch$ahead$behind\[\033[1;36m\])"
fi
调用 function,将 PS1 设置为*stuff*"$git_branch"
以访问此摘录的 output; 然后, export PROMPT_COMMAND="promptFunc"
。 如果我的提示由于“复杂性”而没有再次出现,请原谅菜鸟的错误。 作为预防措施,同样用于显示 virtualenv 并在promptFunc
中执行:
if [ ! -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
VIRT_ENV_TXT=""
if [ "$VIRTUAL_ENV" != "" ]; then
VIRT_ENV_TXT="`basename \"$VIRTUAL_ENV\"`"
elif [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
VIRT_ENV_TXT="[`basename \`dirname \"$VIRTUAL_ENV\"\``]"
fi
fi
if [ "${VIRT_ENV_TXT}" != "" ]; then
venv="\[\033[1;36m\]""virtualenv:(\[\033[0;35m\]"${VIRT_ENV_TXT}"\[\033[1;36m\]) "
fi
任何有关如何加快速度或使事情变得更容易的建议将不胜感激; 如果需要,将添加说明。
明确的 PS1 声明; $ruby
是 rvm:
PS1='\[\033]0;$TITLEPREFIX$PWD\007\]\n\[\033[33m\]\w\n\[\033[32m\]\u\[\033[38;5;253m\]@\[\033[1;34m\]9570'
PS1="$PS1$ruby$venv$git_branch\[\033[0m\]""\n""$ "
众所周知,Windows 文件系统上的几个操作比 linux 慢。
尝试在git-bash
中计时git status -sb
,以确认它是否确实是您表演中的痛点:
运行time git status -sb
设置GIT_TRACE=1
或GIT_TRACE_PERFORMANCE=1
并运行您的命令:
$ GIT_TRACE=1 git status -sb # or: $ export GIT_TRACE=1 # the next invocations of your prompt code will make git dump # information on STDERR
git status
触发索引刷新,以便能够显示每个文件的状态。
如果确实是慢点,您可以尝试使用其他方式获得ahead / behind
计数:
# you have to add some check that current branch does have a remote,
# or simply send error messages to /dev/null
remote=`git rev-parse --abbrev-ref @{u} 2> /dev/null`
if [ -z "$remote" ]; then
# no remote linked to current branch
return
fi
head=`git rev-parse --abbrev-ref HEAD`
leftahead=`git rev-list --count @{u}..HEAD`
rightahead=`git rev-list --count HEAD..@{u}`
echo "$head (ahead $leftahead) | (behind $rightahead) $remote"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.