Skip to content

Commit 326b801

Browse files
committedFeb 3, 2024
Add option to show full host
1 parent f277854 commit 326b801

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed
 

‎prompt.sh

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
function __prompt() {
22
local -r last_exit_code=$?
3-
local -r use_color=$1
4-
local -r show_host=${2:-no}
3+
4+
local -r use_color="$1"
5+
local -r show_host="${2:-no}"
56

67
local -r C_NONE='\[\e[00m\]'
78
local -r C_RED='\[\e[31m\]'
@@ -31,14 +32,12 @@ function __prompt() {
3132
git_untracked_files='*'
3233
fi
3334

34-
if [ "$use_color" = yes ]; then
35-
local git_color=''
35+
if [ "$use_color" = 'yes' ]; then
36+
local git_color=$C_GREEN
3637
if ! git diff --quiet; then
37-
git_color=${C_RED}
38+
git_color=$C_RED
3839
elif ! git diff --cached --quiet; then
39-
git_color=${C_YELLOW}
40-
else
41-
git_color=${C_GREEN}
40+
git_color=$C_YELLOW
4241
fi
4342

4443
git_prompt="[${git_color}\$(__git_ps1 \"%s\")${C_NONE}${git_untracked_files}]"
@@ -48,25 +47,30 @@ function __prompt() {
4847

4948
fi
5049

50+
local hostname='\h'
51+
if [ "$show_host" = 'full' ]; then
52+
hostname='\H'
53+
fi
54+
5155
local host=''
52-
if [ "$show_host" = yes ]; then
53-
if [ "$use_color" = yes ]; then
54-
host="${C_YELLOW}@${C_BOLD_RED}<${C_HOST}\h${C_BOLD_RED}>${C_NONE}"
56+
if [ "$show_host" != 'no' ]; then
57+
if [ "$use_color" = 'yes' ]; then
58+
host="${C_YELLOW}@${C_BOLD_RED}<${C_HOST}${hostname}${C_BOLD_RED}>${C_NONE}"
5559
else
56-
host='@!\h!'
60+
host="@!${hostname}!"
5761
fi
5862
fi
5963

6064
local error_mark=''
6165
if [ "$last_exit_code" -ne 0 ]; then
62-
if [ "$use_color" = yes ]; then
66+
if [ "$use_color" = 'yes' ]; then
6367
error_mark="${C_BOLD_RED}!${C_NONE}"
6468
else
6569
error_mark='!'
6670
fi
6771
fi
6872

69-
if [ "$use_color" = yes ]; then
73+
if [ "$use_color" = 'yes' ]; then
7074
PS1="╭─${C_WHITE}\t${C_NONE} \${debian_chroot:+(\$debian_chroot)}${C_USER}\u${C_NONE}${host}: ${C_BOLD_YELLOW}\w${C_NONE}${git_prompt}\n╰─${error_mark}${C_BOLD_PURPLE}\$${C_NONE} "
7175
else
7276
PS1="╭─\t \${debian_chroot:+(\$debian_chroot)}\u${host}: \w${git_prompt}\n╰─${error_mark}\$ "

0 commit comments

Comments
 (0)
Please sign in to comment.