Основываясь на ответе 6LYTH3, я решил опубликовать свой собственный из-за некоторых улучшений, которые могут пригодиться:
Простое решение
Откройте ~/.bash_profile и добавьте следующее содержимое
# \[\e[0m\] resets the color to default color
reset_color='\[\e[0m\]'
# \[\033[33m\] sets the color to yellow
path_color='\[\033[33m\]'
# \e[0;32m\ sets the color to green
git_clean_color='\[\e[0;32m\]'
# \e[0;31m\ sets the color to red
git_dirty_color='\[\e[0;31m\]'
# determines if the git branch you are on is clean or dirty
git_prompt ()
{
# Is this a git directory?
if ! git rev-parse --git-dir > /dev/null 2>&1; then
return 0
fi
# Grab working branch name
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
# Clean or dirty branch
if git diff --quiet 2>/dev/null >&2; then
git_color="${git_clean_color}"
else
git_color="${git_dirty_color}"
fi
echo " [$git_color$git_branch${reset_color}]"
}
export PS1="${path_color}\w\[\e[0m\]$(git_prompt)\n"
Это должно:
1) Prompt the path you're in, in color: path_color.
2) Tell you which branch are you.
3) Color the name of the branch based on the status of the branch with git_clean_color
for a clean work directory and git_dirty_color for a dirty one.
4) The brackets should stay in the default color you established in your computer.
5) Puts the prompt in the next line for readability.
Вы можете настроить цвета с помощью этого списка а>
Продуманное решение
Другой вариант — использовать Git Bash Prompt, установить с помощью этого. Я использовал вариант через Homebrew на Mac OS X.
git_prompt_list_themes чтобы посмотреть темы, но мне не понравилась ни одна из них.
git_prompt_color_samples, чтобы увидеть доступные цвета.
git_prompt_make_custom_theme [<Name of base theme>] для создания новой пользовательской темы должен быть создан файл .git-prompt-colors.sh.
subl ~/.git-prompt-colors.sh, чтобы открыть git-prompt-colors.sh и настроить:
Файл .git-prompt-colors.sh должен выглядеть так с моей настройкой
override_git_prompt_colors() {
GIT_PROMPT_THEME_NAME="Custom"
# Clean or dirty branch
if git diff --quiet 2>/dev/null >&2; then
GIT_PROMPT_BRANCH="${Green}"
else
GIT_PROMPT_BRANCH="${Red}"
fi
}
reload_git_prompt_colors "Custom"
Надеюсь, это поможет, хорошего дня!
person
Jose Paez
schedule
16.04.2019