[git] quel prompt ?

Autres projets et contributions
djipey
Chu Ko Nu
Messages : 437
Inscription : sam. 04 juin 2011, 10:13

[git] quel prompt ?

Message par djipey »

Bonsoir.

Je cherche un prompt sympa et simple pour git, avec le nombre d'ajouts/retraits, le nombre de commits ahead, et quelques indicateurs visuels pour les fichiers modifiés, non trackés, stached, etc.

Est-ce que vous en connaitriez un ?

Bien à vous.
Avatar de l’utilisateur
Rolinh
Chu Ko Nu
Messages : 392
Inscription : sam. 15 août 2009, 09:15
Localisation : Suisse

Re: [git] quel prompt ?

Message par Rolinh »

Salut,

Je m'en suis fait un pour zsh. Voici les parties pertinentes de mon zshrc:

Code : Tout sélectionner

# {{ Stuff for VCS infos

local reset white green red blue yellow
reset="%{${reset_color}%}"
white="%{$fg[white]%}"
green="%{$fg_bold[green]%}"
red="%{$fg[red]%}"
blue="%{$fg[blue]%}"
yellow="%{$fg[yellow]%}"

autoload -Uz vcs_info

zstyle ':vcs_info:*' enable git hg
zstyle ':vcs_info:(hg*|git*):*' get-revision true
zstyle ':vcs_info:(hg*|git*):*' check-for-changes true

#zstyle ':vcs_info:hg*' formats "(%s)[%i%u %b %m]" # rev+changes branch misc
zstyle ':vcs_info:hg*' formats "[%i%u %b %m]" # rev+changes branch misc
#zstyle ':vcs_info:hg*' actionformats "(%s|${red}%a${white})[%i%u %b %m]"
zstyle ':vcs_info:hg*' actionformats "${red}%a ${white}[%i%u ${blue}%b${white}%m]"

zstyle ':vcs_info:hg*:*' get-bookmarks true
zstyle ':vcs_info:hg*:*' get-mq true

zstyle ':vcs_info:hg*:*' get-unapplied true
zstyle ':vcs_info:hg*:*' patch-format "mq(%g):%n/%c %p"
zstyle ':vcs_info:hg*:*' nopatch-format "mq(%g):%n/%c %p"

zstyle ':vcs_info:hg*:*' unstagedstr "${green}+${white}"
zstyle ':vcs_info:hg*:*' hgrevformat "%r" # only show local rev.
zstyle ':vcs_info:hg*:*' branchformat "%b" # only show branch

#zstyle ':vcs_info:git*' formats "(%s) %12.12i %c%u %b%m" # hash changes branch misc
zstyle ':vcs_info:git*' formats "%c%u %b%m" # hash changes branch misc
zstyle ':vcs_info:git*' actionformats "(%s|${white}%a) %12.12i %c%u %b%m"

zstyle ':vcs_info:git*:*' stagedstr "${green}S${white}"
zstyle ':vcs_info:git*:*' unstagedstr "${red}U${white}"

# zstyle ':vcs_info:hg:*:-all-' command fakehg
# zstyle ':vcs_info:*+*:*' debug true

zstyle ':vcs_info:hg*+set-hgrev-format:*' hooks hg-hashfallback
zstyle ':vcs_info:hg*+set-message:*' hooks mq-vcs
#zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-st

### Dynamically set hgrevformat based on if the local rev is available
# We don't always know the local revision, e.g. if use-simple is set
# Truncate long hash to 12-chars but also allow for multiple parents
function +vi-hg-hashfallback() {
    if [[ -z ${hook_com[localrev]} ]] ; then
        local -a parents

        parents=( ${(s:+:)hook_com[hash]} )
        parents=( ${(@r:12:)parents} )
        hook_com[rev-replace]="${(j:+:)parents}"

        ret=1
    fi
}

### Show when mq itself is under version control
function +vi-mq-vcs() {
    # if [[ -d ${hook_com[base]}/.hg/patches/.hg ]]; then
        # hook_com[hg-mqpatch-string]="mq:${hook_com[hg-mqpatch-string]}"
    # fi
}

# Show remote ref name and number of commits ahead-of or behind
function +vi-git-st() {
    local ahead behind remote
    local -a gitstatus

    # Are we on a remote-tracking branch?
    remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
        --symbolic-full-name --abbrev-ref 2>/dev/null)}

    if [[ -n ${remote} ]] ; then
        # for git prior to 1.7
        # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
        ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
        (( $ahead )) && gitstatus+=( "${green}+${ahead}${white}" )

        # for git prior to 1.7
        # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
        behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
        (( $behind )) && gitstatus+=( "${red}-${behind}${white}" )

        #hook_com[branch]="${hook_com[branch]} [${remote} ${(j:/:)gitstatus}]"
        hook_com[branch]="[${blue}${hook_com[branch]}${white}]"
    fi
}

# Show count of stashed changes
function +vi-git-stash() {
    local -a stashes

    if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
        stashes=$(git stash list 2>/dev/null | wc -l)
        #hook_com[misc]+=" (${stashes} stashed)"
        hook_com[misc]+="(${red}${stashes} ${white}stashed)"
    fi
}

# Show count of untracked files
function +vi-git-untracked(){
	if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
		git status --porcelain | grep '??' &> /dev/null ; then
		# This will show the marker if there are any untracked files in repo.
		# If instead you want to show the marker only if there are untracked
		# files in $PWD, use:
		#[[ -n $(git ls-files --others --exclude-standard) ]] ; then
		local nb_untracked=$(git status --porcelain | grep "\? \?" | wc -l)
		local nb_up=$(git status --porcelain | grep "M" | wc -l)
		hook_com[staged]+="${white}$nb_untracked${red}N ${white}$nb_up"
	fi
}

# }}

# (...)

# {{{ precmd()

function precmd {
  title

if [[ $(uname -s) == Linux ]]; then
  vcs_info
fi

# (...) 

  # Prompt on the right, displayed when in a VCS repository
if [[ $(uname -s) == Linux ]]; then
  RPS1="${vcs_info_msg_0_}%{${reset_color}%}"
fi
}

# }}}
Un petit peu d'explications ici.
Avatar de l’utilisateur
bennyboy
archer de cavalerie
Messages : 154
Inscription : dim. 12 oct. 2008, 20:36

Re: [git] quel prompt ?

Message par bennyboy »

Perso j'utilise ohmyzsh qui fait plus ou moins ce que tu souhaites "out of the box".
Mon wiki
Mon Github
T'es tellement no-life que t'aimerais être un PC pour redémarrer ta vie en mode sans échec !
djipey
Chu Ko Nu
Messages : 437
Inscription : sam. 04 juin 2011, 10:13

Re: [git] quel prompt ?

Message par djipey »

Je n'utilise pas (encore) zsh. En bash peut-être ?
djipey
Chu Ko Nu
Messages : 437
Inscription : sam. 04 juin 2011, 10:13

Re: [git] quel prompt ?

Message par djipey »

J'ai installé zsh et ohmyzsh, mais impossible d'afficher tout ce que je souhaite sur git, je ne sais pas quel plugin utiliser. Un peu d'aide à ce niveau ?
Avatar de l’utilisateur
Rolinh
Chu Ko Nu
Messages : 392
Inscription : sam. 15 août 2009, 09:15
Localisation : Suisse

Re: [git] quel prompt ?

Message par Rolinh »

Je ne connais pas ohmyzsh mais... qu'est-ce qui ne va pas dans ma solution?
djipey
Chu Ko Nu
Messages : 437
Inscription : sam. 04 juin 2011, 10:13

Re: [git] quel prompt ?

Message par djipey »

Apriori rien, mais ohmyzsh a l'air très complet, et vient avec un paquet de plugins. Je ne voudrais pas ré-écrire quelque chose qui est peut-être déjà fourni.
Répondre