1
0
Fork 0

my own git info now

This commit is contained in:
Von Random 2017-03-01 20:14:32 +03:00
parent 1af398dc4b
commit bd607383aa
2 changed files with 54 additions and 44 deletions

View file

@ -1,5 +1,13 @@
vscripts="${HOME}/vscripts"
[[ -d ${vscripts} && ${PATH} != *${vscripts}* ]] && export PATH=${PATH}:${vscripts}
completion_path='/usr/share/bash-completion/bash_completion'
[[ -r "${completion_path}" ]] && . "${completion_path}"
# because fuck you thats' why
fuck() { echo 'no, fuck you'; } fuck() { echo 'no, fuck you'; }
# some cool git stuff
gdiff() { /usr/bin/git diff --color "$@"; } gdiff() { /usr/bin/git diff --color "$@"; }
gdf() gdf()
@ -15,48 +23,49 @@ gdf()
fi fi
} }
enable_vscripts() git_prompt()
{ {
local vscripts="${HOME}/vscripts" # FIXME:
[[ -d ${vscripts} && ${PATH} != *${vscripts}* ]] && export PATH=${PATH}:${vscripts} # upon the first traverse into the git repository, we always get staged
# count instead of unstaged, that is weird
prompt_command
if ! raw_status="$(git status --porcelain -bu 2>/dev/null)"; then
return
fi
git_status=''
staged_count=0
unstaged_count=0
untracked_count=0
unmerged_count=0
while read line; do
if [[ "${line:0:2}" == '##' ]]; then
read branch_info <<< "${line:3}"
fi
[[ "${line:0:2}" =~ .[MD] ]] && (( unstaged_count++ ))
[[ "${line:0:2}" =~ [MDARC]. ]] && (( staged_count++ ))
[[ "${line:0:2}" == '??' ]] && (( untracked_count++ ))
[[ "${line:0:2}" =~ (U[ADU]|A[AU]|D[DU]) ]] && (( unmerged_count++ ))
done <<< "${raw_status}"
(( $unstaged_count > 0 )) && git_status+="${pmagenta}~${unstaged_count}"
(( $staged_count > 0 )) && git_status+="${pyellow}+${staged_count}"
(( $untracked_count > 0 )) && git_status+="${pcyan}?${untracked_count}"
(( $unmerged_count > 0 )) && git_status+="${pred}!${unmerged_count}"
[[ -z "${git_status}" ]] && git_status='.'
full_status="{ ${pblue}${branch_info}${preset} | ${git_status}${preset} }"
IFS="$ifs_temp"
PS1="${ps_line1} ${full_status}\n${ps_line2}"
} }
enable_completion() gitmode()
{ {
local completion_path='/usr/share/bash-completion/bash_completion' if [[ -n "${OLD_PROMPT}" ]]; then
[[ -r "${completion_path}" ]] && . "${completion_path}" PROMPT_COMMAND=${OLD_PROMPT}
} unset OLD_PROMPT
enable_git_prompt()
{
local git_prompt_path='/usr/lib/bash-git-prompt/gitprompt.sh'
if [[ -r "${git_prompt_path}" ]]; then
GIT_PROMPT_FETCH_REMOTE_STATUS=0
GIT_PROMPT_SHOW_UPSTREAM=1
GIT_PROMPT_ONLY_IN_REPO=1
# theme overrides
if [[ $USER == 'von' ]]; then
git_prompt_username=""
else else
git_prompt_username="${pred}${USER}${preset} " OLD_PROMPT=${PROMPT_COMMAND}
fi PROMPT_COMMAND=git_prompt
GIT_PROMPT_PREFIX="[ "
GIT_PROMPT_SUFFIX=" ]"
GIT_PROMPT_SEPARATOR=" "
GIT_PROMPT_START="[ ${git_prompt_username}${HOSTNAME}:${pbold}\w${preset} ]"
GIT_PROMPT_THEME_NAME="Custom"
GIT_PROMPT_UNTRACKED="${pcyan}u"
GIT_PROMPT_CHANGED="${pblue}+"
GIT_PROMPT_STAGED="${pyellow}s"
GIT_PROMPT_CONFLICTS="${pred}x"
GIT_PROMPT_STASHED="${ppurple}→"
GIT_PROMPT_CLEAN="${pgreen}."
GIT_PROMPT_END_USER="\n${pbold}>${preset} "
GIT_PROMPT_END_ROOT="\n${pred}>${preset} "
. "${git_prompt_path}"
fi fi
} }
enable_vscripts
enable_completion
enable_git_prompt

9
bashrc
View file

@ -39,8 +39,6 @@ preset='\[\e[0m\]'
pbold='\[\e[1m\]' pbold='\[\e[1m\]'
reset='\e[0m' reset='\e[0m'
bold='\e[1m' bold='\e[1m'
newline='
'
prompt_command() prompt_command()
{ {
case ${TERM} in case ${TERM} in
@ -61,7 +59,9 @@ prompt_command()
else else
bang="${pred}>" bang="${pred}>"
fi fi
PS1="[ ${prompt_user}${HOSTNAME}:${pbold}\w${preset} ]${newline}${bang}${preset} " ps_line1="[ ${prompt_user}${HOSTNAME}:${pbold}\w${preset} ]"
ps_line2="${bang}${preset} "
PS1="${ps_line1}\n${ps_line2}"
} }
PROMPT_COMMAND=prompt_command PROMPT_COMMAND=prompt_command
# }}} # }}}
@ -130,8 +130,9 @@ alias mountmdf='sudo mount -o loop'
alias mountnrg='sudo mount -o loop,offset=307200' alias mountnrg='sudo mount -o loop,offset=307200'
# git # git
alias gss='command git status -s'
alias gci='command git commit' alias gci='command git commit'
alias gsl='command git stash list'
alias gss='command git status -sbu'
alias gup='command git pull' alias gup='command git pull'
# tig # tig