|
|
|
@ -22,62 +22,77 @@ function git_prompt_dir() |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# gp_set_file_var ENVAR SOMEFILE |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Set ENVAR to the path to SOMEFILE, based on $HOME, $__GIT_PROMPT_DIR, and the |
|
|
|
|
|
|
|
# directory of the current script. The SOMEFILE can be prefixed with '.', or |
|
|
|
|
|
|
|
# not. |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Return 0 (success) if ENVAR not already defined, 1 (failure) otherwise. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function gp_set_file_var() { |
|
|
|
|
|
|
|
local envar="$1" |
|
|
|
|
|
|
|
local file="$2" |
|
|
|
|
|
|
|
if eval "test -z \"\$$envar\"" ; then |
|
|
|
|
|
|
|
eval "$envar=" # set empty envar |
|
|
|
|
|
|
|
gp_maybe_set_envar_to_path "$envar" "$HOME/.$file" && return 0 |
|
|
|
|
|
|
|
gp_maybe_set_envar_to_path "$envar" "$HOME/$file" && return 0 |
|
|
|
|
|
|
|
gp_maybe_set_envar_to_path "$envar" "$HOME/lib/$file" && return 0 |
|
|
|
|
|
|
|
git_prompt_dir |
|
|
|
|
|
|
|
gp_maybe_set_envar_to_path "$envar" "$__GIT_PROMPT_DIR/$file" && return 0 |
|
|
|
|
|
|
|
gp_maybe_set_envar_to_path "$envar" "${0##*/}/$file" && return 0 |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
return 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# gp_maybe_set_envar_to_path ENVAR FILEPATH |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# return 0 (true) if FILEPATH is readable, set ENVAR to it |
|
|
|
|
|
|
|
# return 1 (false) if not |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function gp_maybe_set_envar_to_path(){ |
|
|
|
|
|
|
|
local envar="$1" |
|
|
|
|
|
|
|
local file="$2" |
|
|
|
|
|
|
|
if [[ -r "$file" ]]; then |
|
|
|
|
|
|
|
eval "$envar=\"$file\"" |
|
|
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
return 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function git_prompt_config() |
|
|
|
function git_prompt_config() |
|
|
|
{ |
|
|
|
{ |
|
|
|
# Colors |
|
|
|
|
|
|
|
ResetColor="\[\033[0m\]" # Text reset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bold |
|
|
|
# There are two files related to colors: |
|
|
|
local BoldGreen="\[\033[1;32m\]" # Green |
|
|
|
# |
|
|
|
local BoldBlue="\[\033[1;34m\]" # Blue |
|
|
|
# prompt-colors.sh -- sets generic color names suitable for bash `PS1` prompt |
|
|
|
|
|
|
|
# git-prompt-colors.sh -- sets the GIT_PROMPT color scheme, using names from prompt-colors.sh |
|
|
|
|
|
|
|
|
|
|
|
# High Intensty |
|
|
|
if gp_set_file_var __PROMPT_COLORS_SH prompt-colors.sh ; then |
|
|
|
local IntenseBlack="\[\033[0;90m\]" # Grey |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Bold High Intensty |
|
|
|
if [[ -n "${__PROMPT_COLORS_SH}" ]]; then |
|
|
|
local Magenta="\[\033[1;95m\]" # Purple |
|
|
|
source "${__PROMPT_COLORS_SH}" # outsource the color defs |
|
|
|
|
|
|
|
else |
|
|
|
# Regular Colors |
|
|
|
echo 1>&2 "Cannot find prompt-colors.sh!" |
|
|
|
local Yellow="\[\033[0;33m\]" |
|
|
|
fi |
|
|
|
local White='\[\033[37m\]' |
|
|
|
fi |
|
|
|
local Red="\[\033[0;31m\]" |
|
|
|
|
|
|
|
local Blue="\[\033[0;34m\]" |
|
|
|
|
|
|
|
local Cyan="\[\033[0;36m\]" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# source the user's ~/.git-prompt-colors.sh file, or the one that should be |
|
|
|
# source the user's ~/.git-prompt-colors.sh file, or the one that should be |
|
|
|
# sitting in the same directory as this script |
|
|
|
# sitting in the same directory as this script |
|
|
|
|
|
|
|
|
|
|
|
if [[ -z "$__GIT_PROMPT_COLORS_FILE" ]]; then |
|
|
|
if gp_set_file_var __GIT_PROMPT_COLORS_FILE git-prompt-colors.sh ; then |
|
|
|
local pfx file dir |
|
|
|
|
|
|
|
for dir in "$HOME" "$__GIT_PROMPT_DIR" ; do |
|
|
|
|
|
|
|
for pfx in '.' '' ; do |
|
|
|
|
|
|
|
file="$dir/${pfx}git-prompt-colors.sh" |
|
|
|
|
|
|
|
if [[ -f "$file" ]]; then |
|
|
|
|
|
|
|
__GIT_PROMPT_COLORS_FILE="$file" |
|
|
|
|
|
|
|
break 2 |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
# if the envar is defined, source the file for custom colors |
|
|
|
# if the envar is defined, source the file for custom colors |
|
|
|
if [[ -n "$__GIT_PROMPT_COLORS_FILE" && -f "$__GIT_PROMPT_COLORS_FILE" ]]; then |
|
|
|
if [[ -n "${__GIT_PROMPT_COLORS_FILE}" ]]; then |
|
|
|
source "$__GIT_PROMPT_COLORS_FILE" |
|
|
|
source "${__GIT_PROMPT_COLORS_FILE}" |
|
|
|
else |
|
|
|
else |
|
|
|
# Default values for the appearance of the prompt. Do not change these |
|
|
|
echo 1>&2 "Cannot find git-prompt-colors.sh!" |
|
|
|
# below. Instead, copy these to `~/.git-prompt-colors.sh` and change them |
|
|
|
|
|
|
|
# there. |
|
|
|
|
|
|
|
GIT_PROMPT_PREFIX="[" |
|
|
|
|
|
|
|
GIT_PROMPT_SUFFIX="]" |
|
|
|
|
|
|
|
GIT_PROMPT_SEPARATOR="|" |
|
|
|
|
|
|
|
GIT_PROMPT_BRANCH="${Magenta}" |
|
|
|
|
|
|
|
GIT_PROMPT_STAGED="${Red}●" |
|
|
|
|
|
|
|
GIT_PROMPT_CONFLICTS="${Red}✖" |
|
|
|
|
|
|
|
GIT_PROMPT_CHANGED="${Blue}✚" |
|
|
|
|
|
|
|
GIT_PROMPT_REMOTE=" " |
|
|
|
|
|
|
|
GIT_PROMPT_UNTRACKED="${Cyan}…" |
|
|
|
|
|
|
|
GIT_PROMPT_STASHED="${BoldBlue}⚑" |
|
|
|
|
|
|
|
GIT_PROMPT_CLEAN="${BoldGreen}✔" |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Do this only once to define PROMPT_START and PROMPT_END |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then |
|
|
|
|
|
|
|
|
|
|
|
# Various variables you might want for your PS1 prompt instead |
|
|
|
# Various variables you might want for your PS1 prompt instead |
|
|
|
local Time12a="\$(date +%H:%M)" |
|
|
|
local Time12a="\$(date +%H:%M)" |
|
|
|
@ -85,29 +100,29 @@ function git_prompt_config() |
|
|
|
# local Time12a="(\@))" |
|
|
|
# local Time12a="(\@))" |
|
|
|
local PathShort="\w" |
|
|
|
local PathShort="\w" |
|
|
|
|
|
|
|
|
|
|
|
if [ "x${GIT_PROMPT_START}" == "x" ]; then |
|
|
|
if [[ -z "${GIT_PROMPT_START}" ]] ; then |
|
|
|
PROMPT_START="${Yellow}${PathShort}${ResetColor}" |
|
|
|
PROMPT_START="${Yellow}${PathShort}${ResetColor}" |
|
|
|
else |
|
|
|
else |
|
|
|
PROMPT_START="${GIT_PROMPT_START}" |
|
|
|
PROMPT_START="${GIT_PROMPT_START}" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ "x${GIT_PROMPT_END}" == "x" ]; then |
|
|
|
if [[ -z "${GIT_PROMPT_END}" ]] ; then |
|
|
|
PROMPT_END=" \n${White}${Time12a}${ResetColor} $ " |
|
|
|
PROMPT_END=" \n${White}${Time12a}${ResetColor} $ " |
|
|
|
else |
|
|
|
else |
|
|
|
PROMPT_END="${GIT_PROMPT_END}" |
|
|
|
PROMPT_END="${GIT_PROMPT_END}" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}" |
|
|
|
EMPTY_PROMPT="${PROMPT_START}$($prompt_callback)${PROMPT_END}" |
|
|
|
|
|
|
|
|
|
|
|
# fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes |
|
|
|
# fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes |
|
|
|
GIT_PROMPT_FETCH_TIMEOUT=${1-5} |
|
|
|
GIT_PROMPT_FETCH_TIMEOUT=${1-5} |
|
|
|
if [ "x$__GIT_STATUS_CMD" == "x" ] |
|
|
|
if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. |
|
|
|
then |
|
|
|
|
|
|
|
git_prompt_dir |
|
|
|
git_prompt_dir |
|
|
|
local sfx file |
|
|
|
local sfx file |
|
|
|
# look first for a '.sh' version, then use the python version |
|
|
|
# look first for a '.sh' version, then use the python version |
|
|
|
for sfx in sh py ; do |
|
|
|
for sfx in sh py ; do |
|
|
|
file="${__GIT_PROMPT_DIR}/gitstatus.$sfx" |
|
|
|
file="$__GIT_PROMPT_DIR/gitstatus.$sfx" |
|
|
|
if [[ -x "$file" ]]; then |
|
|
|
if [[ -x "$file" ]]; then |
|
|
|
__GIT_STATUS_CMD="$file" |
|
|
|
__GIT_STATUS_CMD="$file" |
|
|
|
break |
|
|
|
break |
|
|
|
@ -151,23 +166,9 @@ function checkUpstream() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function updatePrompt() { |
|
|
|
function updatePrompt() { |
|
|
|
local GIT_PROMPT_PREFIX |
|
|
|
|
|
|
|
local GIT_PROMPT_SUFFIX |
|
|
|
|
|
|
|
local GIT_PROMPT_SEPARATOR |
|
|
|
|
|
|
|
local GIT_PROMPT_BRANCH |
|
|
|
|
|
|
|
local GIT_PROMPT_STAGED |
|
|
|
|
|
|
|
local GIT_PROMPT_CONFLICTS |
|
|
|
|
|
|
|
local GIT_PROMPT_CHANGED |
|
|
|
|
|
|
|
local GIT_PROMPT_REMOTE |
|
|
|
|
|
|
|
local GIT_PROMPT_UNTRACKED |
|
|
|
|
|
|
|
local GIT_PROMPT_STASHED |
|
|
|
|
|
|
|
local GIT_PROMPT_CLEAN |
|
|
|
|
|
|
|
local PROMPT_START |
|
|
|
local PROMPT_START |
|
|
|
local PROMPT_END |
|
|
|
local PROMPT_END |
|
|
|
local EMPTY_PROMPT |
|
|
|
local EMPTY_PROMPT |
|
|
|
local ResetColor |
|
|
|
|
|
|
|
local Blue |
|
|
|
|
|
|
|
local GIT_PROMPT_FETCH_TIMEOUT |
|
|
|
|
|
|
|
local __GIT_STATUS_CMD |
|
|
|
local __GIT_STATUS_CMD |
|
|
|
|
|
|
|
|
|
|
|
git_prompt_config |
|
|
|
git_prompt_config |
|
|
|
@ -190,37 +191,43 @@ function updatePrompt() { |
|
|
|
if [[ -n "${GitStatus}" ]]; then |
|
|
|
if [[ -n "${GitStatus}" ]]; then |
|
|
|
local STATUS=" ${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" |
|
|
|
local STATUS=" ${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" |
|
|
|
|
|
|
|
|
|
|
|
if [[ -n "${GIT_REMOTE}" ]]; then |
|
|
|
# __add_status KIND VALEXPR INSERT |
|
|
|
STATUS="${STATUS}${GIT_PROMPT_REMOTE}${GIT_REMOTE}${ResetColor}" |
|
|
|
# eg: __add_status 'STAGED' '-ne 0' |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
STATUS="${STATUS}${GIT_PROMPT_SEPARATOR}" |
|
|
|
|
|
|
|
if [ "${GIT_STAGED}" -ne "0" ]; then |
|
|
|
|
|
|
|
STATUS="${STATUS}${GIT_PROMPT_STAGED}${GIT_STAGED}${ResetColor}" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "${GIT_CONFLICTS}" -ne "0" ]; then |
|
|
|
|
|
|
|
STATUS="${STATUS}${GIT_PROMPT_CONFLICTS}${GIT_CONFLICTS}${ResetColor}" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "${GIT_CHANGED}" -ne "0" ]; then |
|
|
|
__chk_gitvar_status() { |
|
|
|
STATUS="${STATUS}${GIT_PROMPT_CHANGED}${GIT_CHANGED}${ResetColor}" |
|
|
|
local v |
|
|
|
fi |
|
|
|
if [[ "x$2" == "x-n" ]] ; then |
|
|
|
|
|
|
|
v="$2 \"\${GIT_$1}\"" |
|
|
|
if [ "${GIT_UNTRACKED}" -ne "0" ]; then |
|
|
|
else |
|
|
|
STATUS="${STATUS}${GIT_PROMPT_UNTRACKED}${GIT_UNTRACKED}${ResetColor}" |
|
|
|
v="\${GIT_$1} $2" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
if eval "test $v" ; then |
|
|
|
if [ "${GIT_STASHED}" -ne "0" ]; then |
|
|
|
if [[ $# -lt 2 || "$3" != '-' ]]; then |
|
|
|
STATUS="${STATUS}${GIT_PROMPT_STASHED}${GIT_STASHED}${ResetColor}" |
|
|
|
__add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
__add_status "\${GIT_PROMPT_$1}\${ResetColor}" |
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ "${GIT_CLEAN}" -eq "1" ]; then |
|
|
|
|
|
|
|
STATUS="${STATUS}${GIT_PROMPT_CLEAN}" |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
|
STATUS="${STATUS}${ResetColor}${GIT_PROMPT_SUFFIX}" |
|
|
|
|
|
|
|
|
|
|
|
__add_gitvar_status() { |
|
|
|
|
|
|
|
__add_status "\${GIT_PROMPT_$1}\${GIT_$1}\${ResetColor}" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# __add_status SOMETEXT |
|
|
|
|
|
|
|
__add_status() { |
|
|
|
|
|
|
|
eval "STATUS=\"${STATUS}$1\"" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__chk_gitvar_status 'REMOTE' '-n' |
|
|
|
|
|
|
|
__add_status "$GIT_PROMPT_SEPARATOR" |
|
|
|
|
|
|
|
__chk_gitvar_status 'STAGED' '-ne 0' |
|
|
|
|
|
|
|
__chk_gitvar_status 'CONFLICTS' '-ne 0' |
|
|
|
|
|
|
|
__chk_gitvar_status 'CHANGED' '-ne 0' |
|
|
|
|
|
|
|
__chk_gitvar_status 'UNTRACKED' '-ne 0' |
|
|
|
|
|
|
|
__chk_gitvar_status 'STASHED' '-ne 0' |
|
|
|
|
|
|
|
__chk_gitvar_status 'CLEAN' '-eq 1' - |
|
|
|
|
|
|
|
__add_status "${ResetColor}$GIT_PROMPT_SUFFIX" |
|
|
|
|
|
|
|
|
|
|
|
PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" |
|
|
|
PS1="${PROMPT_START}$($prompt_callback)${STATUS}${PROMPT_END}" |
|
|
|
if [[ -n "${VIRTUAL_ENV}" ]]; then |
|
|
|
if [[ -n "${VIRTUAL_ENV}" ]]; then |
|
|
|
|