From 2f622e5c3716398dd40caf736f6247d8191ee9b7 Mon Sep 17 00:00:00 2001 From: Georgi Gardev Date: Tue, 18 Oct 2016 16:08:55 +0300 Subject: [PATCH] Migrating to Bash --- .bash_aliases | 2 +- .bash_profile | 13 +- .bashrc | 235 +- .git-completion.bash | 2857 +++++++++++++++++ bash-git-prompt/.brew/bash-git-prompt.rb | 27 + bash-git-prompt/INSTALL_RECEIPT.json | 1 + bash-git-prompt/LICENSE.txt | 23 + .../share/doc/bash-git-prompt/README.md | 359 +++ bash-git-prompt/share/git-prompt-help.sh | 76 + bash-git-prompt/share/gitprompt.fish | 112 + bash-git-prompt/share/gitprompt.sh | 651 ++++ bash-git-prompt/share/gitstatus.py | 153 + bash-git-prompt/share/gitstatus.sh | 121 + bash-git-prompt/share/gitstatus_pre-1.7.10.sh | 125 + bash-git-prompt/share/prompt-colors.sh | 82 + bash-git-prompt/share/themes/Chmike.bgptheme | 31 + bash-git-prompt/share/themes/Crunch.bgptheme | 34 + .../share/themes/Custom.bgptemplate | 58 + bash-git-prompt/share/themes/Default.bgptheme | 106 + .../share/themes/Default_NoExitState.bgptheme | 11 + .../Default_NoExitState_Ubuntu.bgptheme | 15 + .../share/themes/Default_Ubuntu.bgptheme | 11 + .../share/themes/Evermeet.bgptheme | 30 + .../share/themes/Evermeet_Lowres.bgptheme | 32 + .../share/themes/Evermeet_Ubuntu.bgptheme | 32 + bash-git-prompt/share/themes/Georgi.bgptheme | 21 + bash-git-prompt/share/themes/Minimal.bgptheme | 61 + .../share/themes/Plague_Doctor.bgptheme | 41 + .../share/themes/Single_line.bgptheme | 11 + .../themes/Single_line_NoExitState.bgptheme | 12 + .../Single_line_NoExitState_openSUSE.bgptheme | 19 + .../themes/Single_line_Solarized.bgptheme | 34 + .../share/themes/Single_line_Ubuntu.bgptheme | 25 + .../themes/Single_line_openSUSE.bgptheme | 19 + .../share/themes/Solarized.bgptheme | 13 + .../themes/Solarized_Extravagant.bgptheme | 41 + .../themes/Solarized_NoExitState.bgptheme | 16 + .../Solarized_NoExitState_Ubuntu.bgptheme | 18 + .../share/themes/Solarized_Ubuntu.bgptheme | 14 + .../share/themes/Solarized_UserHost.bgptheme | 23 + .../themes/TruncatedPwd_WindowTitle.bgptheme | 40 + ...ncatedPwd_WindowTitle_NoExitState.bgptheme | 40 + ...wd_WindowTitle_NoExitState_Ubuntu.bgptheme | 46 + .../TruncatedPwd_WindowTitle_Ubuntu.bgptheme | 45 + 44 files changed, 5545 insertions(+), 191 deletions(-) create mode 100644 .git-completion.bash create mode 100644 bash-git-prompt/.brew/bash-git-prompt.rb create mode 100644 bash-git-prompt/INSTALL_RECEIPT.json create mode 100644 bash-git-prompt/LICENSE.txt create mode 100644 bash-git-prompt/share/doc/bash-git-prompt/README.md create mode 100755 bash-git-prompt/share/git-prompt-help.sh create mode 100644 bash-git-prompt/share/gitprompt.fish create mode 100755 bash-git-prompt/share/gitprompt.sh create mode 100755 bash-git-prompt/share/gitstatus.py create mode 100755 bash-git-prompt/share/gitstatus.sh create mode 100755 bash-git-prompt/share/gitstatus_pre-1.7.10.sh create mode 100644 bash-git-prompt/share/prompt-colors.sh create mode 100644 bash-git-prompt/share/themes/Chmike.bgptheme create mode 100644 bash-git-prompt/share/themes/Crunch.bgptheme create mode 100644 bash-git-prompt/share/themes/Custom.bgptemplate create mode 100644 bash-git-prompt/share/themes/Default.bgptheme create mode 100644 bash-git-prompt/share/themes/Default_NoExitState.bgptheme create mode 100644 bash-git-prompt/share/themes/Default_NoExitState_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/Default_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/Evermeet.bgptheme create mode 100644 bash-git-prompt/share/themes/Evermeet_Lowres.bgptheme create mode 100644 bash-git-prompt/share/themes/Evermeet_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/Georgi.bgptheme create mode 100644 bash-git-prompt/share/themes/Minimal.bgptheme create mode 100644 bash-git-prompt/share/themes/Plague_Doctor.bgptheme create mode 100644 bash-git-prompt/share/themes/Single_line.bgptheme create mode 100644 bash-git-prompt/share/themes/Single_line_NoExitState.bgptheme create mode 100644 bash-git-prompt/share/themes/Single_line_NoExitState_openSUSE.bgptheme create mode 100644 bash-git-prompt/share/themes/Single_line_Solarized.bgptheme create mode 100644 bash-git-prompt/share/themes/Single_line_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/Single_line_openSUSE.bgptheme create mode 100644 bash-git-prompt/share/themes/Solarized.bgptheme create mode 100644 bash-git-prompt/share/themes/Solarized_Extravagant.bgptheme create mode 100644 bash-git-prompt/share/themes/Solarized_NoExitState.bgptheme create mode 100644 bash-git-prompt/share/themes/Solarized_NoExitState_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/Solarized_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/Solarized_UserHost.bgptheme create mode 100644 bash-git-prompt/share/themes/TruncatedPwd_WindowTitle.bgptheme create mode 100644 bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme create mode 100644 bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState_Ubuntu.bgptheme create mode 100644 bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_Ubuntu.bgptheme diff --git a/.bash_aliases b/.bash_aliases index 355977a..b41e888 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -20,7 +20,7 @@ alias gbd="git branch -D" alias gm="git mergetool" alias tm="tmux -2 attach-session -t "default" || tmux -2 new-session -s \"default\"" -alias evaldocker="eval \"$(docker-machine env default)\"" + # Editing files alias aliases="vim ~/.bash_aliases" alias vimrc="vim ~/.vimrc" diff --git a/.bash_profile b/.bash_profile index 9804cab..86795d7 100644 --- a/.bash_profile +++ b/.bash_profile @@ -1,12 +1 @@ - -[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile - -[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* - -# if [[ "$TERM" != "screen-256color" ]] -# then -# tmux -2 attach-session -t "default" || tmux -2 new-session -s "default" -# exit -# fi - -alias tm="tmux -2 attach-session -t "default" || tmux -2 new-session -s \"default\"" +source ~/.bashrc diff --git a/.bashrc b/.bashrc index 8e706e2..6aa7b26 100644 --- a/.bashrc +++ b/.bashrc @@ -1,205 +1,68 @@ -# ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples +# Colors +PS1='\[\e[1;32m\]\w\[\e[m\]\[\e[1;0m\]:\[\e[m\] \[\e[1;37m\]' +export TERM=xterm-256color -# If not running interactively, don't do anything -[ -z "$PS1" ] && return +shopt -s autocd +shopt -s cdspell +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# Disable Caret-C output +stty -ctlecho + +#so as not to be disturbed by Ctrl-S ctrl-Q in terminals: +stty -ixon + +###################### +# History Management # +###################### + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=5000 +HISTFILESIZE=2000 # don't put duplicate lines or lines starting with space in the history. # See bash(1) for more options HISTCONTROL=ignoreboth -# append to the history file, don't overwrite it -shopt -s histappend -shopt -s autocd - -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# If set, the pattern "**" used in a pathname expansion context will -# match all files and zero or more directories and subdirectories. -#shopt -s globstar - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) +if [ -f ~/.bash-git-prompt/share/gitprompt.sh ]; then + source ~/.bash-git-prompt/share/gitprompt.sh fi -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color) color_prompt=yes;; -esac +GIT_PROMPT_ONLY_IN_REPO=1 +GIT_PROMPT_START="\[\e[1;32m\]\w\[\e[m\]" +GIT_PROMPT_END="\[\e[1;37m\]: \[\e[1;37m\]" +GIT_PROMPT_THEME=Georgi -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -#force_color_prompt=yes - -force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -# Reset -Color_Off="\[\033[0m\]" # Text Reset - -# Regular Colors -Black="\[\033[0;30m\]" # Black -Red="\[\033[0;31m\]" # Red -Green="\[\033[0;32m\]" # Green -Yellow="\[\033[0;33m\]" # Yellow -Blue="\[\033[0;34m\]" # Blue -Purple="\[\033[0;35m\]" # Purple -Cyan="\[\033[0;36m\]" # Cyan -White="\[\033[0;37m\]" # White - -# Bold -BBlack="\[\033[1;30m\]" # Black -BRed="\[\033[1;31m\]" # Red -BGreen="\[\033[1;32m\]" # Green -BYellow="\[\033[1;33m\]" # Yellow -BBlue="\[\033[1;34m\]" # Blue -BPurple="\[\033[1;35m\]" # Purple -BCyan="\[\033[1;36m\]" # Cyan -BWhite="\[\033[1;37m\]" # White - -# Underline -UBlack="\[\033[4;30m\]" # Black -URed="\[\033[4;31m\]" # Red -UGreen="\[\033[4;32m\]" # Green -UYellow="\[\033[4;33m\]" # Yellow -UBlue="\[\033[4;34m\]" # Blue -UPurple="\[\033[4;35m\]" # Purple -UCyan="\[\033[4;36m\]" # Cyan -UWhite="\[\033[4;37m\]" # White - -# Background -On_Black="\[\033[40m\]" # Black -On_Red="\[\033[41m\]" # Red -On_Green="\[\033[42m\]" # Green -On_Yellow="\[\033[43m\]" # Yellow -On_Blue="\[\033[44m\]" # Blue -On_Purple="\[\033[45m\]" # Purple -On_Cyan="\[\033[46m\]" # Cyan -On_White="\[\033[47m\]" # White - -# High Intensty -IBlack="\[\033[0;90m\]" # Black -IRed="\[\033[0;91m\]" # Red -IGreen="\[\033[0;92m\]" # Green -IYellow="\[\033[0;93m\]" # Yellow -IBlue="\[\033[0;94m\]" # Blue -IPurple="\[\033[0;95m\]" # Purple -ICyan="\[\033[0;96m\]" # Cyan -IWhite="\[\033[0;97m\]" # White - -# Bold High Intensty -BIBlack="\[\033[1;90m\]" # Black -BIRed="\[\033[1;91m\]" # Red -BIGreen="\[\033[1;92m\]" # Green -BIYellow="\[\033[1;93m\]" # Yellow -BIBlue="\[\033[1;94m\]" # Blue -BIPurple="\[\033[1;95m\]" # Purple -BICyan="\[\033[1;96m\]" # Cyan -BIWhite="\[\033[1;97m\]" # White - -# High Intensty backgrounds -On_IBlack="\[\033[0;100m\]" # Black -On_IRed="\[\033[0;101m\]" # Red -On_IGreen="\[\033[0;102m\]" # Green -On_IYellow="\[\033[0;103m\]" # Yellow -On_IBlue="\[\033[0;104m\]" # Blue -On_IPurple="\[\033[10;95m\]" # Purple -On_ICyan="\[\033[0;106m\]" # Cyan -On_IWhite="\[\033[0;107m\]" # White - -# Various variables you might want for your PS1 prompt instead -Time12h="\A" -Time12a="\@" -PathShort="\w" -PathFull="\W" -NewLine="\n" -Jobs="\j" - -if [ "$color_prompt" = yes ]; then - PS1='$(git branch &>/dev/null;\ -if [ $? -eq 0 ]; then \ - echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \ - if [ "$?" -eq "0" ]; then \ - # @4 - Clean repository - nothing to commit - echo "'$BGreen$PathShort$BCyan'"$(__git_ps1 " (%s)"); \ - else \ - # @5 - Changes to working tree - echo "'$BGreen$PathShort$IRed'"$(__git_ps1 " (%s)"); \ - fi)'$BWhite':'$Color_Off' "; \ -else \ - # @2 - Prompt when not in GIT repo - echo "'$BGreen$PathShort$BWhite':'$Color_Off' "; \ -fi)' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi - -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac +###################### +# Aliases # +###################### # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Add an "alert" alias for long running commands. Use like so: -# sleep 10; alert -alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. +alias ls='ls -G' +alias ll='ls -alFG' +alias la='ls -AG' +alias l='ls -CFG' if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi -if [ -f ~/.bash_local_aliases ]; then - . ~/.bash_local_aliases -fi +###################### +# Completion # +###################### # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile @@ -207,3 +70,19 @@ fi if [ -f /etc/bash_completion ] && ! shopt -oq posix; then . /etc/bash_completion fi + +# Git completion +if [ -f ~/.git-completion.bash ]; then + . ~/.git-completion.bash +fi + +###################### +# Sources & exports # +###################### + +if [ -f ~/.bashrc_local ]; then + . ~/.bashrc_local +fi + +# Editor +export EDITOR='subl -w' diff --git a/.git-completion.bash b/.git-completion.bash new file mode 100644 index 0000000..96b2e42 --- /dev/null +++ b/.git-completion.bash @@ -0,0 +1,2857 @@ +# bash/zsh completion support for core Git. +# +# Copyright (C) 2006,2007 Shawn O. Pearce +# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). +# Distributed under the GNU General Public License, version 2.0. +# +# The contained completion routines provide support for completing: +# +# *) local and remote branch names +# *) local and remote tag names +# *) .git/remotes file names +# *) git 'subcommands' +# *) git email aliases for git-send-email +# *) tree paths within 'ref:path/to/file' expressions +# *) file paths within current working directory and index +# *) common --long-options +# +# To use these routines: +# +# 1) Copy this file to somewhere (e.g. ~/.git-completion.bash). +# 2) Add the following line to your .bashrc/.zshrc: +# source ~/.git-completion.bash +# 3) Consider changing your PS1 to also show the current branch, +# see git-prompt.sh for details. +# +# If you use complex aliases of form '!f() { ... }; f', you can use the null +# command ':' as the first command in the function body to declare the desired +# completion style. For example '!f() { : git commit ; ... }; f' will +# tell the completion to use commit completion. This also works with aliases +# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". + +case "$COMP_WORDBREAKS" in +*:*) : great ;; +*) COMP_WORDBREAKS="$COMP_WORDBREAKS:" +esac + +# __gitdir accepts 0 or 1 arguments (i.e., location) +# returns location of .git repo +__gitdir () +{ + if [ -z "${1-}" ]; then + if [ -n "${__git_dir-}" ]; then + echo "$__git_dir" + elif [ -n "${GIT_DIR-}" ]; then + test -d "${GIT_DIR-}" || return 1 + echo "$GIT_DIR" + elif [ -d .git ]; then + echo .git + else + git rev-parse --git-dir 2>/dev/null + fi + elif [ -d "$1/.git" ]; then + echo "$1/.git" + else + echo "$1" + fi +} + +# The following function is based on code from: +# +# bash_completion - programmable completion functions for bash 3.2+ +# +# Copyright © 2006-2008, Ian Macdonald +# © 2009-2010, Bash Completion Maintainers +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# The latest version of this software can be obtained here: +# +# http://bash-completion.alioth.debian.org/ +# +# RELEASE: 2.x + +# This function can be used to access a tokenized list of words +# on the command line: +# +# __git_reassemble_comp_words_by_ref '=:' +# if test "${words_[cword_-1]}" = -w +# then +# ... +# fi +# +# The argument should be a collection of characters from the list of +# word completion separators (COMP_WORDBREAKS) to treat as ordinary +# characters. +# +# This is roughly equivalent to going back in time and setting +# COMP_WORDBREAKS to exclude those characters. The intent is to +# make option types like --date= and : easy to +# recognize by treating each shell word as a single token. +# +# It is best not to set COMP_WORDBREAKS directly because the value is +# shared with other completion scripts. By the time the completion +# function gets called, COMP_WORDS has already been populated so local +# changes to COMP_WORDBREAKS have no effect. +# +# Output: words_, cword_, cur_. + +__git_reassemble_comp_words_by_ref() +{ + local exclude i j first + # Which word separators to exclude? + exclude="${1//[^$COMP_WORDBREAKS]}" + cword_=$COMP_CWORD + if [ -z "$exclude" ]; then + words_=("${COMP_WORDS[@]}") + return + fi + # List of word completion separators has shrunk; + # re-assemble words to complete. + for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do + # Append each nonempty word consisting of just + # word separator characters to the current word. + first=t + while + [ $i -gt 0 ] && + [ -n "${COMP_WORDS[$i]}" ] && + # word consists of excluded word separators + [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] + do + # Attach to the previous token, + # unless the previous token is the command name. + if [ $j -ge 2 ] && [ -n "$first" ]; then + ((j--)) + fi + first= + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + if (($i < ${#COMP_WORDS[@]} - 1)); then + ((i++)) + else + # Done. + return + fi + done + words_[$j]=${words_[j]}${COMP_WORDS[i]} + if [ $i = $COMP_CWORD ]; then + cword_=$j + fi + done +} + +if ! type _get_comp_words_by_ref >/dev/null 2>&1; then +_get_comp_words_by_ref () +{ + local exclude cur_ words_ cword_ + if [ "$1" = "-n" ]; then + exclude=$2 + shift 2 + fi + __git_reassemble_comp_words_by_ref "$exclude" + cur_=${words_[cword_]} + while [ $# -gt 0 ]; do + case "$1" in + cur) + cur=$cur_ + ;; + prev) + prev=${words_[$cword_-1]} + ;; + words) + words=("${words_[@]}") + ;; + cword) + cword=$cword_ + ;; + esac + shift + done +} +fi + +__gitcompappend () +{ + local x i=${#COMPREPLY[@]} + for x in $1; do + if [[ "$x" == "$3"* ]]; then + COMPREPLY[i++]="$2$x$4" + fi + done +} + +__gitcompadd () +{ + COMPREPLY=() + __gitcompappend "$@" +} + +# Generates completion reply, appending a space to possible completion words, +# if necessary. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word (optional). +__gitcomp () +{ + local cur_="${3-$cur}" + + case "$cur_" in + --*=) + ;; + *) + local c i=0 IFS=$' \t\n' + for c in $1; do + c="$c${4-}" + if [[ $c == "$cur_"* ]]; then + case $c in + --*=*|*.) ;; + *) c="$c " ;; + esac + COMPREPLY[i++]="${2-}$c" + fi + done + ;; + esac +} + +# Variation of __gitcomp_nl () that appends to the existing list of +# completion candidates, COMPREPLY. +__gitcomp_nl_append () +{ + local IFS=$'\n' + __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" +} + +# Generates completion reply from newline-separated possible completion words +# by appending a space to all of them. +# It accepts 1 to 4 arguments: +# 1: List of possible completion words, separated by a single newline. +# 2: A prefix to be added to each possible completion word (optional). +# 3: Generate possible completion matches for this word (optional). +# 4: A suffix to be appended to each possible completion word instead of +# the default space (optional). If specified but empty, nothing is +# appended. +__gitcomp_nl () +{ + COMPREPLY=() + __gitcomp_nl_append "$@" +} + +# Generates completion reply with compgen from newline-separated possible +# completion filenames. +# It accepts 1 to 3 arguments: +# 1: List of possible completion filenames, separated by a single newline. +# 2: A directory prefix to be added to each possible completion filename +# (optional). +# 3: Generate possible completion matches for this word (optional). +__gitcomp_file () +{ + local IFS=$'\n' + + # XXX does not work when the directory prefix contains a tilde, + # since tilde expansion is not applied. + # This means that COMPREPLY will be empty and Bash default + # completion will be used. + __gitcompadd "$1" "${2-}" "${3-$cur}" "" + + # use a hack to enable file mode in bash < 4 + compopt -o filenames +o nospace 2>/dev/null || + compgen -f /non-existing-dir/ > /dev/null +} + +# Execute 'git ls-files', unless the --committable option is specified, in +# which case it runs 'git diff-index' to find out the files that can be +# committed. It return paths relative to the directory specified in the first +# argument, and using the options specified in the second argument. +__git_ls_files_helper () +{ + if [ "$2" == "--committable" ]; then + git -C "$1" diff-index --name-only --relative HEAD + else + # NOTE: $2 is not quoted in order to support multiple options + git -C "$1" ls-files --exclude-standard $2 + fi 2>/dev/null +} + + +# __git_index_files accepts 1 or 2 arguments: +# 1: Options to pass to ls-files (required). +# 2: A directory path (optional). +# If provided, only files within the specified directory are listed. +# Sub directories are never recursed. Path must have a trailing +# slash. +__git_index_files () +{ + local dir="$(__gitdir)" root="${2-.}" file + + if [ -d "$dir" ]; then + __git_ls_files_helper "$root" "$1" | + while read -r file; do + case "$file" in + ?*/*) echo "${file%%/*}" ;; + *) echo "$file" ;; + esac + done | sort | uniq + fi +} + +__git_heads () +{ + local dir="$(__gitdir)" + if [ -d "$dir" ]; then + git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + refs/heads + return + fi +} + +__git_tags () +{ + local dir="$(__gitdir)" + if [ -d "$dir" ]; then + git --git-dir="$dir" for-each-ref --format='%(refname:short)' \ + refs/tags + return + fi +} + +# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments +# presence of 2nd argument means use the guess heuristic employed +# by checkout for tracking branches +__git_refs () +{ + local i hash dir="$(__gitdir "${1-}")" track="${2-}" + local format refs pfx + if [ -d "$dir" ]; then + case "$cur" in + refs|refs/*) + format="refname" + refs="${cur%/*}" + track="" + ;; + *) + [[ "$cur" == ^* ]] && pfx="^" + for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do + if [ -e "$dir/$i" ]; then echo $pfx$i; fi + done + format="refname:short" + refs="refs/tags refs/heads refs/remotes" + ;; + esac + git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \ + $refs + if [ -n "$track" ]; then + # employ the heuristic used by git checkout + # Try to find a remote branch that matches the completion word + # but only output if the branch name is unique + local ref entry + git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \ + "refs/remotes/" | \ + while read -r entry; do + eval "$entry" + ref="${ref#*/}" + if [[ "$ref" == "$cur"* ]]; then + echo "$ref" + fi + done | sort | uniq -u + fi + return + fi + case "$cur" in + refs|refs/*) + git ls-remote "$dir" "$cur*" 2>/dev/null | \ + while read -r hash i; do + case "$i" in + *^{}) ;; + *) echo "$i" ;; + esac + done + ;; + *) + echo "HEAD" + git for-each-ref --format="%(refname:short)" -- \ + "refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##" + ;; + esac +} + +# __git_refs2 requires 1 argument (to pass to __git_refs) +__git_refs2 () +{ + local i + for i in $(__git_refs "$1"); do + echo "$i:$i" + done +} + +# __git_refs_remotes requires 1 argument (to pass to ls-remote) +__git_refs_remotes () +{ + local i hash + git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \ + while read -r hash i; do + echo "$i:refs/remotes/$1/${i#refs/heads/}" + done +} + +__git_remotes () +{ + local d="$(__gitdir)" + test -d "$d/remotes" && ls -1 "$d/remotes" + git --git-dir="$d" remote +} + +__git_list_merge_strategies () +{ + git merge -s help 2>&1 | + sed -n -e '/[Aa]vailable strategies are: /,/^$/{ + s/\.$// + s/.*:// + s/^[ ]*// + s/[ ]*$// + p + }' +} + +__git_merge_strategies= +# 'git merge -s help' (and thus detection of the merge strategy +# list) fails, unfortunately, if run outside of any git working +# tree. __git_merge_strategies is set to the empty string in +# that case, and the detection will be repeated the next time it +# is needed. +__git_compute_merge_strategies () +{ + test -n "$__git_merge_strategies" || + __git_merge_strategies=$(__git_list_merge_strategies) +} + +__git_complete_revlist_file () +{ + local pfx ls ref cur_="$cur" + case "$cur_" in + *..?*:*) + return + ;; + ?*:*) + ref="${cur_%%:*}" + cur_="${cur_#*:}" + case "$cur_" in + ?*/*) + pfx="${cur_%/*}" + cur_="${cur_##*/}" + ls="$ref:$pfx" + pfx="$pfx/" + ;; + *) + ls="$ref" + ;; + esac + + case "$COMP_WORDBREAKS" in + *:*) : great ;; + *) pfx="$ref:$pfx" ;; + esac + + __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \ + | sed '/^100... blob /{ + s,^.* ,, + s,$, , + } + /^120000 blob /{ + s,^.* ,, + s,$, , + } + /^040000 tree /{ + s,^.* ,, + s,$,/, + } + s/^.* //')" \ + "$pfx" "$cur_" "" + ;; + *...*) + pfx="${cur_%...*}..." + cur_="${cur_#*...}" + __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" + ;; + *..*) + pfx="${cur_%..*}.." + cur_="${cur_#*..}" + __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" + ;; + *) + __gitcomp_nl "$(__git_refs)" + ;; + esac +} + + +# __git_complete_index_file requires 1 argument: +# 1: the options to pass to ls-file +# +# The exception is --committable, which finds the files appropriate commit. +__git_complete_index_file () +{ + local pfx="" cur_="$cur" + + case "$cur_" in + ?*/*) + pfx="${cur_%/*}" + cur_="${cur_##*/}" + pfx="${pfx}/" + ;; + esac + + __gitcomp_file "$(__git_index_files "$1" ${pfx:+"$pfx"})" "$pfx" "$cur_" +} + +__git_complete_file () +{ + __git_complete_revlist_file +} + +__git_complete_revlist () +{ + __git_complete_revlist_file +} + +__git_complete_remote_or_refspec () +{ + local cur_="$cur" cmd="${words[1]}" + local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 + if [ "$cmd" = "remote" ]; then + ((c++)) + fi + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;; + --all) + case "$cmd" in + push) no_complete_refspec=1 ;; + fetch) + return + ;; + *) ;; + esac + ;; + -*) ;; + *) remote="$i"; break ;; + esac + ((c++)) + done + if [ -z "$remote" ]; then + __gitcomp_nl "$(__git_remotes)" + return + fi + if [ $no_complete_refspec = 1 ]; then + return + fi + [ "$remote" = "." ] && remote= + case "$cur_" in + *:*) + case "$COMP_WORDBREAKS" in + *:*) : great ;; + *) pfx="${cur_%%:*}:" ;; + esac + cur_="${cur_#*:}" + lhs=0 + ;; + +*) + pfx="+" + cur_="${cur_#+}" + ;; + esac + case "$cmd" in + fetch) + if [ $lhs = 1 ]; then + __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_" + else + __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" + fi + ;; + pull|remote) + if [ $lhs = 1 ]; then + __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_" + else + __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" + fi + ;; + push) + if [ $lhs = 1 ]; then + __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" + else + __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_" + fi + ;; + esac +} + +__git_complete_strategy () +{ + __git_compute_merge_strategies + case "$prev" in + -s|--strategy) + __gitcomp "$__git_merge_strategies" + return 0 + esac + case "$cur" in + --strategy=*) + __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}" + return 0 + ;; + esac + return 1 +} + +__git_commands () { + if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}" + then + printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}" + else + git help -a|egrep '^ [a-zA-Z0-9]' + fi +} + +__git_list_all_commands () +{ + local i IFS=" "$'\n' + for i in $(__git_commands) + do + case $i in + *--*) : helper pattern;; + *) echo $i;; + esac + done +} + +__git_all_commands= +__git_compute_all_commands () +{ + test -n "$__git_all_commands" || + __git_all_commands=$(__git_list_all_commands) +} + +__git_list_porcelain_commands () +{ + local i IFS=" "$'\n' + __git_compute_all_commands + for i in $__git_all_commands + do + case $i in + *--*) : helper pattern;; + applymbox) : ask gittus;; + applypatch) : ask gittus;; + archimport) : import;; + cat-file) : plumbing;; + check-attr) : plumbing;; + check-ignore) : plumbing;; + check-mailmap) : plumbing;; + check-ref-format) : plumbing;; + checkout-index) : plumbing;; + column) : internal helper;; + commit-tree) : plumbing;; + count-objects) : infrequent;; + credential) : credentials;; + credential-*) : credentials helper;; + cvsexportcommit) : export;; + cvsimport) : import;; + cvsserver) : daemon;; + daemon) : daemon;; + diff-files) : plumbing;; + diff-index) : plumbing;; + diff-tree) : plumbing;; + fast-import) : import;; + fast-export) : export;; + fsck-objects) : plumbing;; + fetch-pack) : plumbing;; + fmt-merge-msg) : plumbing;; + for-each-ref) : plumbing;; + hash-object) : plumbing;; + http-*) : transport;; + index-pack) : plumbing;; + init-db) : deprecated;; + local-fetch) : plumbing;; + ls-files) : plumbing;; + ls-remote) : plumbing;; + ls-tree) : plumbing;; + mailinfo) : plumbing;; + mailsplit) : plumbing;; + merge-*) : plumbing;; + mktree) : plumbing;; + mktag) : plumbing;; + pack-objects) : plumbing;; + pack-redundant) : plumbing;; + pack-refs) : plumbing;; + parse-remote) : plumbing;; + patch-id) : plumbing;; + prune) : plumbing;; + prune-packed) : plumbing;; + quiltimport) : import;; + read-tree) : plumbing;; + receive-pack) : plumbing;; + remote-*) : transport;; + rerere) : plumbing;; + rev-list) : plumbing;; + rev-parse) : plumbing;; + runstatus) : plumbing;; + sh-setup) : internal;; + shell) : daemon;; + show-ref) : plumbing;; + send-pack) : plumbing;; + show-index) : plumbing;; + ssh-*) : transport;; + stripspace) : plumbing;; + symbolic-ref) : plumbing;; + unpack-file) : plumbing;; + unpack-objects) : plumbing;; + update-index) : plumbing;; + update-ref) : plumbing;; + update-server-info) : daemon;; + upload-archive) : plumbing;; + upload-pack) : plumbing;; + write-tree) : plumbing;; + var) : infrequent;; + verify-pack) : infrequent;; + verify-tag) : plumbing;; + *) echo $i;; + esac + done +} + +__git_porcelain_commands= +__git_compute_porcelain_commands () +{ + test -n "$__git_porcelain_commands" || + __git_porcelain_commands=$(__git_list_porcelain_commands) +} + +# Lists all set config variables starting with the given section prefix, +# with the prefix removed. +__git_get_config_variables () +{ + local section="$1" i IFS=$'\n' + for i in $(git --git-dir="$(__gitdir)" config --name-only --get-regexp "^$section\..*" 2>/dev/null); do + echo "${i#$section.}" + done +} + +__git_pretty_aliases () +{ + __git_get_config_variables "pretty" +} + +__git_aliases () +{ + __git_get_config_variables "alias" +} + +# __git_aliased_command requires 1 argument +__git_aliased_command () +{ + local word cmdline=$(git --git-dir="$(__gitdir)" \ + config --get "alias.$1") + for word in $cmdline; do + case "$word" in + \!gitk|gitk) + echo "gitk" + return + ;; + \!*) : shell command alias ;; + -*) : option ;; + *=*) : setting env ;; + git) : git itself ;; + \(\)) : skip parens of shell function definition ;; + {) : skip start of shell helper function ;; + :) : skip null command ;; + \'*) : skip opening quote after sh -c ;; + *) + echo "$word" + return + esac + done +} + +# __git_find_on_cmdline requires 1 argument +__git_find_on_cmdline () +{ + local word subcommand c=1 + while [ $c -lt $cword ]; do + word="${words[c]}" + for subcommand in $1; do + if [ "$subcommand" = "$word" ]; then + echo "$subcommand" + return + fi + done + ((c++)) + done +} + +# Echo the value of an option set on the command line or config +# +# $1: short option name +# $2: long option name including = +# $3: list of possible values +# $4: config string (optional) +# +# example: +# result="$(__git_get_option_value "-d" "--do-something=" \ +# "yes no" "core.doSomething")" +# +# result is then either empty (no option set) or "yes" or "no" +# +# __git_get_option_value requires 3 arguments +__git_get_option_value () +{ + local c short_opt long_opt val + local result= values config_key word + + short_opt="$1" + long_opt="$2" + values="$3" + config_key="$4" + + ((c = $cword - 1)) + while [ $c -ge 0 ]; do + word="${words[c]}" + for val in $values; do + if [ "$short_opt$val" = "$word" ] || + [ "$long_opt$val" = "$word" ]; then + result="$val" + break 2 + fi + done + ((c--)) + done + + if [ -n "$config_key" ] && [ -z "$result" ]; then + result="$(git --git-dir="$(__gitdir)" config "$config_key")" + fi + + echo "$result" +} + +__git_has_doubledash () +{ + local c=1 + while [ $c -lt $cword ]; do + if [ "--" = "${words[c]}" ]; then + return 0 + fi + ((c++)) + done + return 1 +} + +# Try to count non option arguments passed on the command line for the +# specified git command. +# When options are used, it is necessary to use the special -- option to +# tell the implementation were non option arguments begin. +# XXX this can not be improved, since options can appear everywhere, as +# an example: +# git mv x -n y +# +# __git_count_arguments requires 1 argument: the git command executed. +__git_count_arguments () +{ + local word i c=0 + + # Skip "git" (first argument) + for ((i=1; i < ${#words[@]}; i++)); do + word="${words[i]}" + + case "$word" in + --) + # Good; we can assume that the following are only non + # option arguments. + ((c = 0)) + ;; + "$1") + # Skip the specified git command and discard git + # main options + ((c = 0)) + ;; + ?*) + ((c++)) + ;; + esac + done + + printf "%d" $c +} + +__git_whitespacelist="nowarn warn error error-all fix" + +_git_am () +{ + local dir="$(__gitdir)" + if [ -d "$dir"/rebase-apply ]; then + __gitcomp "--skip --continue --resolved --abort" + return + fi + case "$cur" in + --whitespace=*) + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" + return + ;; + --*) + __gitcomp " + --3way --committer-date-is-author-date --ignore-date + --ignore-whitespace --ignore-space-change + --interactive --keep --no-utf8 --signoff --utf8 + --whitespace= --scissors + " + return + esac +} + +_git_apply () +{ + case "$cur" in + --whitespace=*) + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" + return + ;; + --*) + __gitcomp " + --stat --numstat --summary --check --index + --cached --index-info --reverse --reject --unidiff-zero + --apply --no-add --exclude= + --ignore-whitespace --ignore-space-change + --whitespace= --inaccurate-eof --verbose + " + return + esac +} + +_git_add () +{ + case "$cur" in + --*) + __gitcomp " + --interactive --refresh --patch --update --dry-run + --ignore-errors --intent-to-add + " + return + esac + + # XXX should we check for --update and --all options ? + __git_complete_index_file "--others --modified --directory --no-empty-directory" +} + +_git_archive () +{ + case "$cur" in + --format=*) + __gitcomp "$(git archive --list)" "" "${cur##--format=}" + return + ;; + --remote=*) + __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}" + return + ;; + --*) + __gitcomp " + --format= --list --verbose + --prefix= --remote= --exec= + " + return + ;; + esac + __git_complete_file +} + +_git_bisect () +{ + __git_has_doubledash && return + + local subcommands="start bad good skip reset visualize replay log run" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + if [ -f "$(__gitdir)"/BISECT_START ]; then + __gitcomp "$subcommands" + else + __gitcomp "replay start" + fi + return + fi + + case "$subcommand" in + bad|good|reset|skip|start) + __gitcomp_nl "$(__git_refs)" + ;; + *) + ;; + esac +} + +_git_branch () +{ + local i c=1 only_local_ref="n" has_r="n" + + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + -d|--delete|-m|--move) only_local_ref="y" ;; + -r|--remotes) has_r="y" ;; + esac + ((c++)) + done + + case "$cur" in + --set-upstream-to=*) + __gitcomp_nl "$(__git_refs)" "" "${cur##--set-upstream-to=}" + ;; + --*) + __gitcomp " + --color --no-color --verbose --abbrev= --no-abbrev + --track --no-track --contains --merged --no-merged + --set-upstream-to= --edit-description --list + --unset-upstream --delete --move --remotes + " + ;; + *) + if [ $only_local_ref = "y" -a $has_r = "n" ]; then + __gitcomp_nl "$(__git_heads)" + else + __gitcomp_nl "$(__git_refs)" + fi + ;; + esac +} + +_git_bundle () +{ + local cmd="${words[2]}" + case "$cword" in + 2) + __gitcomp "create list-heads verify unbundle" + ;; + 3) + # looking for a file + ;; + *) + case "$cmd" in + create) + __git_complete_revlist + ;; + esac + ;; + esac +} + +_git_checkout () +{ + __git_has_doubledash && return + + case "$cur" in + --conflict=*) + __gitcomp "diff3 merge" "" "${cur##--conflict=}" + ;; + --*) + __gitcomp " + --quiet --ours --theirs --track --no-track --merge + --conflict= --orphan --patch + " + ;; + *) + # check if --track, --no-track, or --no-guess was specified + # if so, disable DWIM mode + local flags="--track --no-track --no-guess" track=1 + if [ -n "$(__git_find_on_cmdline "$flags")" ]; then + track='' + fi + __gitcomp_nl "$(__git_refs '' $track)" + ;; + esac +} + +_git_cherry () +{ + __gitcomp_nl "$(__git_refs)" +} + +_git_cherry_pick () +{ + local dir="$(__gitdir)" + if [ -f "$dir"/CHERRY_PICK_HEAD ]; then + __gitcomp "--continue --quit --abort" + return + fi + case "$cur" in + --*) + __gitcomp "--edit --no-commit --signoff --strategy= --mainline" + ;; + *) + __gitcomp_nl "$(__git_refs)" + ;; + esac +} + +_git_clean () +{ + case "$cur" in + --*) + __gitcomp "--dry-run --quiet" + return + ;; + esac + + # XXX should we check for -x option ? + __git_complete_index_file "--others --directory" +} + +_git_clone () +{ + case "$cur" in + --*) + __gitcomp " + --local + --no-hardlinks + --shared + --reference + --quiet + --no-checkout + --bare + --mirror + --origin + --upload-pack + --template= + --depth + --single-branch + --branch + --recurse-submodules + " + return + ;; + esac +} + +__git_untracked_file_modes="all no normal" + +_git_commit () +{ + case "$prev" in + -c|-C) + __gitcomp_nl "$(__git_refs)" "" "${cur}" + return + ;; + esac + + case "$cur" in + --cleanup=*) + __gitcomp "default scissors strip verbatim whitespace + " "" "${cur##--cleanup=}" + return + ;; + --reuse-message=*|--reedit-message=*|\ + --fixup=*|--squash=*) + __gitcomp_nl "$(__git_refs)" "" "${cur#*=}" + return + ;; + --untracked-files=*) + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" + return + ;; + --*) + __gitcomp " + --all --author= --signoff --verify --no-verify + --edit --no-edit + --amend --include --only --interactive + --dry-run --reuse-message= --reedit-message= + --reset-author --file= --message= --template= + --cleanup= --untracked-files --untracked-files= + --verbose --quiet --fixup= --squash= + " + return + esac + + if git rev-parse --verify --quiet HEAD >/dev/null; then + __git_complete_index_file "--committable" + else + # This is the first commit + __git_complete_index_file "--cached" + fi +} + +_git_describe () +{ + case "$cur" in + --*) + __gitcomp " + --all --tags --contains --abbrev= --candidates= + --exact-match --debug --long --match --always + " + return + esac + __gitcomp_nl "$(__git_refs)" +} + +__git_diff_algorithms="myers minimal patience histogram" + +__git_diff_submodule_formats="log short" + +__git_diff_common_options="--stat --numstat --shortstat --summary + --patch-with-stat --name-only --name-status --color + --no-color --color-words --no-renames --check + --full-index --binary --abbrev --diff-filter= + --find-copies-harder + --text --ignore-space-at-eol --ignore-space-change + --ignore-all-space --ignore-blank-lines --exit-code + --quiet --ext-diff --no-ext-diff + --no-prefix --src-prefix= --dst-prefix= + --inter-hunk-context= + --patience --histogram --minimal + --raw --word-diff --word-diff-regex= + --dirstat --dirstat= --dirstat-by-file + --dirstat-by-file= --cumulative + --diff-algorithm= + --submodule --submodule= +" + +_git_diff () +{ + __git_has_doubledash && return + + case "$cur" in + --diff-algorithm=*) + __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" + return + ;; + --submodule=*) + __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" + return + ;; + --*) + __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex + --base --ours --theirs --no-index + $__git_diff_common_options + " + return + ;; + esac + __git_complete_revlist_file +} + +__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff + tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare +" + +_git_difftool () +{ + __git_has_doubledash && return + + case "$cur" in + --tool=*) + __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}" + return + ;; + --*) + __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex + --base --ours --theirs + --no-renames --diff-filter= --find-copies-harder + --relative --ignore-submodules + --tool=" + return + ;; + esac + __git_complete_revlist_file +} + +__git_fetch_recurse_submodules="yes on-demand no" + +__git_fetch_options=" + --quiet --verbose --append --upload-pack --force --keep --depth= + --tags --no-tags --all --prune --dry-run --recurse-submodules= +" + +_git_fetch () +{ + case "$cur" in + --recurse-submodules=*) + __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" + return + ;; + --*) + __gitcomp "$__git_fetch_options" + return + ;; + esac + __git_complete_remote_or_refspec +} + +__git_format_patch_options=" + --stdout --attach --no-attach --thread --thread= --no-thread + --numbered --start-number --numbered-files --keep-subject --signoff + --signature --no-signature --in-reply-to= --cc= --full-index --binary + --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix= + --inline --suffix= --ignore-if-in-upstream --subject-prefix= + --output-directory --reroll-count --to= --quiet --notes +" + +_git_format_patch () +{ + case "$cur" in + --thread=*) + __gitcomp " + deep shallow + " "" "${cur##--thread=}" + return + ;; + --*) + __gitcomp "$__git_format_patch_options" + return + ;; + esac + __git_complete_revlist +} + +_git_fsck () +{ + case "$cur" in + --*) + __gitcomp " + --tags --root --unreachable --cache --no-reflogs --full + --strict --verbose --lost-found + " + return + ;; + esac +} + +_git_gc () +{ + case "$cur" in + --*) + __gitcomp "--prune --aggressive" + return + ;; + esac +} + +_git_gitk () +{ + _gitk +} + +__git_match_ctag() { + awk "/^${1//\//\\/}/ { print \$1 }" "$2" +} + +_git_grep () +{ + __git_has_doubledash && return + + case "$cur" in + --*) + __gitcomp " + --cached + --text --ignore-case --word-regexp --invert-match + --full-name --line-number + --extended-regexp --basic-regexp --fixed-strings + --perl-regexp + --threads + --files-with-matches --name-only + --files-without-match + --max-depth + --count + --and --or --not --all-match + " + return + ;; + esac + + case "$cword,$prev" in + 2,*|*,-*) + if test -r tags; then + __gitcomp_nl "$(__git_match_ctag "$cur" tags)" + return + fi + ;; + esac + + __gitcomp_nl "$(__git_refs)" +} + +_git_help () +{ + case "$cur" in + --*) + __gitcomp "--all --guides --info --man --web" + return + ;; + esac + __git_compute_all_commands + __gitcomp "$__git_all_commands $(__git_aliases) + attributes cli core-tutorial cvs-migration + diffcore everyday gitk glossary hooks ignore modules + namespaces repository-layout revisions tutorial tutorial-2 + workflows + " +} + +_git_init () +{ + case "$cur" in + --shared=*) + __gitcomp " + false true umask group all world everybody + " "" "${cur##--shared=}" + return + ;; + --*) + __gitcomp "--quiet --bare --template= --shared --shared=" + return + ;; + esac +} + +_git_ls_files () +{ + case "$cur" in + --*) + __gitcomp "--cached --deleted --modified --others --ignored + --stage --directory --no-empty-directory --unmerged + --killed --exclude= --exclude-from= + --exclude-per-directory= --exclude-standard + --error-unmatch --with-tree= --full-name + --abbrev --ignored --exclude-per-directory + " + return + ;; + esac + + # XXX ignore options like --modified and always suggest all cached + # files. + __git_complete_index_file "--cached" +} + +_git_ls_remote () +{ + __gitcomp_nl "$(__git_remotes)" +} + +_git_ls_tree () +{ + __git_complete_file +} + +# Options that go well for log, shortlog and gitk +__git_log_common_options=" + --not --all + --branches --tags --remotes + --first-parent --merges --no-merges + --max-count= + --max-age= --since= --after= + --min-age= --until= --before= + --min-parents= --max-parents= + --no-min-parents --no-max-parents +" +# Options that go well for log and gitk (not shortlog) +__git_log_gitk_options=" + --dense --sparse --full-history + --simplify-merges --simplify-by-decoration + --left-right --notes --no-notes +" +# Options that go well for log and shortlog (not gitk) +__git_log_shortlog_options=" + --author= --committer= --grep= + --all-match --invert-grep +" + +__git_log_pretty_formats="oneline short medium full fuller email raw format:" +__git_log_date_formats="relative iso8601 rfc2822 short local default raw" + +_git_log () +{ + __git_has_doubledash && return + + local g="$(git rev-parse --git-dir 2>/dev/null)" + local merge="" + if [ -f "$g/MERGE_HEAD" ]; then + merge="--merge" + fi + case "$cur" in + --pretty=*|--format=*) + __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) + " "" "${cur#*=}" + return + ;; + --date=*) + __gitcomp "$__git_log_date_formats" "" "${cur##--date=}" + return + ;; + --decorate=*) + __gitcomp "full short no" "" "${cur##--decorate=}" + return + ;; + --diff-algorithm=*) + __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" + return + ;; + --submodule=*) + __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" + return + ;; + --*) + __gitcomp " + $__git_log_common_options + $__git_log_shortlog_options + $__git_log_gitk_options + --root --topo-order --date-order --reverse + --follow --full-diff + --abbrev-commit --abbrev= + --relative-date --date= + --pretty= --format= --oneline + --show-signature + --cherry-mark + --cherry-pick + --graph + --decorate --decorate= + --walk-reflogs + --parents --children + $merge + $__git_diff_common_options + --pickaxe-all --pickaxe-regex + " + return + ;; + esac + __git_complete_revlist +} + +# Common merge options shared by git-merge(1) and git-pull(1). +__git_merge_options=" + --no-commit --no-stat --log --no-log --squash --strategy + --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit + --verify-signatures --no-verify-signatures --gpg-sign + --quiet --verbose --progress --no-progress +" + +_git_merge () +{ + __git_complete_strategy && return + + case "$cur" in + --*) + __gitcomp "$__git_merge_options + --rerere-autoupdate --no-rerere-autoupdate --abort" + return + esac + __gitcomp_nl "$(__git_refs)" +} + +_git_mergetool () +{ + case "$cur" in + --tool=*) + __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}" + return + ;; + --*) + __gitcomp "--tool=" + return + ;; + esac +} + +_git_merge_base () +{ + case "$cur" in + --*) + __gitcomp "--octopus --independent --is-ancestor --fork-point" + return + ;; + esac + __gitcomp_nl "$(__git_refs)" +} + +_git_mv () +{ + case "$cur" in + --*) + __gitcomp "--dry-run" + return + ;; + esac + + if [ $(__git_count_arguments "mv") -gt 0 ]; then + # We need to show both cached and untracked files (including + # empty directories) since this may not be the last argument. + __git_complete_index_file "--cached --others --directory" + else + __git_complete_index_file "--cached" + fi +} + +_git_name_rev () +{ + __gitcomp "--tags --all --stdin" +} + +_git_notes () +{ + local subcommands='add append copy edit list prune remove show' + local subcommand="$(__git_find_on_cmdline "$subcommands")" + + case "$subcommand,$cur" in + ,--*) + __gitcomp '--ref' + ;; + ,*) + case "$prev" in + --ref) + __gitcomp_nl "$(__git_refs)" + ;; + *) + __gitcomp "$subcommands --ref" + ;; + esac + ;; + add,--reuse-message=*|append,--reuse-message=*|\ + add,--reedit-message=*|append,--reedit-message=*) + __gitcomp_nl "$(__git_refs)" "" "${cur#*=}" + ;; + add,--*|append,--*) + __gitcomp '--file= --message= --reedit-message= + --reuse-message=' + ;; + copy,--*) + __gitcomp '--stdin' + ;; + prune,--*) + __gitcomp '--dry-run --verbose' + ;; + prune,*) + ;; + *) + case "$prev" in + -m|-F) + ;; + *) + __gitcomp_nl "$(__git_refs)" + ;; + esac + ;; + esac +} + +_git_pull () +{ + __git_complete_strategy && return + + case "$cur" in + --recurse-submodules=*) + __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" + return + ;; + --*) + __gitcomp " + --rebase --no-rebase + $__git_merge_options + $__git_fetch_options + " + return + ;; + esac + __git_complete_remote_or_refspec +} + +__git_push_recurse_submodules="check on-demand" + +__git_complete_force_with_lease () +{ + local cur_=$1 + + case "$cur_" in + --*=) + ;; + *:*) + __gitcomp_nl "$(__git_refs)" "" "${cur_#*:}" + ;; + *) + __gitcomp_nl "$(__git_refs)" "" "$cur_" + ;; + esac +} + +_git_push () +{ + case "$prev" in + --repo) + __gitcomp_nl "$(__git_remotes)" + return + ;; + --recurse-submodules) + __gitcomp "$__git_push_recurse_submodules" + return + ;; + esac + case "$cur" in + --repo=*) + __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}" + return + ;; + --recurse-submodules=*) + __gitcomp "$__git_push_recurse_submodules" "" "${cur##--recurse-submodules=}" + return + ;; + --force-with-lease=*) + __git_complete_force_with_lease "${cur##--force-with-lease=}" + return + ;; + --*) + __gitcomp " + --all --mirror --tags --dry-run --force --verbose + --quiet --prune --delete --follow-tags + --receive-pack= --repo= --set-upstream + --force-with-lease --force-with-lease= --recurse-submodules= + " + return + ;; + esac + __git_complete_remote_or_refspec +} + +_git_rebase () +{ + local dir="$(__gitdir)" + if [ -f "$dir"/rebase-merge/interactive ]; then + __gitcomp "--continue --skip --abort --edit-todo" + return + elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then + __gitcomp "--continue --skip --abort" + return + fi + __git_complete_strategy && return + case "$cur" in + --whitespace=*) + __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" + return + ;; + --*) + __gitcomp " + --onto --merge --strategy --interactive + --preserve-merges --stat --no-stat + --committer-date-is-author-date --ignore-date + --ignore-whitespace --whitespace= + --autosquash --no-autosquash + --fork-point --no-fork-point + --autostash --no-autostash + --verify --no-verify + --keep-empty --root --force-rebase --no-ff + --exec + " + + return + esac + __gitcomp_nl "$(__git_refs)" +} + +_git_reflog () +{ + local subcommands="show delete expire" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + else + __gitcomp_nl "$(__git_refs)" + fi +} + +__git_send_email_confirm_options="always never auto cc compose" +__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" + +_git_send_email () +{ + case "$prev" in + --to|--cc|--bcc|--from) + __gitcomp " + $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null) + " + return + ;; + esac + + case "$cur" in + --confirm=*) + __gitcomp " + $__git_send_email_confirm_options + " "" "${cur##--confirm=}" + return + ;; + --suppress-cc=*) + __gitcomp " + $__git_send_email_suppresscc_options + " "" "${cur##--suppress-cc=}" + + return + ;; + --smtp-encryption=*) + __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}" + return + ;; + --thread=*) + __gitcomp " + deep shallow + " "" "${cur##--thread=}" + return + ;; + --to=*|--cc=*|--bcc=*|--from=*) + __gitcomp " + $(git --git-dir="$(__gitdir)" send-email --dump-aliases 2>/dev/null) + " "" "${cur#--*=}" + return + ;; + --*) + __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to + --compose --confirm= --dry-run --envelope-sender + --from --identity + --in-reply-to --no-chain-reply-to --no-signed-off-by-cc + --no-suppress-from --no-thread --quiet + --signed-off-by-cc --smtp-pass --smtp-server + --smtp-server-port --smtp-encryption= --smtp-user + --subject --suppress-cc= --suppress-from --thread --to + --validate --no-validate + $__git_format_patch_options" + return + ;; + esac + __git_complete_revlist +} + +_git_stage () +{ + _git_add +} + +_git_status () +{ + local complete_opt + local untracked_state + + case "$cur" in + --ignore-submodules=*) + __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}" + return + ;; + --untracked-files=*) + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" + return + ;; + --column=*) + __gitcomp " + always never auto column row plain dense nodense + " "" "${cur##--column=}" + return + ;; + --*) + __gitcomp " + --short --branch --porcelain --long --verbose + --untracked-files= --ignore-submodules= --ignored + --column= --no-column + " + return + ;; + esac + + untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \ + "$__git_untracked_file_modes" "status.showUntrackedFiles")" + + case "$untracked_state" in + no) + # --ignored option does not matter + complete_opt= + ;; + all|normal|*) + complete_opt="--cached --directory --no-empty-directory --others" + + if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then + complete_opt="$complete_opt --ignored --exclude=*" + fi + ;; + esac + + __git_complete_index_file "$complete_opt" +} + +__git_config_get_set_variables () +{ + local prevword word config_file= c=$cword + while [ $c -gt 1 ]; do + word="${words[c]}" + case "$word" in + --system|--global|--local|--file=*) + config_file="$word" + break + ;; + -f|--file) + config_file="$word $prevword" + break + ;; + esac + prevword=$word + c=$((--c)) + done + + git --git-dir="$(__gitdir)" config $config_file --name-only --list 2>/dev/null +} + +_git_config () +{ + case "$prev" in + branch.*.remote|branch.*.pushremote) + __gitcomp_nl "$(__git_remotes)" + return + ;; + branch.*.merge) + __gitcomp_nl "$(__git_refs)" + return + ;; + branch.*.rebase) + __gitcomp "false true preserve interactive" + return + ;; + remote.pushdefault) + __gitcomp_nl "$(__git_remotes)" + return + ;; + remote.*.fetch) + local remote="${prev#remote.}" + remote="${remote%.fetch}" + if [ -z "$cur" ]; then + __gitcomp_nl "refs/heads/" "" "" "" + return + fi + __gitcomp_nl "$(__git_refs_remotes "$remote")" + return + ;; + remote.*.push) + local remote="${prev#remote.}" + remote="${remote%.push}" + __gitcomp_nl "$(git --git-dir="$(__gitdir)" \ + for-each-ref --format='%(refname):%(refname)' \ + refs/heads)" + return + ;; + pull.twohead|pull.octopus) + __git_compute_merge_strategies + __gitcomp "$__git_merge_strategies" + return + ;; + color.branch|color.diff|color.interactive|\ + color.showbranch|color.status|color.ui) + __gitcomp "always never auto" + return + ;; + color.pager) + __gitcomp "false true" + return + ;; + color.*.*) + __gitcomp " + normal black red green yellow blue magenta cyan white + bold dim ul blink reverse + " + return + ;; + diff.submodule) + __gitcomp "log short" + return + ;; + help.format) + __gitcomp "man info web html" + return + ;; + log.date) + __gitcomp "$__git_log_date_formats" + return + ;; + sendemail.aliasesfiletype) + __gitcomp "mutt mailrc pine elm gnus" + return + ;; + sendemail.confirm) + __gitcomp "$__git_send_email_confirm_options" + return + ;; + sendemail.suppresscc) + __gitcomp "$__git_send_email_suppresscc_options" + return + ;; + sendemail.transferencoding) + __gitcomp "7bit 8bit quoted-printable base64" + return + ;; + --get|--get-all|--unset|--unset-all) + __gitcomp_nl "$(__git_config_get_set_variables)" + return + ;; + *.*) + return + ;; + esac + case "$cur" in + --*) + __gitcomp " + --system --global --local --file= + --list --replace-all + --get --get-all --get-regexp + --add --unset --unset-all + --remove-section --rename-section + --name-only + " + return + ;; + branch.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_" + return + ;; + branch.*) + local pfx="${cur%.*}." cur_="${cur#*.}" + __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "." + __gitcomp_nl_append $'autosetupmerge\nautosetuprebase\n' "$pfx" "$cur_" + return + ;; + guitool.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp " + argprompt cmd confirm needsfile noconsole norescan + prompt revprompt revunmerged title + " "$pfx" "$cur_" + return + ;; + difftool.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp "cmd path" "$pfx" "$cur_" + return + ;; + man.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp "cmd path" "$pfx" "$cur_" + return + ;; + mergetool.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp "cmd path trustExitCode" "$pfx" "$cur_" + return + ;; + pager.*) + local pfx="${cur%.*}." cur_="${cur#*.}" + __git_compute_all_commands + __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_" + return + ;; + remote.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp " + url proxy fetch push mirror skipDefaultUpdate + receivepack uploadpack tagopt pushurl + " "$pfx" "$cur_" + return + ;; + remote.*) + local pfx="${cur%.*}." cur_="${cur#*.}" + __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "." + __gitcomp_nl_append "pushdefault" "$pfx" "$cur_" + return + ;; + url.*.*) + local pfx="${cur%.*}." cur_="${cur##*.}" + __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_" + return + ;; + esac + __gitcomp " + add.ignoreErrors + advice.commitBeforeMerge + advice.detachedHead + advice.implicitIdentity + advice.pushNonFastForward + advice.resolveConflict + advice.statusHints + alias. + am.keepcr + apply.ignorewhitespace + apply.whitespace + branch.autosetupmerge + branch.autosetuprebase + browser. + clean.requireForce + color.branch + color.branch.current + color.branch.local + color.branch.plain + color.branch.remote + color.decorate.HEAD + color.decorate.branch + color.decorate.remoteBranch + color.decorate.stash + color.decorate.tag + color.diff + color.diff.commit + color.diff.frag + color.diff.func + color.diff.meta + color.diff.new + color.diff.old + color.diff.plain + color.diff.whitespace + color.grep + color.grep.context + color.grep.filename + color.grep.function + color.grep.linenumber + color.grep.match + color.grep.selected + color.grep.separator + color.interactive + color.interactive.error + color.interactive.header + color.interactive.help + color.interactive.prompt + color.pager + color.showbranch + color.status + color.status.added + color.status.changed + color.status.header + color.status.nobranch + color.status.unmerged + color.status.untracked + color.status.updated + color.ui + commit.status + commit.template + core.abbrev + core.askpass + core.attributesfile + core.autocrlf + core.bare + core.bigFileThreshold + core.compression + core.createObject + core.deltaBaseCacheLimit + core.editor + core.eol + core.excludesfile + core.fileMode + core.fsyncobjectfiles + core.gitProxy + core.ignoreStat + core.ignorecase + core.logAllRefUpdates + core.loosecompression + core.notesRef + core.packedGitLimit + core.packedGitWindowSize + core.pager + core.preferSymlinkRefs + core.preloadindex + core.quotepath + core.repositoryFormatVersion + core.safecrlf + core.sharedRepository + core.sparseCheckout + core.symlinks + core.trustctime + core.untrackedCache + core.warnAmbiguousRefs + core.whitespace + core.worktree + diff.autorefreshindex + diff.external + diff.ignoreSubmodules + diff.mnemonicprefix + diff.noprefix + diff.renameLimit + diff.renames + diff.statGraphWidth + diff.submodule + diff.suppressBlankEmpty + diff.tool + diff.wordRegex + diff.algorithm + difftool. + difftool.prompt + fetch.recurseSubmodules + fetch.unpackLimit + format.attach + format.cc + format.coverLetter + format.from + format.headers + format.numbered + format.pretty + format.signature + format.signoff + format.subjectprefix + format.suffix + format.thread + format.to + gc. + gc.aggressiveWindow + gc.auto + gc.autopacklimit + gc.packrefs + gc.pruneexpire + gc.reflogexpire + gc.reflogexpireunreachable + gc.rerereresolved + gc.rerereunresolved + gitcvs.allbinary + gitcvs.commitmsgannotation + gitcvs.dbTableNamePrefix + gitcvs.dbdriver + gitcvs.dbname + gitcvs.dbpass + gitcvs.dbuser + gitcvs.enabled + gitcvs.logfile + gitcvs.usecrlfattr + guitool. + gui.blamehistoryctx + gui.commitmsgwidth + gui.copyblamethreshold + gui.diffcontext + gui.encoding + gui.fastcopyblame + gui.matchtrackingbranch + gui.newbranchtemplate + gui.pruneduringfetch + gui.spellingdictionary + gui.trustmtime + help.autocorrect + help.browser + help.format + http.lowSpeedLimit + http.lowSpeedTime + http.maxRequests + http.minSessions + http.noEPSV + http.postBuffer + http.proxy + http.sslCipherList + http.sslVersion + http.sslCAInfo + http.sslCAPath + http.sslCert + http.sslCertPasswordProtected + http.sslKey + http.sslVerify + http.useragent + i18n.commitEncoding + i18n.logOutputEncoding + imap.authMethod + imap.folder + imap.host + imap.pass + imap.port + imap.preformattedHTML + imap.sslverify + imap.tunnel + imap.user + init.templatedir + instaweb.browser + instaweb.httpd + instaweb.local + instaweb.modulepath + instaweb.port + interactive.singlekey + log.date + log.decorate + log.showroot + mailmap.file + man. + man.viewer + merge. + merge.conflictstyle + merge.log + merge.renameLimit + merge.renormalize + merge.stat + merge.tool + merge.verbosity + mergetool. + mergetool.keepBackup + mergetool.keepTemporaries + mergetool.prompt + notes.displayRef + notes.rewrite. + notes.rewrite.amend + notes.rewrite.rebase + notes.rewriteMode + notes.rewriteRef + pack.compression + pack.deltaCacheLimit + pack.deltaCacheSize + pack.depth + pack.indexVersion + pack.packSizeLimit + pack.threads + pack.window + pack.windowMemory + pager. + pretty. + pull.octopus + pull.twohead + push.default + push.followTags + rebase.autosquash + rebase.stat + receive.autogc + receive.denyCurrentBranch + receive.denyDeleteCurrent + receive.denyDeletes + receive.denyNonFastForwards + receive.fsckObjects + receive.unpackLimit + receive.updateserverinfo + remote.pushdefault + remotes. + repack.usedeltabaseoffset + rerere.autoupdate + rerere.enabled + sendemail. + sendemail.aliasesfile + sendemail.aliasfiletype + sendemail.bcc + sendemail.cc + sendemail.cccmd + sendemail.chainreplyto + sendemail.confirm + sendemail.envelopesender + sendemail.from + sendemail.identity + sendemail.multiedit + sendemail.signedoffbycc + sendemail.smtpdomain + sendemail.smtpencryption + sendemail.smtppass + sendemail.smtpserver + sendemail.smtpserveroption + sendemail.smtpserverport + sendemail.smtpuser + sendemail.suppresscc + sendemail.suppressfrom + sendemail.thread + sendemail.to + sendemail.validate + showbranch.default + status.relativePaths + status.showUntrackedFiles + status.submodulesummary + submodule. + tar.umask + transfer.unpackLimit + url. + user.email + user.name + user.signingkey + web.browser + branch. remote. + " +} + +_git_remote () +{ + local subcommands="add rename remove set-head set-branches set-url show prune update" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + return + fi + + case "$subcommand" in + rename|remove|set-url|show|prune) + __gitcomp_nl "$(__git_remotes)" + ;; + set-head|set-branches) + __git_complete_remote_or_refspec + ;; + update) + __gitcomp "$(__git_get_config_variables "remotes")" + ;; + *) + ;; + esac +} + +_git_replace () +{ + __gitcomp_nl "$(__git_refs)" +} + +_git_reset () +{ + __git_has_doubledash && return + + case "$cur" in + --*) + __gitcomp "--merge --mixed --hard --soft --patch" + return + ;; + esac + __gitcomp_nl "$(__git_refs)" +} + +_git_revert () +{ + local dir="$(__gitdir)" + if [ -f "$dir"/REVERT_HEAD ]; then + __gitcomp "--continue --quit --abort" + return + fi + case "$cur" in + --*) + __gitcomp "--edit --mainline --no-edit --no-commit --signoff" + return + ;; + esac + __gitcomp_nl "$(__git_refs)" +} + +_git_rm () +{ + case "$cur" in + --*) + __gitcomp "--cached --dry-run --ignore-unmatch --quiet" + return + ;; + esac + + __git_complete_index_file "--cached" +} + +_git_shortlog () +{ + __git_has_doubledash && return + + case "$cur" in + --*) + __gitcomp " + $__git_log_common_options + $__git_log_shortlog_options + --numbered --summary + " + return + ;; + esac + __git_complete_revlist +} + +_git_show () +{ + __git_has_doubledash && return + + case "$cur" in + --pretty=*|--format=*) + __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases) + " "" "${cur#*=}" + return + ;; + --diff-algorithm=*) + __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" + return + ;; + --submodule=*) + __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" + return + ;; + --*) + __gitcomp "--pretty= --format= --abbrev-commit --oneline + --show-signature + $__git_diff_common_options + " + return + ;; + esac + __git_complete_revlist_file +} + +_git_show_branch () +{ + case "$cur" in + --*) + __gitcomp " + --all --remotes --topo-order --date-order --current --more= + --list --independent --merge-base --no-name + --color --no-color + --sha1-name --sparse --topics --reflog + " + return + ;; + esac + __git_complete_revlist +} + +_git_stash () +{ + local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked' + local subcommands='save list show apply clear drop pop create branch' + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + case "$cur" in + --*) + __gitcomp "$save_opts" + ;; + *) + if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then + __gitcomp "$subcommands" + fi + ;; + esac + else + case "$subcommand,$cur" in + save,--*) + __gitcomp "$save_opts" + ;; + apply,--*|pop,--*) + __gitcomp "--index --quiet" + ;; + drop,--*) + __gitcomp "--quiet" + ;; + show,--*|branch,--*) + ;; + branch,*) + if [ $cword -eq 3 ]; then + __gitcomp_nl "$(__git_refs)"; + else + __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ + | sed -n -e 's/:.*//p')" + fi + ;; + show,*|apply,*|drop,*|pop,*) + __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ + | sed -n -e 's/:.*//p')" + ;; + *) + ;; + esac + fi +} + +_git_submodule () +{ + __git_has_doubledash && return + + local subcommands="add status init deinit update summary foreach sync" + if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then + case "$cur" in + --*) + __gitcomp "--quiet --cached" + ;; + *) + __gitcomp "$subcommands" + ;; + esac + return + fi +} + +_git_svn () +{ + local subcommands=" + init fetch clone rebase dcommit log find-rev + set-tree commit-diff info create-ignore propget + proplist show-ignore show-externals branch tag blame + migrate mkdirs reset gc + " + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + else + local remote_opts="--username= --config-dir= --no-auth-cache" + local fc_opts=" + --follow-parent --authors-file= --repack= + --no-metadata --use-svm-props --use-svnsync-props + --log-window-size= --no-checkout --quiet + --repack-flags --use-log-author --localtime + --ignore-paths= --include-paths= $remote_opts + " + local init_opts=" + --template= --shared= --trunk= --tags= + --branches= --stdlayout --minimize-url + --no-metadata --use-svm-props --use-svnsync-props + --rewrite-root= --prefix= --use-log-author + --add-author-from $remote_opts + " + local cmt_opts=" + --edit --rmdir --find-copies-harder --copy-similarity= + " + + case "$subcommand,$cur" in + fetch,--*) + __gitcomp "--revision= --fetch-all $fc_opts" + ;; + clone,--*) + __gitcomp "--revision= $fc_opts $init_opts" + ;; + init,--*) + __gitcomp "$init_opts" + ;; + dcommit,--*) + __gitcomp " + --merge --strategy= --verbose --dry-run + --fetch-all --no-rebase --commit-url + --revision --interactive $cmt_opts $fc_opts + " + ;; + set-tree,--*) + __gitcomp "--stdin $cmt_opts $fc_opts" + ;; + create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\ + show-externals,--*|mkdirs,--*) + __gitcomp "--revision=" + ;; + log,--*) + __gitcomp " + --limit= --revision= --verbose --incremental + --oneline --show-commit --non-recursive + --authors-file= --color + " + ;; + rebase,--*) + __gitcomp " + --merge --verbose --strategy= --local + --fetch-all --dry-run $fc_opts + " + ;; + commit-diff,--*) + __gitcomp "--message= --file= --revision= $cmt_opts" + ;; + info,--*) + __gitcomp "--url" + ;; + branch,--*) + __gitcomp "--dry-run --message --tag" + ;; + tag,--*) + __gitcomp "--dry-run --message" + ;; + blame,--*) + __gitcomp "--git-format" + ;; + migrate,--*) + __gitcomp " + --config-dir= --ignore-paths= --minimize + --no-auth-cache --username= + " + ;; + reset,--*) + __gitcomp "--revision= --parent" + ;; + *) + ;; + esac + fi +} + +_git_tag () +{ + local i c=1 f=0 + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + -d|-v) + __gitcomp_nl "$(__git_tags)" + return + ;; + -f) + f=1 + ;; + esac + ((c++)) + done + + case "$prev" in + -m|-F) + ;; + -*|tag) + if [ $f = 1 ]; then + __gitcomp_nl "$(__git_tags)" + fi + ;; + *) + __gitcomp_nl "$(__git_refs)" + ;; + esac + + case "$cur" in + --*) + __gitcomp " + --list --delete --verify --annotate --message --file + --sign --cleanup --local-user --force --column --sort + --contains --points-at + " + ;; + esac +} + +_git_whatchanged () +{ + _git_log +} + +_git_worktree () +{ + local subcommands="add list lock prune unlock" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + else + case "$subcommand,$cur" in + add,--*) + __gitcomp "--detach" + ;; + list,--*) + __gitcomp "--porcelain" + ;; + lock,--*) + __gitcomp "--reason" + ;; + prune,--*) + __gitcomp "--dry-run --expire --verbose" + ;; + *) + ;; + esac + fi +} + +__git_main () +{ + local i c=1 command __git_dir + + while [ $c -lt $cword ]; do + i="${words[c]}" + case "$i" in + --git-dir=*) __git_dir="${i#--git-dir=}" ;; + --git-dir) ((c++)) ; __git_dir="${words[c]}" ;; + --bare) __git_dir="." ;; + --help) command="help"; break ;; + -c|--work-tree|--namespace) ((c++)) ;; + -*) ;; + *) command="$i"; break ;; + esac + ((c++)) + done + + if [ -z "$command" ]; then + case "$cur" in + --*) __gitcomp " + --paginate + --no-pager + --git-dir= + --bare + --version + --exec-path + --exec-path= + --html-path + --man-path + --info-path + --work-tree= + --namespace= + --no-replace-objects + --help + " + ;; + *) __git_compute_porcelain_commands + __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;; + esac + return + fi + + local completion_func="_git_${command//-/_}" + declare -f $completion_func >/dev/null && $completion_func && return + + local expansion=$(__git_aliased_command "$command") + if [ -n "$expansion" ]; then + words[1]=$expansion + completion_func="_git_${expansion//-/_}" + declare -f $completion_func >/dev/null && $completion_func + fi +} + +__gitk_main () +{ + __git_has_doubledash && return + + local g="$(__gitdir)" + local merge="" + if [ -f "$g/MERGE_HEAD" ]; then + merge="--merge" + fi + case "$cur" in + --*) + __gitcomp " + $__git_log_common_options + $__git_log_gitk_options + $merge + " + return + ;; + esac + __git_complete_revlist +} + +__git_func_wrap () +{ + local cur words cword prev + _get_comp_words_by_ref -n =: cur words cword prev + $1 +} + +# Setup completion for certain functions defined above by setting common +# variables and workarounds. +# This is NOT a public function; use at your own risk. +__git_complete () +{ + local wrapper="__git_wrap${2}" + eval "$wrapper () { __git_func_wrap $2 ; }" + complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \ + || complete -o default -o nospace -F $wrapper $1 +} + +# wrapper for backwards compatibility +_git () +{ + __git_wrap__git_main +} + +# wrapper for backwards compatibility +_gitk () +{ + __git_wrap__gitk_main +} + +__git_complete git __git_main +__git_complete gitk __gitk_main + +# The following are necessary only for Cygwin, and only are needed +# when the user has tab-completed the executable name and consequently +# included the '.exe' suffix. +# +if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then +__git_complete git.exe __git_main +fi diff --git a/bash-git-prompt/.brew/bash-git-prompt.rb b/bash-git-prompt/.brew/bash-git-prompt.rb new file mode 100644 index 0000000..87c7cea --- /dev/null +++ b/bash-git-prompt/.brew/bash-git-prompt.rb @@ -0,0 +1,27 @@ +class BashGitPrompt < Formula + desc "Informative, fancy bash prompt for Git users" + homepage "https://github.com/magicmonty/bash-git-prompt" + url "https://github.com/magicmonty/bash-git-prompt/archive/2.6.1.tar.gz" + sha256 "d2e58eaaae521cbcf3758a38cbc9233ea2e24a47dd907e64cdb514f30bd7b9ed" + head "https://github.com/magicmonty/bash-git-prompt.git" + + bottle :unneeded + + def install + share.install "gitprompt.sh", "gitprompt.fish", "git-prompt-help.sh", + "gitstatus.py", "gitstatus.sh", "gitstatus_pre-1.7.10.sh", + "prompt-colors.sh" + + (share/"themes").install Dir["themes/*.bgptheme"], "themes/Custom.bgptemplate" + doc.install "README.md" + end + + def caveats; <<-EOS.undent + You should add the following to your .bashrc (or equivalent): + if [ -f "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" ]; then + GIT_PROMPT_THEME=Default + source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" + fi + EOS + end +end diff --git a/bash-git-prompt/INSTALL_RECEIPT.json b/bash-git-prompt/INSTALL_RECEIPT.json new file mode 100644 index 0000000..d19855d --- /dev/null +++ b/bash-git-prompt/INSTALL_RECEIPT.json @@ -0,0 +1 @@ +{"used_options":[],"unused_options":[],"built_as_bottle":false,"poured_from_bottle":false,"time":1476791353,"source_modified_time":1475782274,"HEAD":"0296439c832a915be9b73456c0c26bc6c79c271d","stdlib":null,"compiler":"clang","runtime_dependencies":[],"source":{"path":"/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/bash-git-prompt.rb","tap":"homebrew/core","spec":"stable","versions":{"stable":"2.6.1","devel":null,"head":"HEAD","version_scheme":0}}} \ No newline at end of file diff --git a/bash-git-prompt/LICENSE.txt b/bash-git-prompt/LICENSE.txt new file mode 100644 index 0000000..d9cf93e --- /dev/null +++ b/bash-git-prompt/LICENSE.txt @@ -0,0 +1,23 @@ +Copyright (c) 2016, Martin Gondermann +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/bash-git-prompt/share/doc/bash-git-prompt/README.md b/bash-git-prompt/share/doc/bash-git-prompt/README.md new file mode 100644 index 0000000..93df352 --- /dev/null +++ b/bash-git-prompt/share/doc/bash-git-prompt/README.md @@ -0,0 +1,359 @@ +# Informative git prompt for bash and fish + +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/magicmonty/bash-git-prompt?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +This prompt is a port of the "Informative git prompt for zsh" which you can +find [here](https://github.com/olivierverdier/zsh-git-prompt) + +A ``bash`` prompt that displays information about the current git repository. +In particular the branch name, difference with remote branch, number of files +staged, changed, etc. + +(an original idea from this [blog post][]). + +`gitstatus.sh` and `git-prompt-help.sh` added by [AKS](http://github.com/aks). + +# ATTENTION! Breaking changes! + +**If you use this prompt already, please update your `.git-prompt-colors.sh`, +if you have one. It now contains a function named `define_git_prompt_colors()` or `override_git_prompt_colors()`!** + +**Please see the ``Custom.bgptemplate`` in the ``themes`` subdirectory of the installation directory!** + +**You can now also use the function `override_git_prompt_colors()`. It should define the variable `GIT_PROMPT_THEME_NAME` +and call the function `reload_git_prompt_colors ` like follows:** + +```sh +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique + + # Place your overrides here + ... +} + +# load the theme +reload_git_prompt_colors "Custom" +``` + +The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme. + +--- + +**The variable `GIT_PROMPT_SHOW_LAST_COMMAND_INDICATOR` was replaced with a more general placeholder +named ``_LAST_COMMAND_INDICATOR_``, which is replaced by the state of the last executed command. It is now activated by default.** + +## Examples + +The prompt may look like the following: + +![Example prompt](gitprompt.png) + +* ``(master↑3|✚1)``: on branch ``master``, ahead of remote by 3 commits, 1 file changed but not staged +* ``(status|●2)``: on branch ``status``, 2 files staged +* ``(master|✚7…)``: on branch ``master``, 7 files changed, some files untracked +* ``(master|✖2✚3)``: on branch ``master``, 2 conflicts, 3 files changed +* ``(master|⚑2)``: on branch ``master``, 2 stash entries +* ``(experimental↓2↑3|✔)``: on branch ``experimental``; your branch has diverged by 3 commits, remote by 2 commits; the repository is otherwise clean +* ``(:70c2952|✔)``: not on any branch; parent commit has hash ``70c2952``; the repository is otherwise clean + +## Prompt Structure + +By default, the general appearance of the prompt is:: + + ( |) + +The symbols are as follows: + +- Local Status Symbols + - ``✔``: repository clean + - ``●n``: there are ``n`` staged files + - ``✖n``: there are ``n`` files with merge conflicts + - ``✚n``: there are ``n`` changed but *unstaged* files + - ``…n``: there are ``n`` untracked files + - ``⚑n``: there are ``n`` stash entries +- Upstream branch + - Shows the remote tracking branch + - Disabled by default + - Enable by setting GIT_PROMPT_SHOW_UPSTREAM=1 +- Branch Tracking Symbols + - ``↑n``: ahead of remote by ``n`` commits + - ``↓n``: behind remote by ``n`` commits + - ``↓m↑n``: branches diverged, other by ``m`` commits, yours by ``n`` commits + - ``L``: local branch, not remotely tracked +- Branch Symbol:
+ When the branch name starts with a colon ``:``, it means it's actually a hash, not a branch (although it should be pretty clear, unless you name your branches like hashes :-) + +## Installation + +### via [Homebrew][homebrew] on Mac OS X + +- Run `brew update` + +- Run `brew install bash-git-prompt` for the last stable release or `brew install --HEAD bash-git-prompt` for the + latest version directly from the repository + +- Now you can source the file in your `~/.bash_profile` as follows: + +```sh +if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then + source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" +fi +``` + +### via Git clone + +- Clone this repository to your home directory. + +```sh +cd ~ +git clone https://github.com/magicmonty/bash-git-prompt.git .bash-git-prompt --depth=1 +``` + +Add to the `~/.bashrc`: +``` + GIT_PROMPT_ONLY_IN_REPO=1 + source ~/.bash-git-prompt/gitprompt.sh +``` + +### All configs for .bashrc + +```sh + + # Set config variables first + GIT_PROMPT_ONLY_IN_REPO=1 + + # GIT_PROMPT_FETCH_REMOTE_STATUS=0 # uncomment to avoid fetching remote status + + # GIT_PROMPT_SHOW_UPSTREAM=1 # uncomment to show upstream tracking branch + # GIT_PROMPT_SHOW_UNTRACKED_FILES=all # can be no, normal or all; determines counting of untracked files + + # GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=0 # uncomment to avoid printing the number of changed files + + # GIT_PROMPT_STATUS_COMMAND=gitstatus_pre-1.7.10.sh # uncomment to support Git older than 1.7.10 + + # GIT_PROMPT_START=... # uncomment for custom prompt start sequence + # GIT_PROMPT_END=... # uncomment for custom prompt end sequence + + # as last entry source the gitprompt script + # GIT_PROMPT_THEME=Custom # use custom theme specified in file GIT_PROMPT_THEME_FILE (default ~/.git-prompt-colors.sh) + # GIT_PROMPT_THEME_FILE=~/.git-prompt-colors.sh + # GIT_PROMPT_THEME=Solarized # use theme optimized for solarized color scheme + source ~/.bash-git-prompt/gitprompt.sh +``` + +You can set the `GIT_PROMPT_SHOW_UNTRACKED_FILES` variable to `no` or `normal` to speed things up if you have lots of +untracked files in your repository. This can be the case for build systems that put their build artifacts in +the subdirectory structure of the git repository. + +- `cd` to a git repository and test it! + +#### Themes + +The most settings are now stored in theme files. To select a theme, set the variable `GIT_PROMPT_THEME` to the name +of the theme located in `/themes` without the extension `.bgptheme` like this: + +```sh +GIT_PROMPT_THEME=Solarized +``` + +If you set `GIT_PROMPT_THEME` to `Custom`, then the `.git-prompt-colors.sh` in the home directory will be used. +This file can now be generated with the command `git_prompt_make_custom_theme []`. If the name of +the base theme is ommitted or the theme file is not found, then the Default theme is used. If you have already a custom +`.git-prompt-colors.sh` in your home directory, a error message will be shown. + +You can display a list of available themes with `git_prompt_list_themes` (the current theme is highlighted) + +**If you omit the `GIT_PROMPT_THEME` variable, the Default theme is used or, if you have a custom `.git-prompt-colors.sh` +in your home directory, then the Custom theme is used.** + +##### Ubuntu Themes + +Ubuntu requires a bit more spacing for some characters so it has its own themes. + +These can be listed with `git_prompt_list_themes`: +```sh +git_prompt_list_themes | grep Ubuntu +``` + +##### Theme structure + +Please see the ``Custom.bgptemplate`` in the ``themes`` subdirectory of the installation directory! + +A theme consists of a function `override_git_prompt_colors()` which defines at least the variable `GIT_PROMPT_THEME_NAME` + with a unique theme identifier and a call to the function `reload_git_prompt_colors ` like follows: + +```sh +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" # needed for reload optimization, should be unique + + # Place your overrides here + ... +} + +# load the theme +reload_git_prompt_colors "Custom" +``` + +The advantage of this approach is, that you only need to specify the parts, that are different to the Default theme. + +If you use a custom theme in `.git-prompt-colors.sh`, please set `GIT_PROMPT_THEME_NAME="Custom"`. + +#### Further customizations + +- You can define `GIT_PROMPT_START` and `GIT_PROMPT_END` to tweak your prompt. + +- The default colors are defined within `prompt-colors.sh`, which is sourced by + `gitprompt.sh`. The colors used for various git status are defined in + `themes/Default.bgptheme`. Both of these files may be overridden by copying + them to $HOME with a `.` prefix. They can also be placed in `$HOME/lib` + without the leading `.`. The defaults are the original files in the + `~/.bash-git-prompt` directory. + +- You can use `GIT_PROMPT_START_USER`, `GIT_PROMPT_START_ROOT`, + `GIT_PROMPT_END_USER` and `GIT_PROMPT_END_ROOT` in your + `.git-prompt-colors.sh` to tweak your prompt. You can also override the start + and end of the prompt by setting `GIT_PROMPT_START` and `GIT_PROMPT_END` + before you source the `gitprompt.sh`. + +- The current git repo information is obtained by the script `gitstatus.sh`. +- You can define `prompt_callback` function to tweak your prompt dynamically. + +```sh +function prompt_callback { + if [ `jobs | wc -l` -ne 0 ]; then + echo -n " jobs:\j" + fi +} +``` + +- There are two helper functions that can be used within `prompt_callback`: + - `gp_set_window_title ` - sets the window title to the given string (should work for XTerm type terminals like in OS X or Ubuntu) + - `gp_truncate_pwd` - a function that returns the current PWD truncated to fit the current terminal width + +- If you want to show the git prompt only if you are in a git repository you + can set ``GIT_PROMPT_ONLY_IN_REPO=1`` before sourcing the gitprompt script + +- There is an indicator at the start of the prompt, which shows + the result of the last executed command by if you put the placeholder + `_LAST_COMMAND_INDICATOR_` in any of the prompt templates. + It is now by default activated in the default theme: + +```sh + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" +``` + + If you want to display the exit code too, you can use the placeholder + ``_LAST_COMMAND_STATE_`` in ``GIT_PROMPT_COMMAND_OK`` or ``GIT_PROMPT_COMMAND_FAIL`` + in your ``.git-prompt-colors.sh``: + +```sh +GIT_PROMPT_COMMAND_OK="${Green}✔ " # displays as ✔ +GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # displays as ✘-1 for exit code 1 +``` + +- It is now possible to disable the fetching of the remote repository either + globally by setting ``GIT_PROMPT_FETCH_REMOTE_STATUS=0`` in your .bashrc or + on a per repository basis by creating a file named ``.bash-git-rc`` with the + content ``FETCH_REMOTE_STATUS=0`` in the root of your git repository. + +- You can also ignore a repository completely by creating a file named ``.bash-git-rc`` with the + content ``GIT_PROMPT_IGNORE=1`` in the root of your git repository. + +- If you have a repository with many untracked files, the git prompt can become very slow. + You can disable the display of untracked files on a per repository basis by setting + ``GIT_PROMPT_SHOW_UNTRACKED_FILES=no`` in your ``.bash-git-rc`` in the repository or + by disabling it globally in your ``.bashrc`` + +- You can get help on the git prompt with the function ``git_prompt_help``. + Examples are available with ``git_prompt_examples``. + A list of all available named colors is available with `git_prompt_color_samples` + +- If you make any changes to any file that is sourced by `gitprompt.sh`, you + should run this command, so that the next prompt update will find all the + files and source them anew. + +```sh +git_prompt_reset +``` + +- You can disable/enable gitprompt by runnning: + +```sh +git_prompt_toggle +``` + + +**Enjoy!** + +## Alternative RPM Install + +This project ships an RPM spec to simplify installation on RHEL and +clones. If you wish to install from RPM, you may first build the RPM +from scratch by following this procedure: +* Clone this repository and tag the release with a version number + +````sh + git tag -a -m "Tag release 1.1" 1.1 +```` + +* Run the following command to create a tarball: + +````sh + VER=$(git describe) + # replace dash with underscore to work around + # rpmbuild does not allow dash in version string + VER=${VER//\-/_} + git archive \ + --format tar \ + --prefix=bash-git-prompt-${VER}/ \ + HEAD \ + -- *.sh \ + *.fish \ + README.md \ + themes \ + > bash-git-prompt-${VER}.tar + mkdir -p /tmp/bash-git-prompt-${VER} + sed "s/Version:.*/Version: ${VER}/" \ + bash-git-prompt.spec \ + > /tmp/bash-git-prompt-${VER}/bash-git-prompt.spec + OLDDIR=$(pwd) + cd /tmp + tar -uf ${OLDDIR}/bash-git-prompt-${VER}.tar \ + bash-git-prompt-${VER}/bash-git-prompt.spec + cd ${OLDDIR} + gzip bash-git-prompt-${VER}.tar + mv bash-git-prompt-${VER}.tar.gz bash-git-prompt-${VER}.tgz +```` + +* Log into an RHEL or clones host and run: + +````sh +rpmbuild -ta bash-git-prompt-xxx.tar.gz +```` +Then you may publish or install the rpm from "~/rpmbuild/RPMS/noarch". + +## License +This code is under the [BSD 2 Clause (NetBSD) license][license]. + +## Who Are You? +The current maintainer of the original bash-git-prompt is [Martin Gondermann][magicmonty]. + +## Contributing +If you want to contribute you can look for issues with the label [up-for-grabs][upforgrabs]. +Please leave a comment on the issue, that you want to fix it, so others know, the labels are "taken". + +Pull requests are welcome. I will check them and merge them, if I think they help the project. + +## Donations +I accept tips through [Flattr][flattr]. + +[![Flattr](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt) + +[blog post]: http://sebastiancelis.com/2009/nov/16/zsh-prompt-git-users/ +[tip]:https://www.gittip.com/magicmonty/ +[magicmonty]: http://blog.pagansoft.de/pages/about.html +[license]:https://github.com/magicmonty/bash-git-prompt/tree/master/LICENSE.txt +[flattr]: https://flattr.com/submit/auto?user_id=magicmonty&url=https%3A%2F%2Fgithub.com%2Fmagicmonty%2Fbash-git-prompt +[homebrew]: http://brew.sh/ +[upforgrabs]: https://github.com/magicmonty/bash-git-prompt/labels/up-for-grabs diff --git a/bash-git-prompt/share/git-prompt-help.sh b/bash-git-prompt/share/git-prompt-help.sh new file mode 100755 index 0000000..849753a --- /dev/null +++ b/bash-git-prompt/share/git-prompt-help.sh @@ -0,0 +1,76 @@ +#!/usr/bin/env bash +# git-prompt-help -- show useful info to help new users with the information +# being displayed. + +git_prompt_help() { + source ${__GIT_PROMPT_DIR}/prompt-colors.sh + source ${__GIT_PROMPT_DIR}/themes/Default.bgptheme + cat <${GIT_PROMPT_SEPARATOR}${GIT_PROMPT_SUFFIX} + +BRANCH is a branch name, such as "master" or "stage", a tag name, or commit +hash prefixed with ':'. + +TRACKING indicates how the local branch differs from the +remote branch. It can be empty, or one of: + + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${ResetColor} - ahead of remote by N commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - behind remote by M commits + ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}${GIT_PROMPT_SYMBOLS_AHEAD}N${GIT_PROMPT_SYMBOLS_BEHIND}M${ResetColor} - branches diverged, other by M commits, yours by N commits + +LOCALSTATUS is one of the following: + + ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean + ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files + ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N files with merge conflicts + ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files + ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files + ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries + +See "git_prompt_examples" for examples. +EOF +} + +help_git_prompt() { git_prompt_help ; } + +git_prompt_examples() { + cat < /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 + if [ -z "$__GIT_PROMPT_DIR" ]; then + local SOURCE="${BASH_SOURCE[0]}" + while [ -h "$SOURCE" ]; do + local DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" + done + __GIT_PROMPT_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + fi +} + +function echoc() { + echo -e "${1}$2${ResetColor}" | sed 's/\\\]//g' | sed 's/\\\[//g' +} + +function get_theme() { + local CUSTOM_THEME_FILE="${HOME}/.git-prompt-colors.sh" + if [[ ! (-z ${GIT_PROMPT_THEME_FILE} ) ]]; then + CUSTOM_THEME_FILE=$GIT_PROMPT_THEME_FILE + fi + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + + if [[ -z ${GIT_PROMPT_THEME} ]]; then + if [[ -r $CUSTOM_THEME_FILE ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + else + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE + fi + else + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + GIT_PROMPT_THEME="Custom" + __GIT_PROMPT_THEME_FILE=$CUSTOM_THEME_FILE + + if [[ ! (-r $__GIT_PROMPT_THEME_FILE) ]]; then + GIT_PROMPT_THEME="Default" + __GIT_PROMPT_THEME_FILE=$DEFAULT_THEME_FILE + fi + else + local theme="" + + # use default theme, if theme was not found + for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do + local basename=${themefile##*/} + if [[ "${basename%.bgptheme}" = "${GIT_PROMPT_THEME}" ]]; then + theme=$GIT_PROMPT_THEME + break + fi + done + + if [[ "${theme}" = "" ]]; then + GIT_PROMPT_THEME="Default" + fi + + __GIT_PROMPT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/${GIT_PROMPT_THEME}.bgptheme" + fi + fi +} + +function git_prompt_load_colors() { + if gp_set_file_var __PROMPT_COLORS_FILE prompt-colors.sh ; then + # outsource the color defs + source "$__PROMPT_COLORS_FILE" + else + echo 1>&2 "Cannot find prompt-colors.sh!" + fi +} + +function git_prompt_load_theme() { + get_theme + local DEFAULT_THEME_FILE="${__GIT_PROMPT_DIR}/themes/Default.bgptheme" + source "${DEFAULT_THEME_FILE}" + source "${__GIT_PROMPT_THEME_FILE}" +} + +function git_prompt_list_themes() { + git_prompt_load_colors + git_prompt_dir + get_theme + + for themefile in "${__GIT_PROMPT_DIR}/themes/"*.bgptheme; do + local basename=${themefile##*/} + local theme="${basename%.bgptheme}" + if [[ "${GIT_PROMPT_THEME}" = "${theme}" ]]; then + echoc ${Red} "*${theme}" + else + echo $theme + fi + done + + if [[ "${GIT_PROMPT_THEME}" = "Custom" ]]; then + echoc ${Magenta} "*Custom" + else + echoc ${Blue} "Custom" + fi +} + +function git_prompt_make_custom_theme() { + if [[ -r "${HOME}/.git-prompt-colors.sh" ]]; then + echoc ${Red} "You alread have created a custom theme!" + else + git_prompt_dir + + local base="Default" + if [[ -n $1 && -r "${__GIT_PROMPT_DIR}/themes/${1}.bgptheme" ]]; then + base=$1 + echoc ${Green} "Using theme ${Magenta}\"${base}\"${Green} as base theme!" + else + echoc ${Green} "Using theme ${Magenta}\"Default\"${Green} as base theme!" + fi + + if [[ "${base}" = "Custom" ]]; then + echoc ${Red} "You cannot use the custom theme as base" + else + echoc ${Green} "Creating new custom theme in \"${HOME}/.git-prompt-colors.sh\"" + echoc ${DimYellow} "Please add ${Magenta}\"GIT_PROMPT_THEME=Custom\"${DimYellow} to your .bashrc to use this theme" + if [[ "${base}" == "Default" ]]; then + cp "${__GIT_PROMPT_DIR}/themes/Custom.bgptemplate" "${HOME}/.git-prompt-colors.sh" + else + cp "${__GIT_PROMPT_DIR}/themes/${base}.bgptheme" "${HOME}/.git-prompt-colors.sh" + fi + fi + fi +} + +# gp_set_file_var ENVAR SOMEFILE +# +# If ENVAR is set, check that it's value exists as a readable file. Otherwise, +# 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 "[[ -n \"\$$envar\" && -r \"\$$envar\" ]]" ; then # is envar set to a readable file? + local basefile + eval "basefile=\"\`basename \\\"\$$envar\\\"\`\"" # assign basefile + if [[ "$basefile" = "$file" || "$basefile" = ".$file" ]]; then + return 0 + fi + else # envar is not set, or it's set to a different file than requested + eval "$envar=" # set empty envar + gp_maybe_set_envar_to_path "$envar" "$HOME/.$file" "$HOME/$file" "$HOME/lib/$file" && return 0 + git_prompt_dir + gp_maybe_set_envar_to_path "$envar" "$__GIT_PROMPT_DIR/$file" "${0##*/}/$file" && return 0 + fi + return 1 +} + +# gp_maybe_set_envar_to_path ENVAR FILEPATH ... +# +# return 0 (true) if any FILEPATH is readable, set ENVAR to it +# return 1 (false) if not + +function gp_maybe_set_envar_to_path() { + local envar="$1" + shift + local file + for file in "$@" ; do + if [[ -r "$file" ]]; then + eval "$envar=\"$file\"" + return 0 + fi + done + return 1 +} + +# git_prompt_reset +# +# unsets selected GIT_PROMPT variables, causing the next prompt callback to +# recalculate them from scratch. + +git_prompt_reset() { + local var + for var in GIT_PROMPT_DIR __GIT_PROMPT_COLORS_FILE __PROMPT_COLORS_FILE __GIT_STATUS_CMD GIT_PROMPT_THEME_NAME; do + unset $var + done +} + +# gp_format_exit_status RETVAL +# +# echos the symbolic signal name represented by RETVAL if the process was +# signalled, otherwise echos the original value of RETVAL + +gp_format_exit_status() { + local RETVAL="$1" + local SIGNAL + # Suppress STDERR in case RETVAL is not an integer (in such cases, RETVAL + # is echoed verbatim) + if [ "${RETVAL}" -gt 128 ] 2>/dev/null; then + SIGNAL=$(( ${RETVAL} - 128 )) + kill -l "${SIGNAL}" 2>/dev/null || echo "${RETVAL}" + else + echo "${RETVAL}" + fi +} + +function git_prompt_config() { + #Checking if root to change output + _isroot=false + [[ $UID -eq 0 ]] && _isroot=true + + # There are two files related to colors: + # + # 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 + + git_prompt_load_colors + + # source the user's ~/.git-prompt-colors.sh file, or the one that should be + # sitting in the same directory as this script + + git_prompt_load_theme + + if is_function prompt_callback; then + prompt_callback="prompt_callback" + else + prompt_callback="prompt_callback_default" + fi + + if [ $GIT_PROMPT_LAST_COMMAND_STATE = 0 ]; then + LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_OK"; + else + LAST_COMMAND_INDICATOR="$GIT_PROMPT_COMMAND_FAIL"; + fi + + # replace _LAST_COMMAND_STATE_ token with the actual state + GIT_PROMPT_LAST_COMMAND_STATE=$(gp_format_exit_status ${GIT_PROMPT_LAST_COMMAND_STATE}) + LAST_COMMAND_INDICATOR="${LAST_COMMAND_INDICATOR//_LAST_COMMAND_STATE_/${GIT_PROMPT_LAST_COMMAND_STATE}}" + + # Do this only once to define PROMPT_START and PROMPT_END + + if [[ -z "$PROMPT_START" || -z "$PROMPT_END" ]]; then + + if [[ -z "$GIT_PROMPT_START" ]] ; then + if $_isroot; then + PROMPT_START="$GIT_PROMPT_START_ROOT" + else + PROMPT_START="$GIT_PROMPT_START_USER" + fi + else + PROMPT_START="$GIT_PROMPT_START" + fi + + if [[ -z "$GIT_PROMPT_END" ]] ; then + if $_isroot; then + PROMPT_END="$GIT_PROMPT_END_ROOT" + else + PROMPT_END="$GIT_PROMPT_END_USER" + fi + else + PROMPT_END="$GIT_PROMPT_END" + fi + fi + + # set GIT_PROMPT_LEADING_SPACE to 0 if you want to have no leading space in front of the GIT prompt + if [[ "$GIT_PROMPT_LEADING_SPACE" = 0 ]]; then + PROMPT_LEADING_SPACE="" + else + PROMPT_LEADING_SPACE=" " + fi + + if [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then + EMPTY_PROMPT="$OLD_GITPROMPT" + else + local ps="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$PROMPT_END" + EMPTY_PROMPT="${ps//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}}" + fi + + # fetch remote revisions every other $GIT_PROMPT_FETCH_TIMEOUT (default 5) minutes + if [[ -z "$GIT_PROMPT_FETCH_TIMEOUT" ]]; then + GIT_PROMPT_FETCH_TIMEOUT="5" + fi + if [[ -z "$__GIT_STATUS_CMD" ]] ; then # if GIT_STATUS_CMD not defined.. + git_prompt_dir + if ! gp_maybe_set_envar_to_path __GIT_STATUS_CMD "$__GIT_PROMPT_DIR/$GIT_PROMPT_STATUS_COMMAND" ; then + echo 1>&2 "Cannot find $GIT_PROMPT_STATUS_COMMAND!" + fi + # __GIT_STATUS_CMD defined + fi + unset GIT_BRANCH +} + +function setLastCommandState() { + GIT_PROMPT_LAST_COMMAND_STATE=$? +} + +function we_are_on_repo() { + if [[ -e "$(git rev-parse --git-dir 2> /dev/null)" ]]; then + echo 1 + fi + echo 0 +} + +function update_old_git_prompt() { + local in_repo=$(we_are_on_repo) + if [[ $GIT_PROMPT_OLD_DIR_WAS_GIT = 0 ]]; then + OLD_GITPROMPT=$PS1 + fi + + GIT_PROMPT_OLD_DIR_WAS_GIT=$in_repo +} + +function setGitPrompt() { + update_old_git_prompt + + local repo=$(git rev-parse --show-toplevel 2> /dev/null) + if [[ ! -e "$repo" ]] && [[ "$GIT_PROMPT_ONLY_IN_REPO" = 1 ]]; then + # we do not permit bash-git-prompt outside git repos, so nothing to do + PS1="$OLD_GITPROMPT" + return + fi + + local EMPTY_PROMPT + local __GIT_STATUS_CMD + + git_prompt_config + + if [[ ! -e "$repo" ]] || [[ "$GIT_PROMPT_DISABLE" = 1 ]]; then + PS1="$EMPTY_PROMPT" + return + fi + + local FETCH_REMOTE_STATUS=1 + if [[ "$GIT_PROMPT_FETCH_REMOTE_STATUS" = 0 ]]; then + FETCH_REMOTE_STATUS=0 + fi + + unset GIT_PROMPT_IGNORE + OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES} + unset GIT_PROMPT_SHOW_UNTRACKED_FILES + + if [[ -e "$repo/.bash-git-rc" ]]; then + source "$repo/.bash-git-rc" + fi + + if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then + GIT_PROMPT_SHOW_UNTRACKED_FILES=${OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES} + fi + unset OLD_GIT_PROMPT_SHOW_UNTRACKED_FILES + + if [[ "$GIT_PROMPT_IGNORE" = 1 ]]; then + PS1="$EMPTY_PROMPT" + return + fi + + if [[ "$FETCH_REMOTE_STATUS" = 1 ]]; then + checkUpstream + fi + + updatePrompt +} + +# some versions of find do not have -mmin +_have_find_mmin=1 + +function olderThanMinutes() { + local matches + local find_exit_code + + if [[ -z "$_find_command" ]]; then + if command -v gfind > /dev/null; then + _find_command=gfind + else + _find_command=find + fi + fi + + if [[ "$_have_find_mmin" = 1 ]]; then + matches=$("$_find_command" "$1" -mmin +"$2" 2> /dev/null) + find_exit_code="$?" + if [[ -n "$matches" ]]; then + return 0 + else + if [[ "$find_exit_code" != 0 ]]; then + _have_find_mmin=0 + else + return 1 + fi + fi + fi + + # try perl, solaris ships with perl + if command -v perl > /dev/null; then + perl -e '((time - (stat("'"$1"'"))[9]) / 60) > '"$2"' && exit(0) || exit(1)' + return "$?" + else + echo >&2 + echo "WARNING: neither a find that supports -mmin (such as GNU find) or perl is available, disabling remote status checking. Install GNU find as gfind or perl to enable this feature, or set GIT_PROMPT_FETCH_REMOTE_STATUS=0 to disable this warning." >&2 + echo >&2 + GIT_PROMPT_FETCH_REMOTE_STATUS=0 + return 1 + fi +} + +function checkUpstream() { + local GIT_PROMPT_FETCH_TIMEOUT + git_prompt_config + + local FETCH_HEAD="$repo/.git/FETCH_HEAD" + # Fech repo if local is stale for more than $GIT_FETCH_TIMEOUT minutes + if [[ ! -e "$FETCH_HEAD" ]] || olderThanMinutes "$FETCH_HEAD" "$GIT_PROMPT_FETCH_TIMEOUT" + then + if [[ -n $(git remote show) ]]; then + ( + async_run "git fetch --quiet" + disown -h + ) + fi + fi +} + +function replaceSymbols() { + if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L + fi + + local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}} + local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}} + local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}} + + echo ${VALUE2//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}} +} + +function createPrivateIndex { + # Create a copy of the index to avoid conflicts with parallel git commands, e.g. git rebase. + local __GIT_INDEX_FILE + local __GIT_INDEX_PRIVATE + if [[ -z "$GIT_INDEX_FILE" ]]; then + __GIT_INDEX_FILE="$(git rev-parse --git-dir)/index" + else + __GIT_INDEX_FILE="$GIT_INDEX_FILE" + fi + __GIT_INDEX_PRIVATE="/tmp/git-index-private$$" + command cp "$__GIT_INDEX_FILE" "$__GIT_INDEX_PRIVATE" 2>/dev/null + echo "$__GIT_INDEX_PRIVATE" +} + +function updatePrompt() { + local LAST_COMMAND_INDICATOR + local PROMPT_LEADING_SPACE + local PROMPT_START + local PROMPT_END + local EMPTY_PROMPT + local Blue="\[\033[0;34m\]" + + git_prompt_config + + export __GIT_PROMPT_IGNORE_STASH=${GIT_PROMPT_IGNORE_STASH} + export __GIT_PROMPT_SHOW_UPSTREAM=${GIT_PROMPT_SHOW_UPSTREAM} + + if [ -z "${GIT_PROMPT_SHOW_UNTRACKED_FILES}" ]; then + export __GIT_PROMPT_SHOW_UNTRACKED_FILES=all + else + export __GIT_PROMPT_SHOW_UNTRACKED_FILES=${GIT_PROMPT_SHOW_UNTRACKED_FILES} + fi + + if [ -z "${GIT_PROMPT_SHOW_CHANGED_FILES_COUNT}" ]; then + export __GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=1 + else + export __GIT_PROMPT_SHOW_CHANGED_FILES_COUNT=${GIT_PROMPT_SHOW_CHANGED_FILES_COUNT} + fi + + local GIT_INDEX_PRIVATE="$(createPrivateIndex)" + #important to define GIT_INDEX_FILE as local: This way it only affects this function (and below) - even with the export afterwards + local GIT_INDEX_FILE + export GIT_INDEX_FILE="$GIT_INDEX_PRIVATE" + + local -a git_status_fields + git_status_fields=($("$__GIT_STATUS_CMD" 2>/dev/null)) + + export GIT_BRANCH=$(replaceSymbols ${git_status_fields[0]}) + local GIT_REMOTE="$(replaceSymbols ${git_status_fields[1]})" + if [[ "." == "$GIT_REMOTE" ]]; then + unset GIT_REMOTE + fi + + local GIT_UPSTREAM="${git_status_fields[2]}" + if [[ -z "${__GIT_PROMPT_SHOW_UPSTREAM}" || "^" == "$GIT_UPSTREAM" ]]; then + unset GIT_UPSTREAM + else + GIT_UPSTREAM="${GIT_PROMPT_UPSTREAM//_UPSTREAM_/${GIT_UPSTREAM}}" + fi + + local GIT_STAGED=${git_status_fields[3]} + local GIT_CONFLICTS=${git_status_fields[4]} + local GIT_CHANGED=${git_status_fields[5]} + local GIT_UNTRACKED=${git_status_fields[6]} + local GIT_STASHED=${git_status_fields[7]} + local GIT_CLEAN=${git_status_fields[8]} + + local NEW_PROMPT="$EMPTY_PROMPT" + if [[ -n "$git_status_fields" ]]; then + local STATUS="${PROMPT_LEADING_SPACE}${GIT_PROMPT_PREFIX}${GIT_PROMPT_BRANCH}${GIT_BRANCH}${ResetColor}" + + # __add_status KIND VALEXPR INSERT + # eg: __add_status 'STAGED' '-ne 0' + + __chk_gitvar_status() { + local v + if [[ "x$2" == "x-n" ]] ; then + v="$2 \"\$GIT_$1\"" + else + v="\$GIT_$1 $2" + fi + if eval "test $v" ; then + if [[ $# -lt 2 || "$3" != '-' ]] && [[ "x$__GIT_PROMPT_SHOW_CHANGED_FILES_COUNT" == "x1" || "x$1" == "xREMOTE" ]]; then + __add_status "\$GIT_PROMPT_$1\$GIT_$1\$ResetColor" + else + __add_status "\$GIT_PROMPT_$1\$ResetColor" + fi + fi + } + + __add_gitvar_status() { + __add_status "\$GIT_PROMPT_$1\$GIT_$1\$ResetColor" + } + + # __add_status SOMETEXT + __add_status() { + eval "STATUS=\"$STATUS$1\"" + } + + __add_status '$GIT_UPSTREAM' + __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" + + NEW_PROMPT="$(gp_add_virtualenv_to_prompt)$PROMPT_START$($prompt_callback)$STATUS$PROMPT_END" + else + NEW_PROMPT="$EMPTY_PROMPT" + fi + + PS1="${NEW_PROMPT//_LAST_COMMAND_INDICATOR_/${LAST_COMMAND_INDICATOR}${ResetColor}}" + command rm "$GIT_INDEX_PRIVATE" 2>/dev/null +} + +# Helper function that returns virtual env information to be set in prompt +# Honors virtualenvs own setting VIRTUAL_ENV_DISABLE_PROMPT +function gp_add_virtualenv_to_prompt { + local ACCUMULATED_VENV_PROMPT="" + local VENV="" + if [[ -n "$VIRTUAL_ENV" && -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ]]; then + VENV=$(basename "${VIRTUAL_ENV}") + ACCUMULATED_VENV_PROMPT="${ACCUMULATED_VENV_PROMPT}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" + fi + if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + VENV=$(basename "${CONDA_DEFAULT_ENV}") + ACCUMULATED_VENV_PROMPT="${ACCUMULATED_VENV_PROMPT}${GIT_PROMPT_VIRTUALENV//_VIRTUALENV_/${VENV}}" + fi + echo "$ACCUMULATED_VENV_PROMPT" +} + +# Use exit status from declare command to determine whether input argument is a +# bash function +function is_function { + declare -Ff "$1" >/dev/null; +} + +# Helper function that truncates $PWD depending on window width +function gp_truncate_pwd { + local tilde="~" + local newPWD="${PWD/#${HOME}/${tilde}}" + local pwdmaxlen=$((${COLUMNS:-80}/3)) + [ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}" + echo -n "$newPWD" +} + +# Sets the window title to the given argument string +function gp_set_window_title { + echo -ne "\[\033]0;"$@"\007\]" +} + +function prompt_callback_default { + return +} + +# toggle gitprompt +function git_prompt_toggle() { + if [[ "$GIT_PROMPT_DISABLE" = 1 ]]; then + GIT_PROMPT_DISABLE=0 + else + GIT_PROMPT_DISABLE=1 + fi + return +} + +function gp_install_prompt { + if [ -z "$OLD_GITPROMPT" ]; then + OLD_GITPROMPT=$PS1 + fi + + if [ -z "$GIT_PROMPT_OLD_DIR_WAS_GIT" ]; then + GIT_PROMPT_OLD_DIR_WAS_GIT=$(we_are_on_repo) + fi + + if [ -z "$PROMPT_COMMAND" ]; then + PROMPT_COMMAND=setGitPrompt + else + PROMPT_COMMAND=${PROMPT_COMMAND%% }; # remove trailing spaces + PROMPT_COMMAND=${PROMPT_COMMAND%\;}; # remove trailing semi-colon + + local new_entry="setGitPrompt" + case ";$PROMPT_COMMAND;" in + *";$new_entry;"*) + # echo "PROMPT_COMMAND already contains: $new_entry" + :;; + *) + PROMPT_COMMAND="$PROMPT_COMMAND;$new_entry" + # echo "PROMPT_COMMAND does not contain: $new_entry" + ;; + esac + fi + + local setLastCommandStateEntry="setLastCommandState" + case ";$PROMPT_COMMAND;" in + *";$setLastCommandStateEntry;"*) + # echo "PROMPT_COMMAND already contains: $setLastCommandStateEntry" + :;; + *) + PROMPT_COMMAND="$setLastCommandStateEntry;$PROMPT_COMMAND" + # echo "PROMPT_COMMAND does not contain: $setLastCommandStateEntry" + ;; + esac + + git_prompt_dir + source "$__GIT_PROMPT_DIR/git-prompt-help.sh" +} + +gp_install_prompt diff --git a/bash-git-prompt/share/gitstatus.py b/bash-git-prompt/share/gitstatus.py new file mode 100755 index 0000000..e049d08 --- /dev/null +++ b/bash-git-prompt/share/gitstatus.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +"""This module defines a Print function to use with python 2.x or 3.x., so we can use the prompt with older versions of +Python too + +It's interface is that of python 3.0's print. See +http://docs.python.org/3.0/library/functions.html?highlight=print#print + +Shamelessly ripped from +http://www.daniweb.com/software-development/python/code/217214/a-print-function-for-different-versions-of-python +""" +# change those symbols to whatever you prefer +symbols = {'ahead of': '↑·', 'behind': '↓·', 'prehash': ':'} + +import sys +import re +from subprocess import Popen, PIPE + +__all__ = ["Print"] + +try: + Print = eval("print") # python 3.0 case + python_version = 3 + to_str = str +except SyntaxError as e: + python_version = 2 + to_str = unicode + D = dict() + try: + exec ("from __future__ import print_function\np=print", D) + Print = D["p"] # 2.6 case + except SyntaxError: + def Print(*args, **kwd): # 2.4, 2.5, define our own Print function + fout = kwd.get("file", sys.stdout) + w = fout.write + if args: + w(str(args[0])) + sep = kwd.get("sep", " ") + for a in args[1:]: + w(sep) + w(str(a)) + w(kwd.get("end", "\n")) + finally: + del D + + +def get_tag_or_hash(): + cmd = Popen(['git', 'describe', '--exact-match'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + tag = '%s' % so.decode('utf-8').strip() + + if tag: + return tag + else: + cmd = Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + hash_name = '%s' % so.decode('utf-8').strip() + return ''.join([symbols['prehash'], hash_name]) + + +def get_stash(): + cmd = Popen(['git', 'rev-parse', '--git-dir'], stdout=PIPE, stderr=PIPE) + so, se = cmd.communicate() + stash_file = '%s%s' % (so.decode('utf-8').rstrip(), '/logs/refs/stash') + + try: + with open(stash_file) as f: + return sum(1 for _ in f) + except IOError: + return 0 + + +# `git status --porcelain --branch` can collect all information +# branch, remote_branch, untracked, staged, changed, conflicts, ahead, behind +po = Popen(['git', 'status', '--porcelain', '--branch'], env={'LC_ALL': 'C'}, stdout=PIPE, stderr=PIPE) +stdout, stderr = po.communicate() +if po.returncode != 0: + sys.exit(0) # Not a git repository + +# collect git status information +untracked, staged, changed, conflicts = [], [], [], [] +num_ahead, num_behind = 0, 0 +ahead, behind = '', '' +branch = '' +remote = '' +status = [(line[0], line[1], line[2:]) for line in stdout.decode('utf-8').splitlines()] +for st in status: + if st[0] == '#' and st[1] == '#': + if re.search('Initial commit on', st[2]): + branch = st[2].split(' ')[-1] + elif re.search('no branch', st[2]): # detached status + branch = get_tag_or_hash() + elif len(st[2].strip().split('...')) == 1: + branch = st[2].strip() + else: + # current and remote branch info + branch, rest = st[2].strip().split('...') + if len(rest.split(' ')) == 1: + # remote_branch = rest.split(' ')[0] + pass + else: + # ahead or behind + divergence = ' '.join(rest.split(' ')[1:]) + divergence = divergence.lstrip('[').rstrip(']') + for div in divergence.split(', '): + if 'ahead' in div: + num_ahead = int(div[len('ahead '):].strip()) + ahead = '%s%s' % (symbols['ahead of'], num_ahead) + elif 'behind' in div: + num_behind = int(div[len('behind '):].strip()) + behind = '%s%s' % (symbols['behind'], num_behind) + remote = ''.join([behind, ahead]) + elif st[0] == '?' and st[1] == '?': + untracked.append(st) + else: + if st[1] == 'M': + changed.append(st) + if st[0] == 'U': + conflicts.append(st) + elif st[0] != ' ': + staged.append(st) + +stashed = get_stash() +if not changed and not staged and not conflicts and not untracked and not stashed: + clean = 1 +else: + clean = 0 + +if remote == "": + remote = '.' + +if python_version == 2: + remote = remote.decode('utf-8') + +out = '\n'.join([ + branch, + remote, + to_str(len(staged)), + to_str(len(conflicts)), + to_str(len(changed)), + to_str(len(untracked)), + to_str(stashed), + to_str(clean), + to_str(python_version), +]) + + +if python_version == 2: + Print(out.encode('utf-8')) +else: + Print(out) + diff --git a/bash-git-prompt/share/gitstatus.sh b/bash-git-prompt/share/gitstatus.sh new file mode 100755 index 0000000..68ff511 --- /dev/null +++ b/bash-git-prompt/share/gitstatus.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash +# -*- coding: utf-8 -*- +# gitstatus.sh -- produce the current git repo status on STDOUT +# Functionally equivalent to 'gitstatus.py', but written in bash (not python). +# +# Alan K. Stebbens [http://github.com/aks] + +if [ -z "${__GIT_PROMPT_DIR}" ]; then + SOURCE="${BASH_SOURCE[0]}" + while [ -h "${SOURCE}" ]; do + DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" + done + __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" +fi + +gitstatus=$( LC_ALL=C git status --untracked-files=${__GIT_PROMPT_SHOW_UNTRACKED_FILES:-all} --porcelain --branch ) + +# if the status is fatal, exit now +[[ "$?" -ne 0 ]] && exit 0 + +num_staged=0 +num_changed=0 +num_conflicts=0 +num_untracked=0 +while IFS='' read -r line || [[ -n "$line" ]]; do + status=${line:0:2} + while [[ -n $status ]]; do + case "$status" in + #two fixed character matches, loop finished + \#\#) branch_line="${line/\.\.\./^}"; break ;; + \?\?) ((num_untracked++)); break ;; + U?) ((num_conflicts++)); break;; + ?U) ((num_conflicts++)); break;; + DD) ((num_conflicts++)); break;; + AA) ((num_conflicts++)); break;; + #two character matches, first loop + ?M) ((num_changed++)) ;; + ?D) ((num_changed++)) ;; + ?\ ) ;; + #single character matches, second loop + U) ((num_conflicts++)) ;; + \ ) ;; + *) ((num_staged++)) ;; + esac + status=${status:0:(${#status}-1)} + done +done <<< "$gitstatus" + +num_stashed=0 +if [[ "$__GIT_PROMPT_IGNORE_STASH" != "1" ]]; then + stash_file="$( git rev-parse --git-dir )/logs/refs/stash" + if [[ -e "${stash_file}" ]]; then + while IFS='' read -r wcline || [[ -n "$wcline" ]]; do + ((num_stashed++)) + done < ${stash_file} + fi +fi + +clean=0 +if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed == 0 && num_conflicts == 0)) ; then + clean=1 +fi + +IFS="^" read -ra branch_fields <<< "${branch_line/\#\# }" +branch="${branch_fields[0]}" +remote= +upstream= + +if [[ "$branch" == *"Initial commit on"* ]]; then + IFS=" " read -ra fields <<< "$branch" + branch="${fields[3]}" + remote="_NO_REMOTE_TRACKING_" +elif [[ "$branch" == *"no branch"* ]]; then + tag=$( git describe --tags --exact-match ) + if [[ -n "$tag" ]]; then + branch="$tag" + else + branch="_PREHASH_$( git rev-parse --short HEAD )" + fi +else + if [[ "${#branch_fields[@]}" -eq 1 ]]; then + remote="_NO_REMOTE_TRACKING_" + else + IFS="[,]" read -ra remote_fields <<< "${branch_fields[1]}" + upstream="${remote_fields[0]}" + for remote_field in "${remote_fields[@]}"; do + if [[ "$remote_field" == *ahead* ]]; then + num_ahead=${remote_field:6} + ahead="_AHEAD_${num_ahead}" + fi + if [[ "$remote_field" == *behind* ]]; then + num_behind=${remote_field:7} + behind="_BEHIND_${num_behind# }" + fi + done + remote="${behind}${ahead}" + fi +fi + +if [[ -z "$remote" ]] ; then + remote='.' +fi + +if [[ -z "$upstream" ]] ; then + upstream='^' +fi + +printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ + "$branch" \ + "$remote" \ + "$upstream" \ + $num_staged \ + $num_conflicts \ + $num_changed \ + $num_untracked \ + $num_stashed \ + $clean + +exit diff --git a/bash-git-prompt/share/gitstatus_pre-1.7.10.sh b/bash-git-prompt/share/gitstatus_pre-1.7.10.sh new file mode 100755 index 0000000..a7a352f --- /dev/null +++ b/bash-git-prompt/share/gitstatus_pre-1.7.10.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +# -*- coding: UTF-8 -*- +# gitstatus.sh -- produce the current git repo status on STDOUT +# Functionally equivalent to 'gitstatus.py', but written in bash (not python). +# +# Alan K. Stebbens [http://github.com/aks] + +# helper functions +count_lines() { echo "$1" | egrep -c "^$2" ; } +all_lines() { echo "$1" | grep -v "^$" | wc -l ; } + +if [ -z "${__GIT_PROMPT_DIR}" ]; then + SOURCE="${BASH_SOURCE[0]}" + while [ -h "${SOURCE}" ]; do + DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" + SOURCE="$(readlink "${SOURCE}")" + [[ $SOURCE != /* ]] && SOURCE="${DIR}/${SOURCE}" + done + __GIT_PROMPT_DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )" +fi + +gitsym=$( git symbolic-ref HEAD 2>/dev/null ) + +#If exit status OK, we have a branch +if [[ $? == 0 ]]; then + # the current branch is the tail end of the symbolic reference + branch="${gitsym##refs/heads/}" # get the basename after "refs/heads/" +fi + +gitstatus=$( git diff --name-status 2>&1 ) + +# if the diff is fatal, exit now +if [[ $? != 0 ]]; then exit 0; fi + +staged_files=$( git diff --staged --name-status ) + +num_changed=$(( $( all_lines "$gitstatus" ) - $( count_lines "$gitstatus" U ) )) +num_conflicts=$( count_lines "$staged_files" U ) +num_staged=$(( $( all_lines "$staged_files" ) - num_conflicts )) +num_untracked=$( git ls-files --others --exclude-standard $(git rev-parse --show-cdup) | wc -l ) + +num_stashed=0 +if [[ "$__GIT_PROMPT_IGNORE_STASH" != "1" ]]; then + stash_file="$( git rev-parse --git-dir )/logs/refs/stash" + if [[ -e "${stash_file}" ]]; then + while IFS='' read -r wcline || [[ -n "$wcline" ]]; do + ((num_stashed++)) + done < ${stash_file} + fi +fi + +clean=0 +if (( num_changed == 0 && num_staged == 0 && num_untracked == 0 && num_stashed == 0 && num_conflicts == 0 )) ; then + clean=1 +fi + +remote= +upstream= + +if [[ -z "$branch" ]]; then + tag=$( git describe --tags --exact-match 2>/dev/null ) + if [[ -n "$tag" ]]; then + branch="$tag" + else + branch="_PREHASH_$( git rev-parse --short HEAD )" + fi +else + remote_name=$( git config branch.${branch}.remote ) + + if [[ -n "$remote_name" ]]; then + merge_name=$( git config branch.${branch}.merge ) + else + remote_name='origin' + merge_name="refs/heads/${branch}" + fi + + if [[ "$remote_name" == '.' ]]; then + remote_ref="$merge_name" + else + remote_ref="refs/remotes/$remote_name/${merge_name##refs/heads/}" + fi + + # detect if the local branch have a remote tracking branch + upstream=$( git rev-parse --abbrev-ref ${branch}@{upstream} 2>&1 ) + + if [[ $? == 0 ]]; then + # get the revision list, and count the leading "<" and ">" + revgit=$( git rev-list --left-right ${remote_ref}...HEAD 2>/dev/null ) + if [[ $? == 0 ]]; then + num_revs=$( all_lines "$revgit" ) + num_ahead=$( count_lines "$revgit" "^>" ) + num_behind=$(( num_revs - num_ahead )) + if (( num_behind > 0 )) ; then + remote="${remote}_BEHIND_${num_behind}" + fi + if (( num_ahead > 0 )) ; then + remote="${remote}_AHEAD_${num_ahead}" + fi + fi + else + remote='_NO_REMOTE_TRACKING_' + unset upstream + fi +fi + +if [[ -z "$remote" ]] ; then + remote='.' +fi + +if [[ -z "$upstream" ]] ; then + upstream='^' +fi + +printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ + "$branch" \ + "$remote" \ + "$upstream" \ + $num_staged \ + $num_conflicts \ + $num_changed \ + $num_untracked \ + $num_stashed \ + $clean + +exit diff --git a/bash-git-prompt/share/prompt-colors.sh b/bash-git-prompt/share/prompt-colors.sh new file mode 100644 index 0000000..1f70033 --- /dev/null +++ b/bash-git-prompt/share/prompt-colors.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# prompt-colors.sh +# +# source this file to get color definitions +# if $debug or $verbose is set, the definitions +# are also printed to STDERR. + +define_color_names() { + + ColorNames=( Black Red Green Yellow Blue Magenta Cyan White ) + FgColors=( 30 31 32 33 34 35 36 37 ) + BgColors=( 40 41 42 43 44 45 46 47 ) + + local AttrNorm=0 + local AttrBright=1 + local AttrDim=2 + local AttrUnder=4 + local AttrBlink=5 + local AttrRev=7 + local AttrHide=8 + + # define "BoldCOLOR", "BrightCOLOR", and "DimCOLOR" names + + # _map_colors ATTRNAME ATTRVALUE + # + # Defines three names for every color, attribute combintaion: + # {ATTRNAME}{COLORNAME} + # {ATTRNAME}{COLORNAME}Fg + # {ATTRNAME}{COLORNAME}Bg + # + # Example: BoldRed, BoldRedFg, BoldRedBg + + _map_colors() { + local x=0 + local attrname="$1" + local attrcode=$2 + while (( x < 8 )) ; do + local colorname=${ColorNames[x]} + local fgcolorcode=${FgColors[x]} + local bgcolorcode=${BgColors[x]} + longcolorname="${attrname}${colorname}" + _def_color $longcolorname $attrcode $fgcolorcode + _def_color ${longcolorname}Fg $attrcode $fgcolorcode + _def_color ${longcolorname}Bg $attrcode $bgcolorcode + (( x++ )) + done + } + + # _term_color [ N | N M ] + _term_color() { + local cv + if (( $# > 1 )); then + cv="${1};${2}" + else + cv="${1}" + fi + echo "\[\033[${cv}m\]" + } + + # def_color NAME ATTRCODE COLORCODE + _def_color() { + local def="$1=\"\`_term_color $2 $3\`\"" + if [[ -n "$debug$verbose" ]]; then + echo 1>&2 "+ $def" + 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 + +} + +# do the color definitions only once +if [[ ${#ColorNames[*]} = 0 || -z "$IntenseBlack" || -z "$ResetColor" ]]; then + define_color_names +fi diff --git a/bash-git-prompt/share/themes/Chmike.bgptheme b/bash-git-prompt/share/themes/Chmike.bgptheme new file mode 100644 index 0000000..33f9655 --- /dev/null +++ b/bash-git-prompt/share/themes/Chmike.bgptheme @@ -0,0 +1,31 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# it is clone of oh-my-zsh crunch theme style with exit status + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if command -v rbenv > /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M)" + + + GIT_PROMPT_THEME_NAME="Chmike" + GIT_PROMPT_BRANCH="${Green}" + GIT_PROMPT_REMOTE=" " + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="⭐" + + GIT_PROMPT_SEPARATOR="|" + GIT_PROMPT_CHANGED="${Cyan}❗" + GIT_PROMPT_STAGED="${Yellow}▸" + GIT_PROMPT_UNTRACKED="${Blue}…" + GIT_PROMPT_CONFLICTS="${BoldRed}❓" + GIT_PROMPT_STASHED="${Magenta}>" + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" +} + +reload_git_prompt_colors "Crunch" diff --git a/bash-git-prompt/share/themes/Crunch.bgptheme b/bash-git-prompt/share/themes/Crunch.bgptheme new file mode 100644 index 0000000..8dd182f --- /dev/null +++ b/bash-git-prompt/share/themes/Crunch.bgptheme @@ -0,0 +1,34 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# it is clone of oh-my-zsh crunch theme style with exit status + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if command -v rbenv > /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M)" + + GIT_PROMPT_THEME_NAME="Crunch" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + KERNEL_PROMPT='‹$(uname -r)›' + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_${White}{${Yellow}${Time12a}${White}}[${Magenta}${RUBY_PROMPT}${White}]${Cyan}${PathShort}${White}:" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="${BoldRed} # ${ResetColor}" + GIT_PROMPT_LEADING_SPACE=0 + GIT_PROMPT_PREFIX="${Green}[" + GIT_PROMPT_SUFFIX="${Green}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Crunch" diff --git a/bash-git-prompt/share/themes/Custom.bgptemplate b/bash-git-prompt/share/themes/Custom.bgptemplate new file mode 100644 index 0000000..d494198 --- /dev/null +++ b/bash-git-prompt/share/themes/Custom.bgptemplate @@ -0,0 +1,58 @@ +# This is the custom theme template for gitprompt.sh + +# These are the defaults from the "Default" theme +# You just need to override what you want to have changed +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Custom" + + # Time12a="\$(date +%H:%M)" + # PathShort="\w"; + + ## These are the color definitions used by gitprompt.sh + # GIT_PROMPT_PREFIX="[" # start of the git info string + # GIT_PROMPT_SUFFIX="]" # the end of the git info string + # GIT_PROMPT_SEPARATOR="|" # separates each item + + # GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + # GIT_PROMPT_STAGED="${Red}●" # the number of staged files/directories + # GIT_PROMPT_CONFLICTS="${Red}✖ " # the number of files in conflict + # GIT_PROMPT_CHANGED="${Blue}✚ " # the number of changed files + + # GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + # GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + # GIT_PROMPT_STASHED="${BoldBlue}⚑ " # the number of stashed files/dir + # GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + ## For the command indicator, the placeholder _LAST_COMMAND_STATE_ + ## will be replaced with the exit code of the last command + ## e.g. + ## GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + ## GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + # GIT_PROMPT_COMMAND_OK="${Green}✔" # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 + + ## template for displaying the current virtual environment + ## use the placeholder _VIRTUALENV_ will be replaced with + ## the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + # GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) " + + # template for displaying the current remote tracking branch + # use the placeholder _UPSTREAM_ will be replaced with + # the name of the current remote tracking branch + # GIT_PROMPT_UPSTREAM=" {${Blue}_UPSTREAM_${ResetColor}}" + + ## _LAST_COMMAND_INDICATOR_ will be replaced by the appropriate GIT_PROMPT_COMMAND_OK OR GIT_PROMPT_COMMAND_FAIL + # GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + # GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${GIT_PROMPT_START_USER}" + # GIT_PROMPT_END_USER=" \n${White}${Time12a}${ResetColor} $ " + # GIT_PROMPT_END_ROOT=" \n${White}${Time12a}${ResetColor} # " + + ## Please do not add colors to these symbols + # GIT_PROMPT_SYMBOLS_AHEAD="↑·" # The symbol for "n versions ahead of origin" + # GIT_PROMPT_SYMBOLS_BEHIND="↓·" # The symbol for "n versions behind of origin" + # GIT_PROMPT_SYMBOLS_PREHASH=":" # Written before hash of commit, if no name could be found + # GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L" # This symbol is written after the branch, if the branch is not tracked +} + +reload_git_prompt_colors "Custom" \ No newline at end of file diff --git a/bash-git-prompt/share/themes/Default.bgptheme b/bash-git-prompt/share/themes/Default.bgptheme new file mode 100644 index 0000000..be680c5 --- /dev/null +++ b/bash-git-prompt/share/themes/Default.bgptheme @@ -0,0 +1,106 @@ +# This is the default theme for gitprompt.sh + +unset_git_prompt_colors() { + unset Time12a + unset PathShort + unset GIT_PROMPT_PREFIX + unset GIT_PROMPT_SUFFIX + unset GIT_PROMPT_SEPARATOR + unset GIT_PROMPT_BRANCH + unset GIT_PROMPT_STAGED + unset GIT_PROMPT_CONFLICTS + unset GIT_PROMPT_CHANGED + unset GIT_PROMPT_REMOTE + unset GIT_PROMPT_UNTRACKED + unset GIT_PROMPT_STASHED + unset GIT_PROMPT_CLEAN + unset GIT_PROMPT_COMMAND_OK + unset GIT_PROMPT_COMMAND_FAIL + unset GIT_PROMPT_VIRTUALENV + unset GIT_PROMPT_UPSTREAM + unset GIT_PROMPT_START_USER + unset GIT_PROMPT_START_ROOT + unset GIT_PROMPT_END_USER + unset GIT_PROMPT_END_ROOT + unset GIT_PROMPT_SYMBOLS_AHEAD + unset GIT_PROMPT_SYMBOLS_BEHIND + unset GIT_PROMPT_SYMBOLS_PREHASH + unset GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING +} + +define_helpers() { + Time12a="\$(date +%H:%M)" + PathShort="\w"; +} + +define_undefined_git_prompt_colors() { + if [ -z ${GIT_PROMPT_THEME_NAME+x} ]; then GIT_PROMPT_THEME_NAME="Default"; fi + + # These are the color definitions used by gitprompt.sh + if [ -z ${GIT_PROMPT_PREFIX+x} ]; then GIT_PROMPT_PREFIX="["; fi # start of the git info string + if [ -z ${GIT_PROMPT_SUFFIX+x} ]; then GIT_PROMPT_SUFFIX="]"; fi # the end of the git info string + if [ -z ${GIT_PROMPT_SEPARATOR+x} ]; then GIT_PROMPT_SEPARATOR="|"; fi # separates each item + + if [ -z ${GIT_PROMPT_BRANCH+x} ]; then GIT_PROMPT_BRANCH="${Magenta}"; fi # the git branch that is active in the current directory + if [ -z ${GIT_PROMPT_STAGED+x} ]; then GIT_PROMPT_STAGED="${Red}●"; fi # the number of staged files/directories + if [ -z ${GIT_PROMPT_CONFLICTS+x} ]; then GIT_PROMPT_CONFLICTS="${Red}✖ "; fi # the number of files in conflict + if [ -z ${GIT_PROMPT_CHANGED+x} ]; then GIT_PROMPT_CHANGED="${Blue}✚ "; fi # the number of changed files + + if [ -z ${GIT_PROMPT_REMOTE+x} ]; then GIT_PROMPT_REMOTE=" "; fi # the remote branch name (if any) and the symbols for ahead and behind + if [ -z ${GIT_PROMPT_UNTRACKED+x} ]; then GIT_PROMPT_UNTRACKED="${Cyan}…"; fi # the number of untracked files/dirs + if [ -z ${GIT_PROMPT_STASHED+x} ]; then GIT_PROMPT_STASHED="${BoldBlue}⚑ "; fi # the number of stashed files/dir + if [ -z ${GIT_PROMPT_CLEAN+x} ]; then GIT_PROMPT_CLEAN="${BoldGreen}✔"; fi # a colored flag indicating a "clean" repo + + # For the command indicator, the placeholder _LAST_COMMAND_STATE_ + # will be replaced with the exit code of the last command + # e.g. + # GIT_PROMPT_COMMAND_OK="${Green}✔-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of 0 + # GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_ " # indicator if the last command returned with an exit code of other than 0 + + if [ -z ${GIT_PROMPT_COMMAND_OK+x} ]; then GIT_PROMPT_COMMAND_OK="${Green}✔"; fi # indicator if the last command returned with an exit code of 0 + if [ -z ${GIT_PROMPT_COMMAND_FAIL+x} ]; then GIT_PROMPT_COMMAND_FAIL="${Red}✘-_LAST_COMMAND_STATE_"; fi # indicator if the last command returned with an exit code of other than 0 + + # Possible to change which command is used to create git status information + # There are three options: + # 1) gitstatus.sh (uses git status --branch --porcelain - fast, requires git > 1.7.10) + # 2) gitstatus_pre-1.7.10.sh (Uses a variety of git commands and pipes - slower, works with older git clients) + # 3) gitstatus.py (Unsupported, lack features found in the bash versions) + if [ -z ${GIT_PROMPT_STATUS_COMMAND+x} ]; then GIT_PROMPT_STATUS_COMMAND="gitstatus.sh"; fi # Point out the command to get the git status from + + # template for displaying the current virtual environment + # use the placeholder _VIRTUALENV_ will be replaced with + # the name of the current virtual environment (currently CONDA and VIRTUAL_ENV) + if [ -z ${GIT_PROMPT_VIRTUALENV+x} ]; then GIT_PROMPT_VIRTUALENV="(${Blue}_VIRTUALENV_${ResetColor}) "; fi + + # template for displaying the current remote tracking branch + # use the placeholder _UPSTREAM_ will be replaced with + # the name of the current remote tracking branch + if [ -z ${GIT_PROMPT_UPSTREAM+x} ]; then GIT_PROMPT_UPSTREAM=" {${Blue}_UPSTREAM_${ResetColor}}"; fi + + # _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 + + # 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" + if [ -z ${GIT_PROMPT_SYMBOLS_BEHIND+x} ]; then GIT_PROMPT_SYMBOLS_BEHIND="↓·"; fi # The symbol for "n versions behind of origin" + if [ -z ${GIT_PROMPT_SYMBOLS_PREHASH+x} ]; then GIT_PROMPT_SYMBOLS_PREHASH=":"; fi # Written before hash of commit, if no name could be found + if [ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING+x} ]; then GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="L"; fi # This symbol is written after the branch, if the branch is not tracked +} + +# call only from theme file +reload_git_prompt_colors() { + if [[ "${GIT_PROMPT_THEME_NAME}" != $1 ]]; then + unset_git_prompt_colors + define_helpers + override_git_prompt_colors + define_undefined_git_prompt_colors + fi +} + +if [[ "${GIT_PROMPT_THEME}" == "Default" && "${GIT_PROMPT_THEME_NAME}" != "Default" ]]; then + define_helpers + define_undefined_git_prompt_colors +fi diff --git a/bash-git-prompt/share/themes/Default_NoExitState.bgptheme b/bash-git-prompt/share/themes/Default_NoExitState.bgptheme new file mode 100644 index 0000000..239aae1 --- /dev/null +++ b/bash-git-prompt/share/themes/Default_NoExitState.bgptheme @@ -0,0 +1,11 @@ +# This is the default theme for gitprompt.sh +# without the indicator of the last command state + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default NoExitState" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" +} + +reload_git_prompt_colors "Default NoExitState" diff --git a/bash-git-prompt/share/themes/Default_NoExitState_Ubuntu.bgptheme b/bash-git-prompt/share/themes/Default_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..27b78a8 --- /dev/null +++ b/bash-git-prompt/share/themes/Default_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,15 @@ +# This is the default theme for gitprompt.sh +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default NoExitState Ubuntu" + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" +} + +reload_git_prompt_colors "Default NoExitState Ubuntu" diff --git a/bash-git-prompt/share/themes/Default_Ubuntu.bgptheme b/bash-git-prompt/share/themes/Default_Ubuntu.bgptheme new file mode 100644 index 0000000..e68b7b7 --- /dev/null +++ b/bash-git-prompt/share/themes/Default_Ubuntu.bgptheme @@ -0,0 +1,11 @@ +# This is the default theme for gitprompt.sh +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Default Ubuntu" + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 +} + +reload_git_prompt_colors "Default Ubuntu" diff --git a/bash-git-prompt/share/themes/Evermeet.bgptheme b/bash-git-prompt/share/themes/Evermeet.bgptheme new file mode 100644 index 0000000..56c2f41 --- /dev/null +++ b/bash-git-prompt/share/themes/Evermeet.bgptheme @@ -0,0 +1,30 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# It is most suitable for Retina or high resolution displays + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Evermeet" + + GIT_PROMPT_PREFIX="" # start of the git info string + GIT_PROMPT_SUFFIX="" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Cyan}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${BoldRed}✖" # the number of files in conflict + GIT_PROMPT_CHANGED="${Cyan}✚" # the number of changed files + + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${Magenta}⚑" # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + GIT_PROMPT_UPSTREAM=" {${Magenta}_UPSTREAM_${ResetColor}}" + + GIT_PROMPT_START_USER="[${BoldGreen}\u@\h${ResetColor} ${BoldYellow}\${?}${ResetColor} ${BoldBlue}\w${ResetColor}" + GIT_PROMPT_START_ROOT="[${BoldRed}\u@\h${ResetColor} ${BoldYellow}\${?}${ResetColor} ${BoldBlue}\w${ResetColor}" + GIT_PROMPT_END_USER="]$ " + GIT_PROMPT_END_ROOT="]# " + + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="⭑" # This symbol is written after the branch, if the branch is not tracked +} + +reload_git_prompt_colors "Evermeet" diff --git a/bash-git-prompt/share/themes/Evermeet_Lowres.bgptheme b/bash-git-prompt/share/themes/Evermeet_Lowres.bgptheme new file mode 100644 index 0000000..421ed76 --- /dev/null +++ b/bash-git-prompt/share/themes/Evermeet_Lowres.bgptheme @@ -0,0 +1,32 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# On lowres screens unicode characters like ✖ require a space after them +# otherwise the following character may overlap with the unicode character +# tweaked for low resolution and non-retina screens + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Evermeet_Lowres" + + GIT_PROMPT_PREFIX="" # start of the git info string + GIT_PROMPT_SUFFIX="" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Cyan}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${BoldRed}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Cyan}✚ " # the number of changed files + + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${Magenta}⚑" # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔" # a colored flag indicating a "clean" repo + + GIT_PROMPT_UPSTREAM=" {${Magenta}_UPSTREAM_${ResetColor}}" + + GIT_PROMPT_START_USER="[${BoldGreen}\u@\h${ResetColor} ${BoldYellow}\${?}${ResetColor} ${BoldBlue}\w${ResetColor}" + GIT_PROMPT_START_ROOT="[${BoldRed}\u@\h${ResetColor} ${BoldYellow}\${?}${ResetColor} ${BoldBlue}\w${ResetColor}" + GIT_PROMPT_END_USER="]$ " + GIT_PROMPT_END_ROOT="]# " + + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="⭑ " # This symbol is written after the branch, if the branch is not tracked +} + +reload_git_prompt_colors "Evermeet_Lowres" diff --git a/bash-git-prompt/share/themes/Evermeet_Ubuntu.bgptheme b/bash-git-prompt/share/themes/Evermeet_Ubuntu.bgptheme new file mode 100644 index 0000000..14077b9 --- /dev/null +++ b/bash-git-prompt/share/themes/Evermeet_Ubuntu.bgptheme @@ -0,0 +1,32 @@ +# This theme for gitprompt.sh is designed for dark color schemes +# On lowres screens unicode characters like ✖ require a space after them +# otherwise the following character may overlap with the unicode character +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Evermeet_Ubuntu" + + GIT_PROMPT_PREFIX="" # start of the git info string + GIT_PROMPT_SUFFIX="" # the end of the git info string + GIT_PROMPT_SEPARATOR="|" # separates each item + + GIT_PROMPT_BRANCH="${Magenta}" # the git branch that is active in the current directory + GIT_PROMPT_STAGED="${Cyan}● " # the number of staged files/directories + GIT_PROMPT_CONFLICTS="${BoldRed}✖ " # the number of files in conflict + GIT_PROMPT_CHANGED="${Cyan}✚ " # the number of changed files + + GIT_PROMPT_UNTRACKED="${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED="${Magenta}⚑ " # the number of stashed files/dir + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + + GIT_PROMPT_UPSTREAM=" {${Magenta}_UPSTREAM_${ResetColor}}" + + GIT_PROMPT_START_USER="[${BoldGreen}\u@\h${ResetColor} ${BoldYellow}\${?}${ResetColor} ${BoldBlue}\w${ResetColor}" + GIT_PROMPT_START_ROOT="[${BoldRed}\u@\h${ResetColor} ${BoldYellow}\${?}${ResetColor} ${BoldBlue}\w${ResetColor}" + GIT_PROMPT_END_USER="]$ " + GIT_PROMPT_END_ROOT="]# " + + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="⭑ " # This symbol is written after the branch, if the branch is not tracked +} + +reload_git_prompt_colors "Evermeet_Ubuntu" diff --git a/bash-git-prompt/share/themes/Georgi.bgptheme b/bash-git-prompt/share/themes/Georgi.bgptheme new file mode 100644 index 0000000..25d2d5e --- /dev/null +++ b/bash-git-prompt/share/themes/Georgi.bgptheme @@ -0,0 +1,21 @@ +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Georgi" + + GIT_PROMPT_PREFIX="${BoldCyan}(" + GIT_PROMPT_SUFFIX="${BoldCyan})" + GIT_PROMPT_BRANCH="${BoldCyan}" + GIT_PROMPT_SEPARATOR="${BoldCyan}|" + GIT_PROMPT_CHANGED="${BoldRed}+" + GIT_PROMPT_UNTRACKED="${BoldRed}…" + GIT_PROMPT_STAGED="${BoldGreen}●" + GIT_PROMPT_STASHED="${BoldCyan}⚑" + GIT_PROMPT_CONFLICTS="{BoldRed}✖" + GIT_PROMPT_CLEAN="${BoldCyan}✔" + + GIT_PROMPT_SYMBOLS_AHEAD="${BoldCyan}↑" + GIT_PROMPT_SYMBOLS_BEHIND="${BoldYellow}↓" + GIT_PROMPT_SYMBOLS_PREHASH="${BoldRed}:" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=" " +} + +reload_git_prompt_colors "Georgi" diff --git a/bash-git-prompt/share/themes/Minimal.bgptheme b/bash-git-prompt/share/themes/Minimal.bgptheme new file mode 100644 index 0000000..622388c --- /dev/null +++ b/bash-git-prompt/share/themes/Minimal.bgptheme @@ -0,0 +1,61 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. This version has been tweaked for Ubuntu standard terminal +# fonts. +# +# The prompt will use a Debian-style on the form +# +# relative-path-from-git-toplevel-dir bash-git-prompt-info +# HH:MM:SS ▶ +# +# The window title will have the form +# relative-path-from-git-toplevel-dir +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=Minimal +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# Imbibinebe [https://github.com/imbibinebe] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Minimal" + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + GIT_CONTAINER_FOLDER_FULLPATH=$(git rev-parse --show-toplevel 2> /dev/null) + GIT_CONTAINER_FOLDER=$(basename $GIT_CONTAINER_FOLDER_FULLPATH 2> /dev/null) + CURRENT_FULLPATH=$(pwd) + local PS1=$GIT_CONTAINER_FOLDER${CURRENT_FULLPATH#$GIT_CONTAINER_FOLDER_FULLPATH} + gp_set_window_title "$PS1" + echo -n "${BoldYellow}${PS1}${ResetColor}" + } + + Time12a="\$(date +%H:%M:%S)" + GIT_PROMPT_BRANCH="${BoldMagenta}" # the git branch that is active in the current directory + GIT_PROMPT_PREFIX="" # start of the git info string + GIT_PROMPT_SUFFIX="" # the end of the git info string + GIT_PROMPT_SEPARATOR="" # separates each item + GIT_PROMPT_STAGED=" ${Green}●" # the number of staged files/directories + GIT_PROMPT_CONFLICTS=" ${BoldRed}✖" # the number of files in conflict + GIT_PROMPT_CHANGED=" ${BoldBlue}✚" # the number of changed files + + # GIT_PROMPT_REMOTE=" " # the remote branch name (if any) and the symbols for ahead and behind + GIT_PROMPT_UNTRACKED=" ${Cyan}…" # the number of untracked files/dirs + GIT_PROMPT_STASHED=" ${BoldCyan}⚑" # the number of stashed files/dir + GIT_PROMPT_CLEAN=" ${BoldGreen}✔" # a colored flag indicating a "clean" repo + + local gp_end="_LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor}" + + GIT_PROMPT_START_USER="" + GIT_PROMPT_END_USER="${gp_end} ▶ " + GIT_PROMPT_END_ROOT="${gp_end} /!!!\ " + + GIT_PROMPT_COMMAND_OK="${Green} ✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${BoldRed} ✘-_LAST_COMMAND_STATE_" # indicator if the last command returned with an exit code of other than 0 +} + +reload_git_prompt_colors "Minimal" diff --git a/bash-git-prompt/share/themes/Plague_Doctor.bgptheme b/bash-git-prompt/share/themes/Plague_Doctor.bgptheme new file mode 100644 index 0000000..f399f68 --- /dev/null +++ b/bash-git-prompt/share/themes/Plague_Doctor.bgptheme @@ -0,0 +1,41 @@ +# Plague Doctor's bash-git-prompt theme. +# +# Note 1: The theme is designed to work only in GIT Repos. +# If one needs a coresponding prompt for non GIT locations, here is the code: +# +# if [ -f ]; then +# source +# MYPROMPT="${White}\A${ResetColor} ${BoldGreen}\\u${White}@${BoldYellow}\\h ${Cyan}\w${ResetColor}${BoldWhite} $ ${ResetColor}" +# else +# MYPROMPT="\[\033[37m\]\A \[\033[1m\]\[\033[32m\]\u\[\033[0m\]\[\033[37m\]@\[\033[1m\]\[\033[33m\]\h:\[\033[0m\]\[\033[36m\] \w\[\033[0m\]\[\033[1m\]\[\033[37m\] \$ \[\033[0m\]" +# fi +# export PS1=$MYPROMPT +# +# Note 2: The theme looks very nice with "FantasqueSansMono Nerd Font" https://github.com/ryanoasis/nerd-fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Plague Doctor" + GIT_PROMPT_ONLY_IN_REPO=1 + GIT_PROMPT_LEADING_SPACE=0 + + GIT_PROMPT_PREFIX="[ " + GIT_PROMPT_SUFFIX=" ]" + GIT_PROMPT_SEPARATOR=" |" + GIT_PROMPT_STAGED=" ${Red}● ${ResetColor}" + GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}" + GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_STASHED=" ${BoldBlue}⚑ ${ResetColor}" + GIT_PROMPT_CLEAN=" ${BoldGreen}✔ ${ResetColor}" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" + + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + GIT_PROMPT_START_USER="${BoldBlue} ${ResetColor}" + GIT_PROMPT_START_ROOT="${BoldRed}❖ ${ResetColor}" + GIT_PROMPT_END_USER="\n_LAST_COMMAND_INDICATOR_${White}${Time12a}${ResetColor} ${BoldGreen}\\u${White}@${BoldYellow}\\h ${Cyan}${PathShort}${ResetColor}${BoldWhite} $ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n_LAST_COMMAND_INDICATOR_${White}${Time12a}${ResetColor} ${BoldRed}\\u${White}@${BoldYellow}\\h ${Cyan}${PathShort}${ResetColor}${BoldRed} # ${ResetColor}" +} + +reload_git_prompt_colors "Plague Doctor" diff --git a/bash-git-prompt/share/themes/Single_line.bgptheme b/bash-git-prompt/share/themes/Single_line.bgptheme new file mode 100644 index 0000000..124c1d5 --- /dev/null +++ b/bash-git-prompt/share/themes/Single_line.bgptheme @@ -0,0 +1,11 @@ +# This is an alternative approach. Single line in git repo. +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER="${ResetColor} $ " + GIT_PROMPT_END_ROOT="${BoldRed} # " +} + +reload_git_prompt_colors "Single_line" + diff --git a/bash-git-prompt/share/themes/Single_line_NoExitState.bgptheme b/bash-git-prompt/share/themes/Single_line_NoExitState.bgptheme new file mode 100644 index 0000000..46f7000 --- /dev/null +++ b/bash-git-prompt/share/themes/Single_line_NoExitState.bgptheme @@ -0,0 +1,12 @@ +# This is an alternative approach. Single line in git repo. +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_NoExitState" + + GIT_PROMPT_COMMAND_FAIL="${Red}✘" + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${BoldYellow}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER="${ResetColor} $ " + GIT_PROMPT_END_ROOT="${BoldRed} # " +} + +reload_git_prompt_colors "Single_line_NoExitState" + diff --git a/bash-git-prompt/share/themes/Single_line_NoExitState_openSUSE.bgptheme b/bash-git-prompt/share/themes/Single_line_NoExitState_openSUSE.bgptheme new file mode 100644 index 0000000..e3580d7 --- /dev/null +++ b/bash-git-prompt/share/themes/Single_line_NoExitState_openSUSE.bgptheme @@ -0,0 +1,19 @@ +# This is a theme for gitprompt.sh, +# it uses the default openSUSE bash prompt style + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_NoExitState_openSUSE" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="\u@\h:\w" + GIT_PROMPT_START_ROOT="${BoldRed}\h:\w" + + GIT_PROMPT_END_USER="> " + GIT_PROMPT_END_ROOT=" # ${ResetColor}" +} + +reload_git_prompt_colors "Single_line_NoExitState_openSUSE" + diff --git a/bash-git-prompt/share/themes/Single_line_Solarized.bgptheme b/bash-git-prompt/share/themes/Single_line_Solarized.bgptheme new file mode 100644 index 0000000..44345c9 --- /dev/null +++ b/bash-git-prompt/share/themes/Single_line_Solarized.bgptheme @@ -0,0 +1,34 @@ +# This is an alternative approach. Single line in git repo. +# Theme optimised for Terminus and PowerLine compatible fonts. +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +define_helpers() { + PathShort="${BoldBlue}\u:${Cyan}\W" +} + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_Solarized" + + + GIT_PROMPT_PREFIX="[ " + GIT_PROMPT_SUFFIX=" ]" + GIT_PROMPT_SEPARATOR=" |" + GIT_PROMPT_STAGED=" ${Yellow}● ${ResetColor}" + GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}" + GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_STASHED=" ${BoldMagenta}⚑ ${ResetColor}" + GIT_PROMPT_CLEAN=" ${Green}✔ ${ResetColor}" + + GIT_PROMPT_COMMAND_FAIL="${Red}✘" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER="${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="${BoldRed} # " + + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Single_line_Solarized" diff --git a/bash-git-prompt/share/themes/Single_line_Ubuntu.bgptheme b/bash-git-prompt/share/themes/Single_line_Ubuntu.bgptheme new file mode 100644 index 0000000..7dd3a4f --- /dev/null +++ b/bash-git-prompt/share/themes/Single_line_Ubuntu.bgptheme @@ -0,0 +1,25 @@ +# This is an alternative approach. Single line in git repo. +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_Ubuntu" + + GIT_PROMPT_PREFIX="[ " + GIT_PROMPT_SUFFIX=" ]" + GIT_PROMPT_SEPARATOR=" |" + GIT_PROMPT_STAGED=" ${Red}● ${ResetColor}" + GIT_PROMPT_CONFLICTS=" ${Red}✖ ${ResetColor}" + GIT_PROMPT_CHANGED=" ${Blue}✚ ${ResetColor}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_STASHED=" ${BoldBlue}⚑ ${ResetColor}" + GIT_PROMPT_CLEAN=" ${BoldGreen}✔ ${ResetColor}" + + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${White}${Time12a}${ResetColor} ${Cyan}${PathShort}${ResetColor}" + GIT_PROMPT_END_USER="${ResetColor} $ " + GIT_PROMPT_END_ROOT="${BoldRed} # " + +} + +reload_git_prompt_colors "Single_line_Ubuntu" + diff --git a/bash-git-prompt/share/themes/Single_line_openSUSE.bgptheme b/bash-git-prompt/share/themes/Single_line_openSUSE.bgptheme new file mode 100644 index 0000000..396006a --- /dev/null +++ b/bash-git-prompt/share/themes/Single_line_openSUSE.bgptheme @@ -0,0 +1,19 @@ +# This is a theme for gitprompt.sh, +# it uses the default openSUSE bash prompt style with exit status + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Single_line_openSUSE" + GIT_PROMPT_BRANCH="${Cyan}" + GIT_PROMPT_UNTRACKED=" ${Cyan}…${ResetColor}" + GIT_PROMPT_CHANGED="${Yellow}✚ " + GIT_PROMPT_STAGED="${Magenta}●" + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${ResetColor}\u@\h:\w" + GIT_PROMPT_START_ROOT="_LAST_COMMAND_INDICATOR_ ${BoldRed}\h:\w" + + GIT_PROMPT_END_USER="${ResetColor}> " + GIT_PROMPT_END_ROOT=" # ${ResetColor}" +} + +reload_git_prompt_colors "Single_line_openSUSE" + diff --git a/bash-git-prompt/share/themes/Solarized.bgptheme b/bash-git-prompt/share/themes/Solarized.bgptheme new file mode 100644 index 0000000..d2448ba --- /dev/null +++ b/bash-git-prompt/share/themes/Solarized.bgptheme @@ -0,0 +1,13 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized" + GIT_PROMPT_STAGED="${Yellow}●" + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized" diff --git a/bash-git-prompt/share/themes/Solarized_Extravagant.bgptheme b/bash-git-prompt/share/themes/Solarized_Extravagant.bgptheme new file mode 100644 index 0000000..f87ccb4 --- /dev/null +++ b/bash-git-prompt/share/themes/Solarized_Extravagant.bgptheme @@ -0,0 +1,41 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts +# some modifications on colors +# added ruby prompt, and kernel version as well + +override_git_prompt_colors() { + if [ -e ~/.rvm/bin/rvm-prompt ]; then + RUBY_PROMPT='{$(~/.rvm/bin/rvm-prompt i v)}' + else + if command -v rbenv > /dev/null; then + RUBY_PROMPT='{$(rbenv version | sed -e "s/ (set.*$//")}' + fi + fi + Time12a="\$(date +%H:%M:%S)" + + GIT_PROMPT_THEME_NAME="Solarized Extravagant" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + KERNEL_PROMPT='‹$(uname -r)›' + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${BoldBlueFg}${Time12a} ${Green}${KERNEL_PROMPT} ${Cyan}${RUBY_PROMPT} ${Yellow}${PathShort}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + if [ -n "$SSH_CLIENT" ]; then + GIT_PROMPT_END_USER="\n${BoldRed} ➤ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} » ${ResetColor}" + else + GIT_PROMPT_END_USER="\n${BoldBlue} ➭ ${ResetColor}" + GIT_PROMPT_END_ROOT="\n${BoldRed} # ${ResetColor}" + fi + GIT_PROMPT_LEADING_SPACE=1 + GIT_PROMPT_PREFIX="${Cyan}[" + GIT_PROMPT_SUFFIX="${Cyan}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors "Solarized Extravagant" diff --git a/bash-git-prompt/share/themes/Solarized_NoExitState.bgptheme b/bash-git-prompt/share/themes/Solarized_NoExitState.bgptheme new file mode 100644 index 0000000..77f8e50 --- /dev/null +++ b/bash-git-prompt/share/themes/Solarized_NoExitState.bgptheme @@ -0,0 +1,16 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized NoExitState" + GIT_PROMPT_STAGED="${Yellow}●" + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔" + GIT_PROMPT_COMMAND_FAIL="${Red}✘" + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized NoExitState" \ No newline at end of file diff --git a/bash-git-prompt/share/themes/Solarized_NoExitState_Ubuntu.bgptheme b/bash-git-prompt/share/themes/Solarized_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..be6be1f --- /dev/null +++ b/bash-git-prompt/share/themes/Solarized_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,18 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# without the indicator of the last command state +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized NoExitState Ubuntu" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + GIT_PROMPT_START_USER="${Yellow}${PathShort}${ResetColor}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized NoExitState Ubuntu" diff --git a/bash-git-prompt/share/themes/Solarized_Ubuntu.bgptheme b/bash-git-prompt/share/themes/Solarized_Ubuntu.bgptheme new file mode 100644 index 0000000..99589c4 --- /dev/null +++ b/bash-git-prompt/share/themes/Solarized_Ubuntu.bgptheme @@ -0,0 +1,14 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# tweaked for Ubuntu terminal fonts + +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="Solarized Ubuntu" + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_END_USER=" \n${BoldBlue}${Time12a}${ResetColor} $ " + GIT_PROMPT_END_ROOT=" \n${BoldBlue}${Time12a}${ResetColor} # " +} + +reload_git_prompt_colors "Solarized Ubuntu" diff --git a/bash-git-prompt/share/themes/Solarized_UserHost.bgptheme b/bash-git-prompt/share/themes/Solarized_UserHost.bgptheme new file mode 100644 index 0000000..4eea2f1 --- /dev/null +++ b/bash-git-prompt/share/themes/Solarized_UserHost.bgptheme @@ -0,0 +1,23 @@ +# This theme for gitprompt.sh is optimized for the "Solarized Dark" and "Solarized Light" color schemes +# based on "Solarized Extravagant", with user@host on the second line and some things removed. + +function override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME='Solarized UserHost' + GIT_PROMPT_STAGED="${Yellow}● " + GIT_PROMPT_UNTRACKED="${Cyan}… " + GIT_PROMPT_STASHED="${BoldMagenta}⚑ " + GIT_PROMPT_CLEAN="${Green}✔ " + GIT_PROMPT_COMMAND_OK="${Green}✔ " + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " + + GIT_PROMPT_START_USER="_LAST_COMMAND_INDICATOR_ ${Yellow}${PathShort}" + GIT_PROMPT_START_ROOT="${GIT_PROMPT_START_USER}" + GIT_PROMPT_END_USER="\n${Blue}\\u${White}@${BoldBlue}\\h ${BoldRed} ➤ ${ResetColor} " + GIT_PROMPT_END_ROOT="\n${Blue}\\u${White}@${BoldBlue}\\h ${BoldRed} #️ ${ResetColor} " + GIT_PROMPT_LEADING_SPACE=1 + GIT_PROMPT_PREFIX="${Cyan}[" + GIT_PROMPT_SUFFIX="${Cyan}]" + GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING="✭" +} + +reload_git_prompt_colors 'Solarized UserHost' diff --git a/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle.bgptheme b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle.bgptheme new file mode 100644 index 0000000..1c1f5ee --- /dev/null +++ b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle.bgptheme @@ -0,0 +1,40 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle" + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_window_title "$PS1" + echo -n "${Yellow}[${PS1}]${ResetColor}" + } + + local gp_end=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor}" + + GIT_PROMPT_START_USER="" + GIT_PROMPT_END_USER="${gp_end} $ " + GIT_PROMPT_END_ROOT="${gp_end} # " +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle" diff --git a/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme new file mode 100644 index 0000000..bae8f57 --- /dev/null +++ b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState.bgptheme @@ -0,0 +1,40 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle_NoExitState +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState" + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_window_title "$PS1" + echo -n "${Yellow}[${PS1}]${ResetColor}" + } + + local gp_end=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor}" + + GIT_PROMPT_START_USER="" + GIT_PROMPT_END_USER="${gp_end} $ " + GIT_PROMPT_END_ROOT="${gp_end} # " +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle_NoExitState" diff --git a/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState_Ubuntu.bgptheme b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState_Ubuntu.bgptheme new file mode 100644 index 0000000..032dddc --- /dev/null +++ b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_NoExitState_Ubuntu.bgptheme @@ -0,0 +1,46 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. This version has been tweaked for Ubuntu standard terminal +# fonts. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle_NoExitState_Ubuntu +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_NoExitState_Ubuntu" + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_window_title "$PS1" + echo -n "${Yellow}[${PS1}]${ResetColor}" + } + + local gp_end=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor}" + + GIT_PROMPT_START_USER="" + GIT_PROMPT_END_USER="${gp_end} $ " + GIT_PROMPT_END_ROOT="${gp_end} # " + + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 + GIT_PROMPT_COMMAND_FAIL="${Red}✘ " # indicator if the last command returned with an exit code of other than 0 +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle_NoExitState_Ubuntu" diff --git a/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_Ubuntu.bgptheme b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_Ubuntu.bgptheme new file mode 100644 index 0000000..e24653a --- /dev/null +++ b/bash-git-prompt/share/themes/TruncatedPwd_WindowTitle_Ubuntu.bgptheme @@ -0,0 +1,45 @@ +############################################################################## +# Changes the prompt to a Debian-style one that truncates pwd to a max length +# depending on the terminal column width. Also uses the prompt_callback +# function of bash-git-prompt to set the window title to almost the same +# Debian-style. This version has been tweaked for Ubuntu standard terminal +# fonts. +# +# The prompt will use a Debian-style on the form +# +# [user@host: ] [bash-git-prompt-info] +# HH:MM $ +# +# The window title will have the form +# user@host: +# +# Example usage: +# if [ -f ~/.bash-git-prompt/gitprompt.sh ]; then +# GIT_PROMPT_THEME=TruncatedPwd_WindowTitle_Ubuntu +# source ~/.bash-git-prompt/gitprompt.sh +# fi +# +# oGre [https://github.com/ogr3] +############################################################################## +override_git_prompt_colors() { + GIT_PROMPT_THEME_NAME="TruncatedPwd_WindowTitle_Ubuntu" + + #Overrides the prompt_callback function used by bash-git-prompt + function prompt_callback { + local PS1="\u@\h: $(gp_truncate_pwd)" + gp_set_window_title "$PS1" + echo -n "${Yellow}[${PS1}]${ResetColor}" + } + + local gp_end=" _LAST_COMMAND_INDICATOR_\n${White}${Time12a}${ResetColor}" + + GIT_PROMPT_START_USER="" + GIT_PROMPT_END_USER="${gp_end} $ " + GIT_PROMPT_END_ROOT="${gp_end} # " + + GIT_PROMPT_STAGED="${Red}● " # the number of staged files/directories + GIT_PROMPT_CLEAN="${BoldGreen}✔ " # a colored flag indicating a "clean" repo + GIT_PROMPT_COMMAND_OK="${Green}✔ " # indicator if the last command returned with an exit code of 0 +} + +reload_git_prompt_colors "TruncatedPwd_WindowTitle_Ubuntu"