- Correction de la gestion des couleurs

- Ajout de l information pour la commande alias
- debut d'ajot d'alias GIT
This commit is contained in:
Frogg 2026-05-07 15:53:15 +02:00
parent 319310f86f
commit fbf7347d89
8 changed files with 94 additions and 78 deletions

16
TODO.md
View File

@ -1,9 +1,3 @@
# 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
@ -15,13 +9,13 @@
- conf nom de machine
- menu qui propose des choix
- faire la connexion git sans faire pass a chaque fois en script
- AJOUTER PLUS D ALIAS
- AJOUTER PLUS DE CMD
- AJOUTER PLUS DE PATH
Ajouter des alias GIT
> mettre le reset
> git fetch origin
> git reset --hard origin/main
git clean -fd
>> rename la machine
hostnamectl set-hostname gitea

View File

@ -27,6 +27,14 @@ CMD_LIST_CONFIG_JSON=$(cat <<EOF
{"label": "Network stats", "cmd": "htop", "bin": "htop"}
]
}
{
"section": "UTILS",
"items": [
{"label": "Display loaded functions", "cmd": "declare -F"},
]
}
]
EOF
)

View File

@ -2,28 +2,36 @@
# shellcheck disable=SC2034
# SETTING CUSTOM COLOR
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\]"
# ==========================================
# 1. COULEURS STANDARDS (Pour echo / scripts)
# ==========================================
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"
# BACKGROUND STANDARDS
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"
# Fonction pour sécuriser une couleur pour le PS1
color_secure() {
echo -ne "\[$1\]"
}
# 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

@ -5,6 +5,12 @@
#region JSON
CONF_LIST_CONFIG_JSON=$(cat <<EOF
[
{
"section": "SYSTEM",
"items": [
{"label": "Env vars", "cmd": "/etc/environment"},
]
},
{
"section": "APACHE",
"items": [

14
func/git.sh Normal file
View File

@ -0,0 +1,14 @@
function git-reset(){
local branch
# Récupère le nom de la branche actuelle
branch=$(git branch --show-current 2>/dev/null)
[[ -z "$branch" ]] && echo "Pas dans un dépôt Git" && return 1
git fetch origin
git reset --hard origin/"${1:$branch}"
git clean -fd
echo -e "${COLOR_GREEN}✅ Dépôt synchronisé et nettoyé.${NONE}"
}

View File

@ -28,7 +28,7 @@ alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias ports='netstat -tulanp'
alias psg='ps aux | grep -i'
alias top='htop'
#alias top='htop'
alias cpu='top -o %CPU'
alias mem='top -o %MEM'
alias hdd='ncdu'
@ -44,10 +44,13 @@ alias wlog='tail -fn 100 /var/log/apache2/access.log /var/log/apache2/error.log'
#endregion
#region Shortcut GIT
# LOAD GIT FUNCS
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
fi
. "${WELCOME_SCRIPT_PATH}/func/git.sh"
alias gsync='git-reset'
#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\] >'
# 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\] '
# 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\] '

View File

@ -8,7 +8,7 @@ fi
# Infos
echo ""
echo -e "${COLOR_YELLOW}Type ${COLOR_WHITE}cmd${COLOR_YELLOW}, ${COLOR_WHITE}conf ${COLOR_YELLOW}or ${COLOR_WHITE}colors ${COLOR_YELLOW}for more information...${NONE}"
echo -e "${COLOR_YELLOW}Type ${COLOR_WHITE}cmd${COLOR_YELLOW}, ${COLOR_WHITE}conf${COLOR_YELLOW}, ${COLOR_WHITE}colors ${COLOR_YELLOW}or ${COLOR_WHITE}alias ${COLOR_YELLOW}for more information...${NONE}"
echo ""

View File

@ -8,27 +8,9 @@ fi
. "${WELCOME_SCRIPT_PATH}/config/config_colors.sh"
#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 >'
# 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 '
# 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 '
# ==========================================
# CONFIGURATION DES COULEURS (Modifie ici !)
# ==========================================
# Séparateur
SEP="█►"
# ==========================================
# LOGIQUE DU PROMPT (Ne pas toucher)
# ==========================================
get_git_status() {
local branch status current_bg current_color project upstream behind
branch=$(git branch --show-current 2>/dev/null)
@ -36,35 +18,36 @@ get_git_status() {
project=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)" 2>/dev/null)
# --- SEGMENT PRINCIPAL (PROJET/BRANCHE) ---
current_bg="$COLOR_DARK_GREEN_BG"
current_color="$COLOR_DARK_GREEN"
current_bg="$(color_secure "$COLOR_DARK_GREEN_BG")"
current_color="$(color_secure "$COLOR_DARK_GREEN")"
status="🆗"
if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
current_bg="$COLOR_LIGHT_RED_BG"
current_color="$COLOR_LIGHT_RED"
current_bg="$(color_secure "$COLOR_LIGHT_RED_BG")"
# shellcheck disable=SC2086
current_color="$(color_secure "$COLOR_LIGHT_RED")"
status="🔄"
fi
# Affichage du premier bloc
echo -ne "${COLOR_DARK_GRAY}${current_bg}${SEP}$COLOR_WHITE [${project}/${branch}]${status}"
echo -ne "$(color_secure "$COLOR_DARK_GRAY")${current_bg}${SEP}$(color_secure "$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)
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 🆙"
echo -ne "${current_color}$(color_secure "$COLOR_ORANGE_BG")${SEP}$(color_secure "$COLOR_WHITE") pull $behind 🆙"
# On met à jour les variables pour le SEP de fin
current_bg="${COLOR_ORANGE_BG}"
current_color="${COLOR_ORANGE}"
# shellcheck disable=SC2086
current_bg="$(color_secure $COLOR_ORANGE_BG)"
current_color="$(color_secure "$COLOR_ORANGE")"
fi
fi
@ -80,17 +63,17 @@ get_git_status_OK() {
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"
current_bg="$(color_secure "$COLOR_DARK_GREEN_BG")"
current_color="$(color_secure "$COLOR_DARK_GREEN")"
status="🆗"
if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
current_bg="$COLOR_LIGHT_RED_BG"
current_color="$COLOR_LIGHT_RED"
current_bg="$(color_secure "$COLOR_LIGHT_RED_BG")"
current_color="$(color_secure "$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}"
echo -ne "$(color_secure "$COLOR_DARK_GRAY")${current_bg}${SEP}$(color_secure "$COLOR_WHITE") TEST[${project}/${branch}]${status}${current_bg}${NONE}${current_color}${SEP}${NONE}"
}
set_ps1() {
@ -98,10 +81,10 @@ set_ps1() {
EXIT="$?"
# Segment 1 : User (Bleu) - Ajout des
P1="${COLOR_LIGHT_BLUE_BG}${COLOR_WHITE} <\u@$(hostname -f)>${NONE}"
P1="$(color_secure "$COLOR_LIGHT_BLUE_BG")$(color_secure "$COLOR_WHITE") <\u@$(hostname -f)>${NONE}"
# Segment 2 : Chemin (Gris) avec raccord Bleu
P2="${COLOR_LIGHT_BLUE}${COLOR_DARK_GRAY_BG}${SEP}${COLOR_WHITE} \w"
P2="$(color_secure "$COLOR_LIGHT_BLUE")$(color_secure "$COLOR_DARK_GRAY_BG")${SEP}$(color_secure "$COLOR_WHITE") \w"
# Segment 3 : Git
GIT_PART=$(get_git_status)
@ -110,12 +93,12 @@ set_ps1() {
# 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}"
PS1="\n${P1}${P2} ${NONE}$(color_secure "$COLOR_DARK_GRAY")${SEP}${NONE}"
fi
# Ligne 2 : Flèche de retour
ARROW_C="${COLOR_GREEN}"
[[ $EXIT != 0 ]] && ARROW_C="${COLOR_LIGHT_RED}"
ARROW_C="$(color_secure "$COLOR_GREEN")"
[[ $EXIT != 0 ]] && ARROW_C="$(color_secure "$COLOR_LIGHT_RED")"
PS1+="\n${ARROW_C}└─${NONE} "
}