Linux_frogg-profile.d/inc/ps1.sh

82 lines
2.5 KiB
Bash

#!/bin/bash
if [[ -z "${WELCOME_SCRIPT_PATH}" ]]; then
WELCOME_SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &>/dev/null && pwd)"
fi
#region INCLUDES
. "${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
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
status="🆗"
if [[ -n $(git status --porcelain 2>/dev/null) ]]; then
current_bg=$COLOR_LIGHT_RED_BG
current_color=$COLOR_LIGHT_RED
#status="▼"
status="🔄"
fi
echo -ne "${COLOR_DARK_GRAY}${current_bg}${SEP}${COLOR_WHITE} [${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)
P1="${COLOR_LIGHT_BLUE_BG}${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"
# Segment 3 : Git
GIT_PART=$(get_git_status)
if [[ -n "$GIT_PART" ]]; then
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}
PS1+="\n${ARROW_C}└─${NONE} "
}
PROMPT_COMMAND=set_ps1