Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions git-prompt-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ git_prompt_color_samples() {

local x=0
while (( x < 8 )) ; do
showColor "${ColorNames[x]}"
showColor "Dim${ColorNames[x]}"
showColor "Bold${ColorNames[x]}"
showColor "Bright${ColorNames[x]}"
showColor "${ColorNames[@]:$x:1}"
showColor "Dim${ColorNames[@]:$x:1}"
showColor "Bold${ColorNames[@]:$x:1}"
showColor "Bright${ColorNames[@]:$x:1}"
(( x++ ))
done
}
41 changes: 29 additions & 12 deletions gitprompt.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#!/usr/bin/env bash

# bash/zsh cross compatibility notes:
# - always use ${array[@]:offset:length} syntax for array indexing

function async_run() {
{
eval "$@" &> /dev/null
}&
}

function async_run_zsh() {
{
eval "$@" &> /dev/null
}&!
}


function git_prompt_dir() {
# assume the gitstatus.sh is in the same directory as this script
# code thanks to http://stackoverflow.com/questions/59895
Expand Down Expand Up @@ -438,8 +448,12 @@ function checkUpstream() {
then
if [[ -n $(git remote show) ]]; then
(
async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet"
disown -h
if [ -n $ZSH_VERSION ]; then
async_run_zsh "GIT_TERMINAL_PROMPT=0 git fetch --quiet"
else
async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet"
disown -h
fi
)
fi
fi
Expand Down Expand Up @@ -484,6 +498,9 @@ function updatePrompt() {
local PROMPT_END
local EMPTY_PROMPT
local Blue="\[\033[0;34m\]"
if [ -n $ZSH_VERSION ]; then
Blue='%{fg[blue]%}'
fi

git_prompt_config

Expand All @@ -502,30 +519,30 @@ function updatePrompt() {
local -a git_status_fields
while IFS=$'\n' read -r line; do git_status_fields+=("${line}"); done < <("${__GIT_STATUS_CMD}" 2>/dev/null)

export GIT_BRANCH=$(replaceSymbols "${git_status_fields[0]}")
local GIT_REMOTE="$(replaceSymbols "${git_status_fields[1]}")"
export GIT_BRANCH=$(replaceSymbols "${git_status_fields[@]:0:1}")
local GIT_REMOTE="$(replaceSymbols "${git_status_fields[@]:1:1}")"
if [[ "." == "${GIT_REMOTE}" ]]; then
unset GIT_REMOTE
fi
local GIT_REMOTE_USERNAME_REPO="$(replaceSymbols "${git_status_fields[2]}")"
local GIT_REMOTE_USERNAME_REPO="$(replaceSymbols "${git_status_fields[@]:2:1}")"
if [[ "." == "${GIT_REMOTE_USERNAME_REPO}" ]]; then
unset GIT_REMOTE_USERNAME_REPO
fi

local GIT_FORMATTED_UPSTREAM
local GIT_UPSTREAM_PRIVATE="${git_status_fields[3]}"
local GIT_UPSTREAM_PRIVATE="${git_status_fields[@]:3:1}"
if [[ "${__GIT_PROMPT_SHOW_UPSTREAM:-0}" != "1" || "^" == "${GIT_UPSTREAM_PRIVATE}" ]]; then
unset GIT_FORMATTED_UPSTREAM
else
GIT_FORMATTED_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/${GIT_UPSTREAM_PRIVATE}}"
fi

local GIT_STAGED="${git_status_fields[4]}"
local GIT_CONFLICTS="${git_status_fields[5]}"
local GIT_CHANGED="${git_status_fields[6]}"
local GIT_UNTRACKED="${git_status_fields[7]}"
local GIT_STASHED="${git_status_fields[8]}"
local GIT_CLEAN="${git_status_fields[9]}"
local GIT_STAGED="${git_status_fields[@]:4:1}"
local GIT_CONFLICTS="${git_status_fields[@]:5:1}"
local GIT_CHANGED="${git_status_fields[@]:6:1}"
local GIT_UNTRACKED="${git_status_fields[@]:7:1}"
local GIT_STASHED="${git_status_fields[@]:8:1}"
local GIT_CLEAN="${git_status_fields[@]:9:1}"


local NEW_PROMPT="${EMPTY_PROMPT}"
Expand Down
8 changes: 4 additions & 4 deletions gitstatus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed =
fi

IFS="^" read -ra branch_fields <<< "${branch_line/\#\# }"
branch="${branch_fields[0]}"
branch="${branch_fields[@]:0:1}"
remote=""
upstream=""

if [[ "${branch}" == *"Initial commit on"* ]]; then
IFS=" " read -ra fields <<< "${branch}"
branch="${fields[3]}"
branch="${fields[@]:3:1}"
remote="_NO_REMOTE_TRACKING_"
remote_url='.'
elif [[ "${branch}" == *"No commits yet on"* ]]; then
IFS=" " read -ra fields <<< "${branch}"
branch="${fields[4]}"
branch="${fields[@]:4:1}"
remote="_NO_REMOTE_TRACKING_"
remote_url='.'
elif [[ "${branch}" == *"no branch"* ]]; then
Expand All @@ -159,7 +159,7 @@ else
remote_url='.'
else
IFS="[,]" read -ra remote_fields <<< "${branch_fields[1]}"
upstream="${remote_fields[0]}"
upstream="${remote_fields[@]:0:1}"
for remote_field in "${remote_fields[@]}"; do
if [[ "${remote_field}" == "ahead "* ]]; then
num_ahead="${remote_field:6}"
Expand Down
54 changes: 45 additions & 9 deletions prompt-colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# source this file to get color definitions
# are also printed to STDERR.

# bash/zsh cross compatibility notes:
# - using colors modules to set colors in zsh, please autoload it
# - Dim colors, Intense Black not supported in zsh

define_color_names() {

ColorNames=( Black Red Green Yellow Blue Magenta Cyan White )
Expand Down Expand Up @@ -34,13 +38,23 @@ define_color_names() {
local attrname="${1}"
local attrcode="${2}"
while (( x < 8 )) ; do
local colorname="${ColorNames[x]}"
local fgcolorcode="${FgColors[x]}"
local bgcolorcode="${BgColors[x]}"
local colorname="${ColorNames[@]:$x:1}"
local fgcolorcode="${FgColors[@]:$x:1}"
local bgcolorcode="${BgColors[@]:$x:1}"
longcolorname="${attrname}${colorname}"
_def_color "${longcolorname}" "${attrcode}" "${fgcolorcode}"
_def_color "${longcolorname}Fg" "${attrcode}" "${fgcolorcode}"
_def_color "${longcolorname}Bg" "${attrcode}" "${bgcolorcode}"

if [ -n "$ZSH_VERSION" ]; then
# zsh
lowercolorname=$(echo $colorname | tr '[A-Z]' '[a-z]')
_def_color_zsh "${longcolorname}" "${attrcode}" "${lowercolorname}" "fg"
_def_color_zsh "${longcolorname}Fg" "${attrcode}" "${lowercolorname}" "fg"
_def_color_zsh "${longcolorname}Bg" "${attrcode}" "${lowercolorname}" "bg"
else
# bash
_def_color "${longcolorname}" "${attrcode}" "${fgcolorcode}"
_def_color "${longcolorname}Fg" "${attrcode}" "${fgcolorcode}"
_def_color "${longcolorname}Bg" "${attrcode}" "${bgcolorcode}"
fi
(( x++ ))
done
}
Expand All @@ -62,14 +76,36 @@ define_color_names() {
eval "${def}"
}

# def_color_zsh NAME ATTRCODE COLORNAME FG|BG
_def_color_zsh() {
if [ "${3}" = "0" ]; then
local def="${1}=\"%{\$reset_color%}\""
else
case ${2} in
1) # bold color
local def="${1}=\"%{\$${4}_bold[${3}]%}\""
;;
*)
local def="${1}=\"%{\$${4}[${3}]%}\""
;;
esac
fi
eval "${def}"
}


_map_colors Bold ${AttrBright}
_map_colors Bright ${AttrBright}
_map_colors Dim ${AttrDim}
_map_colors '' ${AttrNorm}

_def_color IntenseBlack 0 90
_def_color ResetColor 0 0

if [ -n "$ZSH_VERSION" ]; then
_def_color_zsh IntenseBlack 0 90
_def_color_zsh ResetColor 0 0
else
_def_color IntenseBlack 0 90
_def_color ResetColor 0 0
fi
}

# do the color definitions only once
Expand Down
11 changes: 9 additions & 2 deletions themes/Default.bgptheme
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ unset_git_prompt_colors() {
define_helpers() {
Time12a="\$(date +%H:%M)"
PathShort="\w";
NewLine="\n"

if [ -n "$ZSH_VERSION" ]; then
Time12a="%T"
PathShort="%~"
NewLine=$'\n'
fi
}

define_undefined_git_prompt_colors() {
Expand Down Expand Up @@ -81,8 +88,8 @@ define_undefined_git_prompt_colors() {
# _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL
if [ -z "${GIT_PROMPT_START_USER+x}" ]; then GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}"; fi
if [ -z "${GIT_PROMPT_START_ROOT+x}" ]; then GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}"; fi
if [ -z "${GIT_PROMPT_END_USER+x}" ]; then GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ "; fi
if [ -z "${GIT_PROMPT_END_ROOT+x}" ]; then GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # "; fi
if [ -z "${GIT_PROMPT_END_USER+x}" ]; then GIT_PROMPT_END_USER=" ${NewLine}${White}${Time12a}${ResetColor} $ "; fi
if [ -z "${GIT_PROMPT_END_ROOT+x}" ]; then GIT_PROMPT_END_ROOT=" ${NewLine}${White}${Time12a}${ResetColor} # "; fi

# Please do not add colors to these symbols
if [ -z ${GIT_PROMPT_SYMBOLS_AHEAD+x} ]; then GIT_PROMPT_SYMBOLS_AHEAD="↑·"; fi # The symbol for "n versions ahead of origin"
Expand Down