-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappendme_basic
More file actions
80 lines (70 loc) · 2.27 KB
/
Copy pathappendme_basic
File metadata and controls
80 lines (70 loc) · 2.27 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
### FANCY BASHRC ###
get_user_color() {
if [[ $(whoami) == "root" ]]; then
echo "\[\033[38;5;1m\]" # red
else
echo "\[\033[38;5;226m\]" # yellow
fi
}
bclear(){
# Clear the terminal
clear
# Get the number of terminal lines
lines=$(tput lines)
# Ensure the value is within a reasonable range
if [[ $lines -gt 5 && $lines -lt 500 ]]; then
# Move the prompt to the bottom of the terminal safely
for ((i = 1; i < lines; i++)); do echo; done
else
echo "Warning: 'tput lines' returned an unexpected value ($lines), skipping newline fill."
fi
}
if [ -f /hostname_override ]; then
FBRC_HOSTNAME=$(cat /hostname_override)
else
FBRC_HOSTNAME=$HOSTNAME
fi
if [ $(tput cols) -lt 180 ]; then
if [ $(tput colors) -gt 7 ]; then
export PS1="[ \[$(tput sgr0)\]$(get_user_color)\u\[$(tput sgr0)\]@\[$(tput sgr0)\]\[\033[38;5;2m\]$(echo $FBRC_HOSTNAME)\[$(tput sgr0)\] \w ]\n\\$ \[$(tput sgr0)\]"
else
export PS1="[ \u@$(echo $FBRC_HOSTNAME)\[$(tput sgr0)\] \w ]\n\\$ "
fi
else
if [ $(tput colors) -gt 7 ]; then
export PS1="[ \[$(tput sgr0)\]$(get_user_color)\u\[$(tput sgr0)\]@\[$(tput sgr0)\]\[\033[38;5;2m\]$(echo $FBRC_HOSTNAME)\[$(tput sgr0)\] \w ]\\$ \[$(tput sgr0)\]"
else
export PS1="[ \u@$(echo $FBRC_HOSTNAME)\[$(tput sgr0)\] \w ]\\$ "
fi
fi
#unset color_prompt force_color_prompt
detect_environment_and_set_TERM() {
local pid=$$
local max_depth=10 # avoid infinite loops
while [ "$pid" -gt 1 ] && [ "$max_depth" -gt 0 ]; do
cmd="$(ps -o comm= -p "$pid" 2>/dev/null)"
if [[ "$cmd" == tmux* ]]; then
export TERM=tmux-256color
return
elif [[ "$cmd" == screen* ]]; then
export TERM=screen-256color
return
fi
pid="$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ')"
max_depth=$((max_depth - 1))
done
# Default fallback
export TERM=xterm-256color
}
if [ $(tput colors) -gt 7 ]; then
detect_environment_and_set_TERM
fi
# automatically cat tmux motd if exists, and set terminal to bottom
if [ -n "$TMUX" ]; then
# clear screen and move cursor to bottom
bclear
if [ -f ~/.tmux.motd ]; then
cat ~/.tmux.motd
fi
fi
### /FANCY BASHRC ###