- Ajout des pull en retard dans le PS1

- Fix des couleurs en les securisant pour eviter de baver sur plusieurs lignes
This commit is contained in:
Frogg 2026-05-07 14:53:18 +02:00
parent 10de4b539c
commit 319310f86f
3 changed files with 81 additions and 37 deletions

View File

@ -1,8 +1,9 @@
# BUG
> PS1 quand on remonte l historique peut bug
> Si bare sur deux ligne bug du couleur fond
>
# SCRIPT
- VERIF SI NOM DE L ENV DISPO

View File

@ -3,26 +3,27 @@
# shellcheck disable=SC2034
# SETTING CUSTOM COLOR
NONE="\e[0m"
COLOR_WHITE="\e[1;37m"
#COLOR_WHITE='\033[38;5;255m'
COLOR_GREEN="\e[1;32m"
COLOR_RED="\e[38;5;196m"
COLOR_ORANGE="\e[38;5;208m"
COLOR_YELLOW="\e[1;33m"
COLOR_BLUE="\e[1;94m"
COLOR_CYAN="\e[36m"
COLOR_GRAY="\e[38;5;250m"
COLOR_LIGHT_GREEN='\033[38;5;154m'
COLOR_LIGHT_BLUE="\033[38;5;31m"
COLOR_LIGHT_RED="\033[01;91m"
COLOR_DARK_GRAY="\033[38;5;239m"
COLOR_DARK_GREEN='\033[38;5;28m'
NONE="\[\e[0m\]"
COLOR_WHITE="\[\e[1;37m\]"
COLOR_GREEN="\[\e[1;32m\]"
COLOR_RED="\[\e[38;5;196m\]"
COLOR_ORANGE="\[\033[38;5;208m\]"
COLOR_YELLOW="\[\e[1;33m\]"
COLOR_BLUE="\[\e[1;94m\]"
COLOR_CYAN="\[\e[36m\]"
COLOR_GRAY="\[\e[38;5;250m\]"
COLOR_LIGHT_GREEN="\[\033[38;5;154m\]"
COLOR_LIGHT_BLUE="\[\033[38;5;31m\]"
COLOR_LIGHT_RED="\[\033[01;91m\]"
COLOR_DARK_GRAY="\[\033[38;5;239m\]"
COLOR_DARK_GREEN="\[\033[38;5;28m\]"
COLOR_DARK_GREEN_BG='\033[48;5;28m'
COLOR_DARK_GRAY_BG='\033[48;5;239m'
COLOR_LIGHT_BLUE_BG='\033[48;5;31m'
COLOR_LIGHT_RED_BG='\033[01;101m'
# BACKGROUND
COLOR_ORANGE_BG="\[\033[48;5;208m\]"
COLOR_DARK_GREEN_BG="\[\033[48;5;28m\]"
COLOR_DARK_GRAY_BG="\[\033[48;5;239m\]"
COLOR_LIGHT_BLUE_BG="\[\033[48;5;31m\]"
COLOR_LIGHT_RED_BG="\[\033[01;101m\]"
# Les Asci sympas :
# 🐧 🌀 🍥 ✅ ❎ ❌ ⭕ ℹ️🔄🚨🆔 🆗 🆕 🆙

View File

@ -9,12 +9,12 @@ fi
#endregion
# Frogg version
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] >'
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m[\[\033[01;91m\u\[\033[01;34m@\[\033[01;91m\h\[\033[01;34m]\[\033[01;34m \w\[\033[01;37m >'
# Github https://gist.github.com/justintv/168835
#PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[0;32m\]\n$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] '
#PS1='\[\033[0;32m\[\033[0m\033[0;32m\u\[\033[0;36m @ \w\[\033[0;32m\n$(git branch 2>/dev/null | grep "^*" | colrm 1 2)\[\033[0;32m└─\[\033[0m\033[0;32m \$\[\033[0m\033[0;32m\[\033[0m '
# Mixed version
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m\][\[\033[01;91m\]\u\[\033[01;34m\]@\[\033[01;91m\]\h\[\033[01;34m\]]\[\033[01;34m\] \w\[\033[01;37m\] \n$(git branch --show-current 2>/dev/null)\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] '
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;34m[\[\033[01;91m\u\[\033[01;34m@\[\033[01;91m\h\[\033[01;34m]\[\033[01;34m \w\[\033[01;37m \n$(git branch --show-current 2>/dev/null)\[\033[0;32m└─\[\033[0m\033[0;32m \$\[\033[0m\033[0;32m\[\033[0m '
# ==========================================
# CONFIGURATION DES COULEURS (Modifie ici !)
@ -28,35 +28,76 @@ SEP="█►"
# LOGIQUE DU PROMPT (Ne pas toucher)
# ==========================================
get_git_status() {
local branch status current_bg current_color project
get_git_status() {
local branch status current_bg current_color project upstream behind
branch=$(git branch --show-current 2>/dev/null)
[[ -z "$branch" ]] && return
project=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null)
current_bg=$COLOR_DARK_GREEN_BG
current_color=$COLOR_DARK_GREEN
# --- SEGMENT PRINCIPAL (PROJET/BRANCHE) ---
current_bg="$COLOR_DARK_GREEN_BG"
current_color="$COLOR_DARK_GREEN"
status="🆗"
if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
current_bg=$COLOR_LIGHT_RED_BG
current_color=$COLOR_LIGHT_RED
#status="▼"
current_bg="$COLOR_LIGHT_RED_BG"
current_color="$COLOR_LIGHT_RED"
status="🔄"
fi
echo -ne "${COLOR_DARK_GRAY}${current_bg}${SEP}${COLOR_WHITE} [${project}/${branch}]${status}${current_bg}${NONE}${current_color}${SEP}${NONE}"
# Affichage du premier bloc
echo -ne "${COLOR_DARK_GRAY}${current_bg}${SEP}$COLOR_WHITE [${project}/${branch}]${status}"
# --- SEGMENT DYNAMIQUE (BEHIND / PULL) ---
# On vérifie si on a un upstream (une branche distante)
upstream=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null)
if [[ -n "$upstream" ]]; then
# On compte le nombre de commits de retard
behind=$(git rev-list --count HEAD..$upstream 2>/dev/null)
if [[ "$behind" -gt 0 ]]; then
# Raccord entre le segment précédent et le segment orange
# On utilise la couleur de fond du précédent pour le texte du SEP
echo -ne "${current_color}${COLOR_ORANGE_BG}${SEP}$COLOR_WHITE pull $behind 🆙"
# On met à jour les variables pour le SEP de fin
current_bg="${COLOR_ORANGE_BG}"
current_color="${COLOR_ORANGE}"
fi
fi
# --- FIN DU BLOC ---
echo -ne "${current_bg}${NONE}${current_color}${SEP}${NONE}"
}
get_git_status_OK() {
local branch status current_bg current_color project
branch=$(git branch --show-current 2>/dev/null)
[[ -z "$branch" ]] && return
project=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null)
# Initialisation des couleurs (On utilise des variables propres)
current_bg="$COLOR_DARK_GREEN_BG"
current_color="$COLOR_DARK_GREEN"
status="🆗"
if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
current_bg="$COLOR_LIGHT_RED_BG"
current_color="$COLOR_LIGHT_RED"
status="🔄"
fi
echo -ne "${COLOR_DARK_GRAY}${current_bg}${SEP}$COLOR_WHITE TEST[${project}/${branch}]${status}${current_bg}${NONE}${current_color}${SEP}${NONE}"
}
set_ps1() {
local EXIT P1 P2 GIT_PART ARROW_C
EXIT="$?"
# Segment 1 : User (Bleu)
# Segment 1 : User (Bleu) - Ajout des
P1="${COLOR_LIGHT_BLUE_BG}${COLOR_WHITE} <\u@$(hostname -f)>${NONE}"
# Segment 2 : Chemin (Gris) avec raccord Bleu
@ -66,14 +107,15 @@ set_ps1() {
GIT_PART=$(get_git_status)
if [[ -n "$GIT_PART" ]]; then
# On ne met pas d'espace avant ${GIT_PART} car le SEP s'en occupe
PS1="\n${P1}${P2} ${GIT_PART}"
else
PS1="\n${P1}${P2} ${NONE}${COLOR_DARK_GRAY}${SEP}${NONE}"
fi
# Ligne 2
ARROW_C=${COLOR_GREEN}
[[ $EXIT != 0 ]] && ARROW_C=${COLOR_LIGHT_RED}
# Ligne 2 : Flèche de retour
ARROW_C="${COLOR_GREEN}"
[[ $EXIT != 0 ]] && ARROW_C="${COLOR_LIGHT_RED}"
PS1+="\n${ARROW_C}└─${NONE} "
}