.bash_prompt
· 3.7 KiB · Bash
Surowy
################################################################################
# -------------------------
# 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 unicode font
# * 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
echo -en " \[$S_TASK_BG\]\[$S_GIT_ARROW\]$I_ARROW\[$PLAIN\] ";
else
echo -en " \[$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 '\[$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 ${RESULT_OK}${I_OK}\[$PLAIN\];
else
echo -n ${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}\` "'
| 1 | ################################################################################ |
| 2 | # ------------------------- |
| 3 | # BASH PROMPT CONFIGURATION |
| 4 | # ------------------------- |
| 5 | # Description: |
| 6 | # Shows a nicer bash prompt: |
| 7 | # ▶ 🖳 mypc ▶ documents ▶ ⎇ master ▶ 𝍠 ✔ |
| 8 | # -------- --------- ---------- --- ----- |
| 9 | # | | | | | |
| 10 | # hostname folder git branch jobs last command result |
| 11 | # |
| 12 | # See https://gist.github.com/DavidEGx/7b8d378d55ec03aeefe86e5135ef8514#file-prompt_demo-png |
| 13 | # for a colurful demo. |
| 14 | # |
| 15 | # Last version of this file can be found at |
| 16 | # https://gist.github.com/DavidEGx/7b8d378d55ec03aeefe86e5135ef8514 |
| 17 | # |
| 18 | # Usage: |
| 19 | # 1. Get a copy of __git_ps1 |
| 20 | # wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -O ~/.git-prompt.sh |
| 21 | # 2. Copy this file in your local diretory as ~/.bash_prompt |
| 22 | # 3. Edit your ~/.bashrc and add this line: |
| 23 | # . ~/.bash_prompt |
| 24 | # 4. Reload your ~/.bashrc: |
| 25 | # . ~/.bashrc |
| 26 | # |
| 27 | # Requires: |
| 28 | # * Some unicode font |
| 29 | # * 256 colors support in your terminal |
| 30 | # * __git_ps1 |
| 31 | # |
| 32 | # Useful info: |
| 33 | # * http://misc.flogisoft.com/bash/tip_colors_and_formatting |
| 34 | # * https://github.com/morhetz/gruvbox |
| 35 | # * https://gist.github.com/MicahElliott/719710 |
| 36 | # |
| 37 | ################################################################################ |
| 38 | |
| 39 | ####################### |
| 40 | # Git config |
| 41 | ####################### |
| 42 | # Need to get git-prompt: |
| 43 | # wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -O ~/.git-prompt.sh |
| 44 | if [ -f ~/.git-prompt.sh ]; then |
| 45 | . ~/.git-prompt.sh |
| 46 | fi |
| 47 | GIT_PS1_SHOWDIRTYSTATE="" |
| 48 | GIT_PS1_SHOWCOLORHINTS="" |
| 49 | GIT_PS1_SHOWUNTRACKEDFILES="" |
| 50 | GIT_PS1_SHOWUPSTREAM="" |
| 51 | GIT_PS1_SHOWSTASHSTATE="" |
| 52 | |
| 53 | ####################### |
| 54 | # Colors |
| 55 | ####################### |
| 56 | |
| 57 | # Color reset |
| 58 | PLAIN='\e[0m' |
| 59 | |
| 60 | # Text colors |
| 61 | RED='\[\e[31m\]' |
| 62 | GREEN='\[\e[32m\]' |
| 63 | BLUE='\e[1;38;5;25m' |
| 64 | LIGHTGRAY='\e[1;38;5;252m' |
| 65 | GRAY='\e[1;38;5;242m' |
| 66 | WHITE='\e[1;38;5;251m' |
| 67 | ORANGE='\[\e[1;38;5;130m\]' |
| 68 | BOLDBLACK='\e[1;38;5;232m' |
| 69 | |
| 70 | # Background colors |
| 71 | BGBLACK='\e[40m' |
| 72 | BGBLUE='\e[48;5;25m' |
| 73 | BGLIGHTGRAY='\e[48;5;252m' |
| 74 | BGGRAY='\e[48;5;242m' |
| 75 | |
| 76 | ####################### |
| 77 | # Icons (I_ICON_NAME) |
| 78 | ####################### |
| 79 | I_ARROW="▶" |
| 80 | #I_HOST=" 💻 " This character casues some issues |
| 81 | I_HOST=" 🖳 " |
| 82 | I_GIT=" ⎇ " |
| 83 | I_OK="✔" |
| 84 | I_KO="✖️" |
| 85 | |
| 86 | ####################### |
| 87 | # Styles (S_STYLE_NAME) |
| 88 | ####################### |
| 89 | S_HOST_BG=$BGLIGHTGRAY |
| 90 | S_HOST_TXT=$BOLDBLACK |
| 91 | S_HOST_ARROW=$GRAY |
| 92 | S_DIR_BG=$BGGRAY |
| 93 | S_DIR_TXT=$LIGHTGRAY |
| 94 | S_GIT_BG=$BGBLUE |
| 95 | S_GIT_TXT=$WHITE |
| 96 | S_GIT_ARROW=$GRAY |
| 97 | S_TASK_BG=$BGBLACK |
| 98 | S_TASK_TXT=$ORANGE |
| 99 | S_TASK_ARROW=$BLUE |
| 100 | S_RESULT_OK=$GREEN |
| 101 | S_RESULT_KO=$RED |
| 102 | |
| 103 | ####################### |
| 104 | # Prompt parts (P_*) |
| 105 | ####################### |
| 106 | P_HOST=`printf "\[$S_HOST_BG\]\[$S_HOST_ARROW\]$I_ARROW\[$S_HOST_TXT\] $I_HOST\h "` |
| 107 | P_DIR=`printf "\[$S_DIR_BG\]\[$S_DIR_TXT\]$I_ARROW \W "` |
| 108 | P_GIT=' |
| 109 | P_GIT_BRANCH=\`type __git_ps1 >/dev/null 2>&1 && __git_ps1 %s\` |
| 110 | if [ -z $P_GIT_BRANCH ]; then |
| 111 | echo -en " \[$S_TASK_BG\]\[$S_GIT_ARROW\]$I_ARROW\[$PLAIN\] "; |
| 112 | else |
| 113 | echo -en " \[$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\] "; |
| 114 | fi |
| 115 | ' |
| 116 | # Number of jobs running |
| 117 | P_JOBS=`printf " |
| 118 | echo -n '\[$TASK_TXT\]' |
| 119 | case '\j' in |
| 120 | 0) echo -n '';; |
| 121 | 1) echo -n '𝍠 ' ;; |
| 122 | 2) echo -n '𝍡 ' ;; |
| 123 | 3) echo -n '𝍢 ' ;; |
| 124 | 4) echo -n '𝍣 ' ;; |
| 125 | *) echo -n '𝍤 ' ;; |
| 126 | esac |
| 127 | echo -n '\[$PLAIN\]' |
| 128 | "` |
| 129 | # Result of the last command |
| 130 | P_CMD_RESULT=" |
| 131 | if [ \$LASTCMD -eq 0 ]; then |
| 132 | echo -n ${RESULT_OK}${I_OK}\[$PLAIN\]; |
| 133 | else |
| 134 | echo -n ${RESULT_KO}${I_KO}\[$PLAIN\]; |
| 135 | fi |
| 136 | echo -n ' ' |
| 137 | " |
| 138 | |
| 139 | PROMPT_COMMAND='LASTCMD=$? PS1="${debian_chroot:+($debian_chroot)}${P_HOST}${P_DIR}\`${P_GIT}\`\`${P_JOBS}\`\`${P_CMD_RESULT}\` "' |
| 140 |
prompt_demo.png
· 4.6 KiB · Image (PNG)
Surowy