From 399c89c03bf78fabc8ec401a44283af4ebdedce4 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Thu, 25 Jul 2013 19:14:15 +0200 Subject: [PATCH] =?utf8?q?En=20fait=20on=20n'a=20pas=20besoin=20que=20cett?= =?utf8?q?e=20fonction=20soit=20comment=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .bashrc | 107 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/.bashrc b/.bashrc index 041f2f9..d3d5e47 100644 --- a/.bashrc +++ b/.bashrc @@ -37,58 +37,58 @@ fi [ -d ~/.bash_completion.d/ ] && for f in ~/.bash_completion.d/*; do source $f; done -#~# # +-----+ -#~# # | VCS | -#~# # +-----+ -#~# -#~# # Définition de fonction pour pouvoir afficher dans le prompt -#~# # des infos quand on est dans un dépôt versionné -#~# -#~# find_up () { -#~# path="$1" -#~# shift 1 -#~# while [[ "`readlink -f -- \"$path\"`" != "/" ]]; -#~# do -#~# find "$path" -maxdepth 1 -mindepth 1 "$@" -#~# path=${path}/.. -#~# done -#~# } -#~# -#~# get_vcs_info () { -#~# # Donne les infos sur le dépôt VCS courant. -#~# local LBRANCH LTYPE BRANCH TYPE DIR -#~# declare -a DIR -#~# declare -A TYPE -#~# declare -A BRANCH -#~# DIR[0]=".git" -#~# DIR[1]=".hg" -#~# DIR[2]="_darcs" -#~# DIR[3]=".svn" -#~# TYPE[.git]="git" -#~# TYPE[.hg]="mercurial" -#~# TYPE[_darcs]="darcs" -#~# TYPE[.svn]="svn" -#~# BRANCH[.git]='git branch 2>/dev/null | sed -r "s/^[^*].*$//" | paste -s -d "" | sed -r "s/^[*] //"' -#~# BRANCH[.hg]='hg branch 2>/dev/null' -#~# BRANCH[_darcs]="darcs show repo 2>/dev/null| egrep '^ *Cache' | sed 's@.*/\([^/]*\),.*@\1@'" -#~# BRANCH[.svn]="svn info 2>/dev/null | head -n 6 | tail -n 1" -#~# -#~# DIR=$(eval "find_up \"$PWD\" -name \"\"$(printf -- ' -o -name "%s"' "${DIR[@]}") | head -n 1") -#~# if [ -n "$DIR" ]; then -#~# DIR=$(basename "$DIR") -#~# LBRANCH=$(eval "${BRANCH[$DIR]}") -#~# LTYPE="${TYPE[$DIR]}" -#~# if [ "$color_prompt" = yes ]; then -#~# VCS_info="${nocolor}${vcs_symbols_color}(${nocolor}$LTYPE${vcs_symbols_color})-${vcs_symbols_color}[${vcs_branch_color}$LBRANCH${vcs_symbols_color}]${nocolor}" -#~# else -#~# VCS_info="($LTYPE)-[$LBRANCH]" -#~# fi -#~# VCS_size=$((${#LTYPE}+${#LBRANCH}+5)) -#~# else -#~# VCS_info="" -#~# VCS_size=0 -#~# fi -#~# } +# +-----+ +# | VCS | +# +-----+ + +# Définition de fonction pour pouvoir afficher dans le prompt +# des infos quand on est dans un dépôt versionné + +find_up () { + path="$1" + shift 1 + while [[ "`readlink -f -- \"$path\"`" != "/" ]]; + do + find "$path" -maxdepth 1 -mindepth 1 "$@" + path=${path}/.. + done +} + +get_vcs_info () { + # Donne les infos sur le dépôt VCS courant. + local LBRANCH LTYPE BRANCH TYPE DIR + declare -a DIR + declare -A TYPE + declare -A BRANCH + DIR[0]=".git" + DIR[1]=".hg" + DIR[2]="_darcs" + DIR[3]=".svn" + TYPE[.git]="git" + TYPE[.hg]="mercurial" + TYPE[_darcs]="darcs" + TYPE[.svn]="svn" + BRANCH[.git]='git branch 2>/dev/null | sed -r "s/^[^*].*$//" | paste -s -d "" | sed -r "s/^[*] //"' + BRANCH[.hg]='hg branch 2>/dev/null' + BRANCH[_darcs]="darcs show repo 2>/dev/null| egrep '^ *Cache' | sed 's@.*/\([^/]*\),.*@\1@'" + BRANCH[.svn]="svn info 2>/dev/null | head -n 6 | tail -n 1" + + DIR=$(eval "find_up \"$PWD\" -name \"\"$(printf -- ' -o -name "%s"' "${DIR[@]}") | head -n 1") + if [ -n "$DIR" ]; then + DIR=$(basename "$DIR") + LBRANCH=$(eval "${BRANCH[$DIR]}") + LTYPE="${TYPE[$DIR]}" + if [ "$color_prompt" = yes ]; then + VCS_info="${nocolor}${vcs_symbols_color}(${nocolor}$LTYPE${vcs_symbols_color})-${vcs_symbols_color}[${vcs_branch_color}$LBRANCH${vcs_symbols_color}]${nocolor}" + else + VCS_info="($LTYPE)-[$LBRANCH]" + fi + VCS_size=$((${#LTYPE}+${#LBRANCH}+5)) + else + VCS_info="" + VCS_size=0 + fi +} # Pour avoir le bon umask en fonction du dossier où on se trouve @@ -165,7 +165,8 @@ function prompt_command local pwd ERR DATE PROMPT DIR POST_DIR (( SAVE_COLUMNS == COLUMNS )) || gen_minus_line - #~# #dépend de la section VCS + #~# # À décommenter si on veut des infos + #~# # quand on se trouve dans un dépôt versionné #~# get_vcs_info pwd=${PWD/#$HOME/'~'} -- 2.39.2