最後活躍 1 month ago

修訂 90f5520b9402926be18af8d9bf471930715d1b9c

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