Last active
January 11, 2019 11:57
-
-
Save DavidEGx/7b8d378d55ec03aeefe86e5135ef8514 to your computer and use it in GitHub Desktop.
Bash prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# ------------------------- | |
# BASH PROMPT CONFIGURATION | |
# ------------------------- | |
# Description: | |
# Shows a nicer bash prompt: | |
# βΆ π³ mypc βΆ documents βΆ β master βΆ π β | |
# -------- --------- ---------- --- ----- | |
# | | | | | | |
# hostname folder git branch jobs last command result | |
# | |
# See https://gist.github.com/DavidEGx/7b8d378d55ec03aeefe86e5135ef8514#file-prompt_demo-png | |
# for a colurful demo. | |
# | |
# Last version of this file can be found at | |
# https://gist.github.com/DavidEGx/7b8d378d55ec03aeefe86e5135ef8514 | |
# | |
# Usage: | |
# 1. Get a copy of __git_ps1 | |
# wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -O ~/.git-prompt.sh | |
# 2. Copy this file in your local diretory as ~/.bash_prompt | |
# 3. Edit your ~/.bashrc and add this line: | |
# . ~/.bash_prompt | |
# 4. Reload your ~/.bashrc: | |
# . ~/.bashrc | |
# | |
# Requires: | |
# * Some font with good unicode support installed (sudo apt install unifont) | |
# * 256 colors support in your terminal | |
# * __git_ps1 | |
# | |
# Useful info: | |
# * http://misc.flogisoft.com/bash/tip_colors_and_formatting | |
# * https://github.com/morhetz/gruvbox | |
# * https://gist.github.com/MicahElliott/719710 | |
# | |
################################################################################ | |
####################### | |
# Git config | |
####################### | |
# Need to get git-prompt: | |
# wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -O ~/.git-prompt.sh | |
if [ -f ~/.git-prompt.sh ]; then | |
. ~/.git-prompt.sh | |
fi | |
GIT_PS1_SHOWDIRTYSTATE="" | |
GIT_PS1_SHOWCOLORHINTS="" | |
GIT_PS1_SHOWUNTRACKEDFILES="" | |
GIT_PS1_SHOWUPSTREAM="" | |
GIT_PS1_SHOWSTASHSTATE="" | |
####################### | |
# Colors | |
####################### | |
# Color reset | |
PLAIN='\e[0m' | |
# Text colors | |
RED='\e[31m' | |
GREEN='\e[32m' | |
BLUE='\e[1;38;5;25m' | |
LIGHTGRAY='\e[1;38;5;252m' | |
GRAY='\e[1;38;5;242m' | |
WHITE='\e[1;38;5;251m' | |
ORANGE='\e[1;38;5;130m' | |
BOLDBLACK='\e[1;38;5;232m' | |
# Background colors | |
BGBLACK='\e[40m' | |
BGBLUE='\e[48;5;25m' | |
BGLIGHTGRAY='\e[48;5;252m' | |
BGGRAY='\e[48;5;242m' | |
####################### | |
# Icons (I_ICON_NAME) | |
####################### | |
I_ARROW="βΆ" | |
#I_HOST=" π» " This character casues some issues | |
I_HOST=" π³ " | |
I_GIT=" β " | |
I_OK="β" | |
I_KO="βοΈ" | |
####################### | |
# Styles (S_STYLE_NAME) | |
####################### | |
S_HOST_BG=$BGLIGHTGRAY | |
S_HOST_TXT=$BOLDBLACK | |
S_HOST_ARROW=$GRAY | |
S_DIR_BG=$BGGRAY | |
S_DIR_TXT=$LIGHTGRAY | |
S_GIT_BG=$BGBLUE | |
S_GIT_TXT=$WHITE | |
S_GIT_ARROW=$GRAY | |
S_TASK_BG=$BGBLACK | |
S_TASK_TXT=$ORANGE | |
S_TASK_ARROW=$BLUE | |
S_RESULT_OK=$GREEN | |
S_RESULT_KO=$RED | |
####################### | |
# Prompt parts (P_*) | |
####################### | |
P_HOST=`printf "\[$S_HOST_BG\]\[$S_HOST_ARROW\]$I_ARROW\[$S_HOST_TXT\] $I_HOST\h "` | |
P_DIR=`printf "\[$S_DIR_BG\]\[$S_DIR_TXT\]$I_ARROW \W "` | |
P_GIT=' | |
P_GIT_BRANCH=\`type __git_ps1 >/dev/null 2>&1 && __git_ps1 %s\` | |
if [ -z $P_GIT_BRANCH ]; then | |
printf " \[$S_TASK_BG\]\[$S_GIT_ARROW\]$I_ARROW\[$PLAIN\] "; | |
else | |
printf " \[$S_GIT_BG\]\[$S_GIT_ARROW\]$I_ARROW\[$S_GIT_TXT\]$I_GIT $P_GIT_BRANCH \[$S_TASK_BG\]\[$S_TASK_ARROW\]$I_ARROW\[$PLAIN\] "; | |
fi | |
' | |
# Number of jobs running | |
P_JOBS=`printf " | |
echo -n '\[$S_TASK_TXT\]' | |
case '\j' in | |
0) echo -n '';; | |
1) echo -n 'π ' ;; | |
2) echo -n 'π‘ ' ;; | |
3) echo -n 'π’ ' ;; | |
4) echo -n 'π£ ' ;; | |
*) echo -n 'π€ ' ;; | |
esac | |
echo -n '\[$PLAIN\]' | |
"` | |
# Result of the last command | |
P_CMD_RESULT=" | |
if [ \$LASTCMD -eq 0 ]; then | |
echo -n \[$S_RESULT_OK\]$I_OK\[$PLAIN\]; | |
else | |
echo -n \[$S_RESULT_KO\]$I_KO\[$PLAIN\]; | |
fi | |
echo -n ' ' | |
" | |
PROMPT_COMMAND='LASTCMD=$? PS1="${debian_chroot:+($debian_chroot)}${P_HOST}${P_DIR}\`${P_GIT}\`\`${P_JOBS}\`\`${P_CMD_RESULT}\` "' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment