Last active
July 18, 2021 22:15
-
-
Save eutobias/1d7f2d36b91c9c11f766bd54cf58fa83 to your computer and use it in GitHub Desktop.
.gitcolors converted to ohMyZsh theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Determine the branch/state information for this git repository. | |
function set_git_branch { | |
# Capture the output of the "git status" command. | |
git_status="$(git status 2> /dev/null)" | |
# Set color based on clean/staged/dirty. | |
if [[ ${git_status} =~ "working tree clean" ]]; then | |
state="%{$terminfo[bold]%}%{$fg[green]%}" | |
elif [[ ${git_status} =~ "Changes to be committed" ]]; then | |
state="%{$terminfo[bold]%}%{$fg[yellow]%}" | |
else | |
state="%{$terminfo[bold]%}%{$fg[red]%}" | |
fi | |
# Set arrow icon based on status against remote. | |
remote_pattern="# Your branch is (.*) of" | |
if [[ ${git_status} =~ ${remote_pattern} ]]; then | |
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then | |
remote="↑" | |
else | |
remote="↓" | |
fi | |
else | |
remote="" | |
fi | |
diverge_pattern="# Your branch and (.*) have diverged" | |
if [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="↕" | |
fi | |
branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/')" | |
# Set the final branch string. | |
echo "${state}${branch}${remote}${reset_color}" | |
} | |
local git_info='$(set_git_branch)' | |
local exit_code="%(?,,C:%{$fg[red]%}%?%{$reset_color%})" | |
PROMPT=" | |
%{$fg[white]%}[%*]%{$reset_color%} \ | |
%{$fg[cyan]%}%n \ | |
%{$fg[white]%}@ \ | |
%{$fg[green]%}%m \ | |
%{$fg[white]%}in \ | |
%{$terminfo[bold]$fg[yellow]%}%~%{$reset_color%}\ | |
${git_info} \ | |
$exit_code | |
$ %{$reset_color%}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment