Skip to content

Instantly share code, notes, and snippets.

@tdd
Last active April 17, 2024 10:04

Revisions

  1. tdd revised this gist Jul 27, 2015. 1 changed file with 20 additions and 15 deletions.
    35 changes: 20 additions & 15 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,31 @@
    # Envie de ZSH ? https://github.com/robbyrussell/oh-my-zsh
    #
    # Si vous n'avez pas déjà un /etc/bash_completion.d/git, regardez où se trouve le script de complétion
    # sur votre plate-forme et chargez-le explicitement. Par exemple, avec Homebrew sur OSX, ça donnerait
    # un truc du genre :
    # STEP 1: ENSURE COMPLETION AND PROMPT FUNCTION ARE LOADED
    # ========================================================

    # source /usr/local/Cellar/git/1.7.10.4/etc/bash_completion.d/git-completion.bash
    # OPTION 1: If on OSX using Homebrew:
    #
    # source /usr/local/etc/bash_completion.d/git-completion.bash
    # source /usr/local/etc/bash_completion.d/git-prompt.sh
    # source $(brew --prefix)/etc/bash_completion.d/git-prompt.sh
    # source $(brew --prefix)/etc/bash_completion.d/git-completion.bash

    # Éviter l'auto-édit en merge réussi à partir de Git 2.0
    # OPTION 2: If on OSX using built-in Git (also works on ZSH):
    #
    # source /usr/local/git/contrib/completion/git-prompt.sh
    # source /usr/local/git/contrib/completion/git-completion.bash

    export GIT_MERGE_AUTOEDIT=no
    # OPTION 3: If on Ubuntu/Debian/Mint using standard packages, or on Windows: pre-loaded!

    # Exportez au moins ces trois activations : modified/staged, stash present, untracked
    # STEP 2: CONFIGURE THE PROMPT
    # ============================

    # Configure `__git_ps1` to tell us as much as possible
    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1
    export GIT_PS1_SHOWUPSTREAM=verbose GIT_PS1_DESCRIBE_STYLE=branch GIT_PS1_SHOWCOLORHINTS=1
    export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\] '
    export GIT_PS1_HIDE_IF_PWD_IGNORED=1

    # Ou si tu ne veux pas des couleurs de dingue, plutôt celui du dessous :
    # Colorful prompt for Bash!
    export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\] '

    # Or if you want the basic prompt, no colors, no timestamps, just regular + Git info:
    # export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '

    # Envie de trucs carrément plus bourrins ?
    # https://github.com/matthewmccullough/dotfiles/blob/master/bash_gitprompt
    # Unrelated but useful: avoid auto-édit on successful merges, starting with Git 2.0
    export GIT_MERGE_AUTOEDIT=no
  2. tdd revised this gist Jan 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ export GIT_MERGE_AUTOEDIT=no

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1
    export GIT_PS1_SHOWUPSTREAM=verbose GIT_PS1_DESCRIBE_STYLE=branch GIT_PS1_SHOWCOLORHINTS=1
    export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\]'
    export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\] '

    # Ou si tu ne veux pas des couleurs de dingue, plutôt celui du dessous :
    # export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '
  3. tdd revised this gist Jan 30, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -17,10 +17,10 @@ export GIT_MERGE_AUTOEDIT=no

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1
    export GIT_PS1_SHOWUPSTREAM=verbose GIT_PS1_DESCRIBE_STYLE=branch GIT_PS1_SHOWCOLORHINTS=1
    export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '
    export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\]'

    # Ou si tu veux des couleurs de dingue, plutôt celui du dessous :
    # export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\]'
    # Ou si tu ne veux pas des couleurs de dingue, plutôt celui du dessous :
    # export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '

    # Envie de trucs carrément plus bourrins ?
    # https://github.com/matthewmccullough/dotfiles/blob/master/bash_gitprompt
  4. tdd revised this gist Jan 30, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,10 @@
    # source /usr/local/etc/bash_completion.d/git-completion.bash
    # source /usr/local/etc/bash_completion.d/git-prompt.sh

    # Éviter l'auto-édit en merge réussi à partir de Git 2.0

    export GIT_MERGE_AUTOEDIT=no

    # Exportez au moins ces trois activations : modified/staged, stash present, untracked

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1
  5. tdd revised this gist Oct 17, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,8 @@ export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFI
    export GIT_PS1_SHOWUPSTREAM=verbose GIT_PS1_DESCRIBE_STYLE=branch GIT_PS1_SHOWCOLORHINTS=1
    export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '

    # Ou si tu veux des couleurs de dingue, plutôt celui du dessous :
    # export PS1='\[\e[0;36m\][\A] \u@\h:\[\e[0m\e[0;32m\]\W\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0;37m\] \$\[\e[0m\]'

    # Envie de trucs carrément plus bourrins ?
    # https://github.com/matthewmccullough/dotfiles/blob/master/bash_gitprompt
  6. tdd revised this gist Oct 9, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,7 @@
    # Exportez au moins ces trois activations : modified/staged, stash present, untracked

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1
    export GIT_PS1_SHOWUPSTREAM=verbose GIT_PS1_DESCRIBE_STYLE=branch GIT_PS1_SHOWCOLORHINTS=1
    export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '

    # Envie de trucs carrément plus bourrins ?
  7. tdd revised this gist Jan 30, 2013. 1 changed file with 16 additions and 5 deletions.
    21 changes: 16 additions & 5 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,18 @@
    # .git-completion.bash est en fait fourni par les paquets Git divers et variés…
    # * Paquet Ubuntu/Debian : /etc/bash_completion.d/git (probablement déjà chargé par votre shell Bash)
    # * Homebrew (OSX) : /usr/local/Cellar/git/1.7.4.1/etc/bash_completion.d/git-completion.bash
    # Envie de ZSH ? https://github.com/robbyrussell/oh-my-zsh
    #
    # Si vous n'avez pas déjà un /etc/bash_completion.d/git, regardez où se trouve le script de complétion
    # sur votre plate-forme et chargez-le explicitement. Par exemple, avec Homebrew sur OSX, ça donnerait
    # un truc du genre :

    source "$HOME/.git-completion.bash" &&
    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 &&
    # source /usr/local/Cellar/git/1.7.10.4/etc/bash_completion.d/git-completion.bash
    #
    # source /usr/local/etc/bash_completion.d/git-completion.bash
    # source /usr/local/etc/bash_completion.d/git-prompt.sh

    # Exportez au moins ces trois activations : modified/staged, stash present, untracked

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1
    export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '

    # Envie de trucs carrément plus bourrins ?
    # https://github.com/matthewmccullough/dotfiles/blob/master/bash_gitprompt
  8. tdd revised this gist Jan 25, 2012. 1 changed file with 6 additions and 113 deletions.
    119 changes: 6 additions & 113 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -1,114 +1,7 @@
    # Scavenged from Git 1.6.5.x contrib/completion/git_completion.bash
    # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
    # returns text to add to bash PS1 prompt (includes branch name)
    __gitdir ()
    {
    if [ -z "${1-}" ]; then
    if [ -n "${__git_dir-}" ]; then
    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
    }
    __git_ps1 ()
    {
    local g="$(__gitdir)"
    if [ -n "$g" ]; then
    local r
    local b
    if [ -f "$g/rebase-merge/interactive" ]; then
    r="|REBASE-i"
    b="$(cat "$g/rebase-merge/head-name")"
    elif [ -d "$g/rebase-merge" ]; then
    r="|REBASE-m"
    b="$(cat "$g/rebase-merge/head-name")"
    else
    if [ -d "$g/rebase-apply" ]; then
    if [ -f "$g/rebase-apply/rebasing" ]; then
    r="|REBASE"
    elif [ -f "$g/rebase-apply/applying" ]; then
    r="|AM"
    else
    r="|AM/REBASE"
    fi
    elif [ -f "$g/MERGE_HEAD" ]; then
    r="|MERGING"
    elif [ -f "$g/BISECT_LOG" ]; then
    r="|BISECTING"
    fi
    # .git-completion.bash est en fait fourni par les paquets Git divers et variés…
    # * Paquet Ubuntu/Debian : /etc/bash_completion.d/git (probablement déjà chargé par votre shell Bash)
    # * Homebrew (OSX) : /usr/local/Cellar/git/1.7.4.1/etc/bash_completion.d/git-completion.bash

    b="$(git symbolic-ref HEAD 2>/dev/null)" || {

    b="$(
    case "${GIT_PS1_DESCRIBE_STYLE-}" in
    (contains)
    git describe --contains HEAD ;;
    (branch)
    git describe --contains --all HEAD ;;
    (describe)
    git describe HEAD ;;
    (* | default)
    git describe --exact-match HEAD ;;
    esac 2>/dev/null)" ||

    b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
    b="unknown"
    b="($b)"
    }
    fi

    local w
    local i
    local s
    local u
    local c

    if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
    if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
    c="BARE:"
    else
    b="GIT_DIR!"
    fi
    elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
    if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
    if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
    git diff --no-ext-diff --ignore-submodules \
    --quiet --exit-code || w="*"
    if git rev-parse --quiet --verify HEAD >/dev/null; then
    git diff-index --cached --quiet \
    --ignore-submodules HEAD -- || i="+"
    else
    i="#"
    fi
    fi
    fi
    if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
    git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
    fi

    if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
    if [ -n "$(git ls-files --others --exclude-standard)" ]; then
    u="%"
    fi
    fi
    fi

    if [ -n "${1-}" ]; then
    printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
    else
    printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
    fi
    fi
    }

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWSTASHSTATE=1

    # En fait l'important ici c'est le "\033[1;32m\]$(__git_ps1)\[\033[0m\]", le reste c'est mon prompt usuel…
    export PS1='\[\033[0;37m\]\u@\h:\[\033[0;33m\]\W\[\033[0m\]\[\033[1;32m\]$(__git_ps1)\[\033[0m\] \$ '
    source "$HOME/.git-completion.bash" &&
    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 &&
    export PS1='\u@\h:\W$(__git_ps1 " (%s)")\$ '
  9. tdd revised this gist Jul 13, 2010. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -109,4 +109,6 @@ __git_ps1 ()
    }

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWSTASHSTATE=1

    # En fait l'important ici c'est le "\033[1;32m\]$(__git_ps1)\[\033[0m\]", le reste c'est mon prompt usuel…
    export PS1='\[\033[0;37m\]\u@\h:\[\033[0;33m\]\W\[\033[0m\]\[\033[1;32m\]$(__git_ps1)\[\033[0m\] \$ '
  10. tdd created this gist Jul 13, 2010.
    112 changes: 112 additions & 0 deletions config-bash-pour-un-prompt-git-de-tueur.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,112 @@
    # Scavenged from Git 1.6.5.x contrib/completion/git_completion.bash
    # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
    # returns text to add to bash PS1 prompt (includes branch name)
    __gitdir ()
    {
    if [ -z "${1-}" ]; then
    if [ -n "${__git_dir-}" ]; then
    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
    }
    __git_ps1 ()
    {
    local g="$(__gitdir)"
    if [ -n "$g" ]; then
    local r
    local b
    if [ -f "$g/rebase-merge/interactive" ]; then
    r="|REBASE-i"
    b="$(cat "$g/rebase-merge/head-name")"
    elif [ -d "$g/rebase-merge" ]; then
    r="|REBASE-m"
    b="$(cat "$g/rebase-merge/head-name")"
    else
    if [ -d "$g/rebase-apply" ]; then
    if [ -f "$g/rebase-apply/rebasing" ]; then
    r="|REBASE"
    elif [ -f "$g/rebase-apply/applying" ]; then
    r="|AM"
    else
    r="|AM/REBASE"
    fi
    elif [ -f "$g/MERGE_HEAD" ]; then
    r="|MERGING"
    elif [ -f "$g/BISECT_LOG" ]; then
    r="|BISECTING"
    fi

    b="$(git symbolic-ref HEAD 2>/dev/null)" || {

    b="$(
    case "${GIT_PS1_DESCRIBE_STYLE-}" in
    (contains)
    git describe --contains HEAD ;;
    (branch)
    git describe --contains --all HEAD ;;
    (describe)
    git describe HEAD ;;
    (* | default)
    git describe --exact-match HEAD ;;
    esac 2>/dev/null)" ||

    b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." ||
    b="unknown"
    b="($b)"
    }
    fi

    local w
    local i
    local s
    local u
    local c

    if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
    if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
    c="BARE:"
    else
    b="GIT_DIR!"
    fi
    elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
    if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ]; then
    if [ "$(git config --bool bash.showDirtyState)" != "false" ]; then
    git diff --no-ext-diff --ignore-submodules \
    --quiet --exit-code || w="*"
    if git rev-parse --quiet --verify HEAD >/dev/null; then
    git diff-index --cached --quiet \
    --ignore-submodules HEAD -- || i="+"
    else
    i="#"
    fi
    fi
    fi
    if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
    git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
    fi

    if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then
    if [ -n "$(git ls-files --others --exclude-standard)" ]; then
    u="%"
    fi
    fi
    fi

    if [ -n "${1-}" ]; then
    printf "$1" "$c${b##refs/heads/}$w$i$s$u$r"
    else
    printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r"
    fi
    fi
    }

    export GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWSTASHSTATE=1
    export PS1='\[\033[0;37m\]\u@\h:\[\033[0;33m\]\W\[\033[0m\]\[\033[1;32m\]$(__git_ps1)\[\033[0m\] \$ '