-
-
Notifications
You must be signed in to change notification settings - Fork 643
Expand file tree
/
Copy path.bash_server_prompt
More file actions
81 lines (72 loc) · 2.67 KB
/
Copy path.bash_server_prompt
File metadata and controls
81 lines (72 loc) · 2.67 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
71
72
73
74
75
76
77
78
79
80
81
# Standalone bash prompt for remote servers — pulled onto fresh hosts where
# the rest of the dotfiles aren't deployed, so no .shared_prompt dependency.
# If not running interactively, don't do anything
[[ $- == *i* ]] || return 0
# Fall back to xterm-256color if the client's TERM has no terminfo here (e.g. xterm-ghostty)
if ! infocmp "$TERM" >/dev/null 2>&1 && infocmp xterm-256color >/dev/null 2>&1; then
export TERM='xterm-256color'
fi
bold=$(tput bold 2>/dev/null || printf '\e[1m')
reset=$(tput sgr0 2>/dev/null || printf '\e[0m')
# Exact 24-bit colors when the terminal advertises them, else the nearest
# 256-color values (COLORTERM rarely survives SSH). To forward it: server
# needs `AcceptEnv COLORTERM` in sshd_config (then reload ssh); Ghostty's
# ssh-env sends it, other clients need `SendEnv COLORTERM` in ~/.ssh/config.
if [[ "${COLORTERM}" == "truecolor" || "${COLORTERM}" == "24bit" ]]; then
# hex "e47030" -> its 24-bit escape (printf %d converts each 0x pair)
color() { printf '\033[38;2;%d;%d;%dm' "0x${1:0:2}" "0x${1:2:2}" "0x${1:4:2}"; }
blue=$(color afd7ff)
green=$(color 5faf5f)
magenta=$(color b48ead)
orange=$(color e47030)
red=$(color d75f5f)
white=$(color f1f1f1)
yellow=$(color ffff87)
elif tput setaf 1 >/dev/null 2>&1; then
blue=$(tput setaf 153)
green=$(tput setaf 71)
magenta=$(tput setaf 139)
orange=$(tput setaf 166)
red=$(tput setaf 167)
white=$(tput setaf 15)
yellow=$(tput setaf 228)
else # last resort: the basic 16 colors
blue="\e[1;34m"
green="\e[1;32m"
magenta="\e[1;35m"
orange="\e[1;33m"
red="\e[1;31m"
white="\e[1;37m"
yellow="\e[1;33m"
fi
# ls colors (GNU syntax) matching LSCOLORS in .aliases: bold yellow dirs, green executables
export LS_COLORS='di=01;33:ln=34:so=32:pi=33:ex=32:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43'
alias ls='ls --color=auto'
alias la='ls -lahF --color=auto'
# Red username + traditional # when root ($EUID is set even where $USER isn't)
if (( EUID == 0 )); then
userStyle="${red}"
marker='#' # root keeps the traditional marker
else
userStyle="${orange}"
marker='›'
fi
# Magenta hostname over SSH (distinct from the red root warning)
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${magenta}"
else
hostStyle="${yellow}"
fi
# Terminal title = current directory
PS1="\[\033]0;\w\007\]"
PS1+="\[${bold}\]\n" # newline
PS1+="\[${userStyle}\]\u" # username
PS1+="\[${white}\] at "
PS1+="\[${hostStyle}\]\h" # host
PS1+="\[${white}\] in "
PS1+="\[${green}\]\W" # working directory
PS1+="\n"
PS1+="\[${white}\]${marker} \[${reset}\]" # input marker (and reset color)
export PS1
PS2="\[${yellow}\]➜ \[${reset}\]"
export PS2