有条件的语句检查您是否位于Shell中的GIT存储库中
我正在尝试在 c:/program Files/git/etc/profile.d/git-prompt.sh
目录的Windows上编辑我的git bash终端目录是GIT存储库。
以下是我当前的代码:
if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\[\033[1;32m\]' # change to green
PS1="$PS1"'➜ ' # arrow
PS1="$PS1"'\[\033[1;36m\]' # change color to bold cyan
PS1="$PS1"'\W' # current working directory
if test -z "$WINELOADERNOEXEC"
then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
# if test -z "$COMPLETION_PATH/git-prompt.sh"
# then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
# if test -n `git branch --show-current`
# then
PS1="$PS1"'\[\033[1;34m\]' # change color to cyan
PS1="$PS1"' git:(' # bash function
PS1="$PS1"'\[\033[1;31m\]' # change color to cyan
PS1="$PS1"'`git branch --show-current`' # get current working branch
PS1="$PS1"'\[\033[1;34m\]' # change color to bold blue
PS1="$PS1"') ' # close brackets
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[1;33m\]' # change color to bold yellow
PS1="$PS1"'$ ' # prompt: always $
PS1="$PS1"'\[\033[0m\]' # change color to default
# fi
# fi
fi
fi
MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc
# Evaluate all user-specific Bash completion scripts (if any)
if test -z "$WINELOADERNOEXEC"
then
for c in "$HOME"/bash_completion.d/*.bash
do
# Handle absence of any scripts (or the folder) gracefully
test ! -f "$c" ||
. "$c"
done
fi
我正在尝试创建一个有条件的语句,以测试我的当前目录是否为git存储库,如果是的,请显示正确的格式。
如果我在GIT存储库中打开终端:
➜ test-repo git:(main)
$
如果我打开端子而没有 git存储库:
fatal: not a git repository (or any of the parent directories): .git
➜ test-repo git:()
$
Intension是删除 fatal:不是git存储库(或任何父级目录):。 git
和 git:()
如果我不在git存储库中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新如何
:
git状态的更快替代品-s
是How about
UPDATE : A faster alternative to
git status -s
would be