diff --git a/TODO.md b/TODO.md index 0774da7..ebf7740 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/config/config_cmd.sh b/config/config_cmd.sh index b032229..22e0bb6 100644 --- a/config/config_cmd.sh +++ b/config/config_cmd.sh @@ -27,6 +27,14 @@ CMD_LIST_CONFIG_JSON=$(cat </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}" +} \ No newline at end of file diff --git a/inc/alias.sh b/inc/alias.sh index 0cf9487..1559105 100644 --- a/inc/alias.sh +++ b/inc/alias.sh @@ -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\] ' diff --git a/inc/infos.sh b/inc/infos.sh index 04a83e6..dc6d6dd 100644 --- a/inc/infos.sh +++ b/inc/infos.sh @@ -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 "" diff --git a/inc/ps1.sh b/inc/ps1.sh index 1f43ebb..cfc443a 100644 --- a/inc/ps1.sh +++ b/inc/ps1.sh @@ -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} " }