Browse Source

Added git info to zsh prompt

pull/2/head
Josh Wolfe 6 years ago
parent
commit
f15928856d
  1. 92
      .zsh/git-prompt.zsh
  2. 17
      .zshrc

92
.zsh/git-prompt.zsh

@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
function in_git_repos() {
test "`git rev-parse --is-inside-work-tree 2>/dev/null`" = "true"
}
function git_current_branch() {
if in_git_repos; then
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref=$(git rev-parse --short HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
fi
}
function git_status_is_clean() {
if in_git_repos; then
local lines=$(git status --porcelain | egrep -v '^\?\? ' | wc -l)
test $lines = 0
fi
}
function git_unknown_files() {
if in_git_repos; then
local lines=$(git status --porcelain | egrep '^\?\? ' | wc -l)
test $lines = 0
fi
}
function git_stash_is_clean() {
if in_git_repos; then
local lines=$(git stash list | wc -l)
test $lines = 0
fi
}
function git_no_branches() {
if in_git_repos; then
local lines=$(git branch | wc -l)
test $lines = 1
fi
}
function git_single_remote() {
if in_git_repos; then
local lines=$(git remote | wc -l)
test $lines -le 1
fi
}
function git_no_remote() {
if in_git_repos; then
local lines=$(git remote | wc -l)
test $lines = 0
fi
}
function git_branch_is_pushed() {
if in_git_repos; then
if git branch -r | grep "origin/master" >/dev/null 2>&1; then
git_no_remote || git diff-tree --quiet origin/master heads/master
fi
fi
}
#-----------------------------------------------------------------------------
function git_prompt_precmd() {
local GITINFO=""
if [ ! -z `git_current_branch` ]; then
GITINFO=" "
if ! git_status_is_clean; then
GITINFO="$GITINFO*"
fi
if ! git_unknown_files; then
GITINFO="${GITINFO}?"
fi
if ! git_branch_is_pushed; then
GITINFO="$GITINFO"
fi
if ! git_stash_is_clean; then
GITINFO="$GITINFO"
fi
if ! git_no_branches; then
GITINFO="$GITINFO"
fi
if ! git_single_remote; then
GITINFO="$GITINFO®"
fi
GITINFO="$GITINFO "
fi
echo $GITINFO
}

17
.zshrc

@ -145,17 +145,24 @@ _newline=$'\n' @@ -145,17 +145,24 @@ _newline=$'\n'
_lineup=$'\e[1A'
_linedown=$'\e[1B'
#* There are uncommitted changes.
#? There are files git doesn't know about.
#➚ There are commits that haven't been pushed yet.
#☰ There are stashed files.
#⌥ There are branches other than master.
#® There are remote repositories other than origin configured.
source ~/.zsh/git-prompt.zsh
function preexec() {
echo
echo
}
function precmd() {
echo -e "$txtpur"
jobs
echo -ne "$txtrst"
echo
PSVAR=`git_prompt_precmd`
}
PROMPT="%F{red}%n%F{white}@%F{green}%m %F{blue}%~ ${_newline}%F{white}$ "
RPROMPT=%{${_lineup}%}%F{red}%(?..%? )%F{white}[`date +%H:%M:%S`]%{${_linedown}%}
RPROMPT=%{${_lineup}%}%F{red}%(?..%? )%F{yellow}%v%F{white}[`date +%H:%M:%S`]%{${_linedown}%}
setopt promptsubst
# Delay of 0.1 seconds

Loading…
Cancel
Save