forked from nhs-england-tools/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_bash_prompt
More file actions
70 lines (64 loc) · 2 KB
/
dot_bash_prompt
File metadata and controls
70 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Utilise the extended colour palette in the command-line output
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color > /dev/null 2>&1; then
export TERM="gnome-256color"
elif infocmp xterm-256color > /dev/null 2>&1; then
export TERM="xterm-256color"
fi
if tput setaf 1 > /dev/null 2>&1; then
tput sgr0
__ps_bold=$(tput bold)
__ps_reset=$(tput sgr0)
__ps_black=$(tput setaf 0)
__ps_blue=$(tput setaf 33)
__ps_cyan=$(tput setaf 37)
__ps_green=$(tput setaf 64)
__ps_orange=$(tput setaf 166)
__ps_pink=$(tput setaf 9)
__ps_purple=$(tput setaf 125)
__ps_red=$(tput setaf 124)
__ps_violet=$(tput setaf 61)
__ps_white=$(tput setaf 15)
__ps_yellow=$(tput setaf 136)
else
__ps_bold=""
__ps_reset="\e[0m"
__ps_black="\e[1;30m"
__ps_blue="\e[1;34m"
__ps_cyan="\e[1;36m"
__ps_green="\e[1;32m"
__ps_orange="\e[1;33m"
__ps_pink="\e[1;31m"
__ps_purple="\e[1;35m"
__ps_red="\e[1;31m"
__ps_violet="\e[1;35m"
__ps_white="\e[1;37m"
__ps_yellow="\e[1;33m"
fi
# Highlight the user and host name when logged in as root
if [[ $(id -un) == "root" ]] || [[ "$USER" == "root" ]]; then
__ps_userStyle="${__ps_pink}"
__ps_hostStyle="${__ps_pink}"
else
__ps_userStyle="${__ps_orange}"
__ps_hostStyle="${__ps_yellow}"
fi
function prompt_command() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
exit_code=" \[${__ps_reset}${__ps_pink}\](${exit_code})"
else
exit_code=""
fi
PS1="\[\033]0;\w\007\]"
PS1+="\[${__ps_bold}${__ps_userStyle}\]\u " # {user}
PS1+="\[${__ps_reset}${__ps_white}\]at " # at
PS1+="\[${__ps_bold}${__ps_hostStyle}\]\h " # {host}
PS1+="\[${__ps_reset}${__ps_white}\]in " # in
PS1+="\[${__ps_bold}${__ps_green}\]\w" # {dir}
PS1+="${exit_code}" # {exit_code}
PS1+="\[${__ps_reset}${__ps_white}\] \$ \[${__ps_reset}\]" # $
export PS1
PS2="\[${__ps_white}\]→ \[${__ps_reset}\]"
export PS2
}
export PROMPT_COMMAND="prompt_command"