diff options
author | Mountain Man <43313373+MountainMan1312@users.noreply.github.com> | 2023-03-31 01:03:01 -0400 |
---|---|---|
committer | Mountain Man <43313373+MountainMan1312@users.noreply.github.com> | 2023-03-31 01:03:01 -0400 |
commit | 2f1c46350c9294ee360527722464abf493469650 (patch) | |
tree | f7470cddfcf4680a8c8796d15bd3512c3d8a92c3 /home/.bashrc | |
parent | Use same '.bashrc' file for all users (diff) | |
download | dotfiles.old-2f1c46350c9294ee360527722464abf493469650.tar.gz dotfiles.old-2f1c46350c9294ee360527722464abf493469650.tar.bz2 dotfiles.old-2f1c46350c9294ee360527722464abf493469650.zip |
Create custom $PS1 prompt in 'home/.bashrc'
This change adds a custom PS1 prompt.
The prompt is constructed step-by-step through concatenation, and contains
conditional formatting based on which user is logged in and whether or not
it is running in an SSH session.
The PS1 prompt should look something like:
- `[TTY#] [DATE TIME] [USER@HOST] [DIR] >`
- `[1] [2023-03-31 01:07:42] [username@hostname] [~/dotfiles/home] >`
Diffstat (limited to 'home/.bashrc')
-rw-r--r-- | home/.bashrc | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/home/.bashrc b/home/.bashrc index 786f06d..d4e96d3 100644 --- a/home/.bashrc +++ b/home/.bashrc | |||
@@ -1,7 +1,88 @@ | |||
1 | # ~/.bashrc | 1 | # dotfiles/home/.bashrc -> /home/$USER/.bashrc |
2 | # Author: Mountain Man | 2 | # Author: Mountain Man |
3 | 3 | ||
4 | |||
4 | # Test for an interactive shell. | 5 | # Test for an interactive shell. |
5 | if [[ $- != *i* ]] ; then | 6 | if [[ $- != *i* ]] ; then |
6 | return | 7 | return |
7 | fi | 8 | fi |
9 | |||
10 | |||
11 | ########################################################################## | ||
12 | # PS1 - Primary prompt displayed before each command | ||
13 | #################################################### | ||
14 | # The PS1 prompt is constructed piece-by-piece by concatenating each | ||
15 | # component to the previous component. Parts of the prompt are colored | ||
16 | # conditionally based on what kind of user is logged in. | ||
17 | # | ||
18 | # Breakdown of PS1 components: | ||
19 | # [TTY#] [DATE TIME] [USER HOST] [DIR] > | ||
20 | # | ||
21 | # Example of what the prompt should look like: | ||
22 | # [1] [2023-03-28 16:02:55] [user host] [/etc/portage] > | ||
23 | ########################################################################## | ||
24 | |||
25 | # Set colors for easy reading | ||
26 | PS1_COLOR_RESET="\[\e[0m\]" | ||
27 | PS1_COLOR_GREY="\[\e[90m\]" | ||
28 | PS1_COLOR_RED="\[\e[91m\]" | ||
29 | PS1_COLOR_YELLOW="\[\e[33m\]" | ||
30 | PS1_COLOR_BLUE="\[\e[94m\]" | ||
31 | PS1_COLOR_CYAN="\[\e[96m\]" | ||
32 | |||
33 | if [[ "$(id -u)" == 0 ]]; then # if root | ||
34 | PS1_COLOR_MAIN=$PS1_COLOR_RED # set main color red | ||
35 | elif [[ "$USER" == *"-dev" ]]; then # if -dev account | ||
36 | PS1_COLOR_MAIN=$PS1_COLOR_YELLOW # set main color yellow | ||
37 | else # all other accounts | ||
38 | PS1_COLOR_MAIN=$PS1_COLOR_GREY # set main color grey | ||
39 | fi | ||
40 | |||
41 | # Start with a blank PS1 prompt | ||
42 | PS1="" | ||
43 | |||
44 | # [TTY#] [DATE TIME] | ||
45 | PS1+=$PS1_COLOR_MAIN | ||
46 | TTY_NUM=$(ps -p $$ -o tty= | tr -dc '0-9') | ||
47 | PS1+="[$TTY_NUM] [\D{%F} \t] " | ||
48 | PS1+=$PS1_COLOR_RESET | ||
49 | |||
50 | # [SSH USER@HOST] | ||
51 | PS1+=$PS1_COLOR_MAIN | ||
52 | if [[ "$SSH_TTY" == "/dev/pts"* ]]; then # if this is SSH session | ||
53 | PS1+="[SSH " # add "[SSH " | ||
54 | else | ||
55 | PS1+="[" | ||
56 | fi | ||
57 | PS1+=$PS1_COLOR_RESET | ||
58 | |||
59 | PS1+=$PS1_COLOR_CYAN | ||
60 | PS1+="\u" | ||
61 | PS1+=$PS1_COLOR_RESET | ||
62 | |||
63 | PS1+=$PS1_COLOR_GREY | ||
64 | PS1+="@" | ||
65 | PS1+=$PS1_COLOR_RESET | ||
66 | |||
67 | PS1+=$PS1_COLOR_BLUE | ||
68 | PS1+="\h" | ||
69 | PS1+=$PS1_COLOR_RESET | ||
70 | |||
71 | PS1+=$PS1_COLOR_MAIN | ||
72 | PS1+="] " | ||
73 | PS1+=$PS1_COLOR_RESET | ||
74 | |||
75 | # [DIR] > | ||
76 | PS1+=$PS1_COLOR_MAIN | ||
77 | PS1+="[" | ||
78 | PS1+=$PS1_COLOR_RESET | ||
79 | |||
80 | PS1+=$PS1_COLOR_CYAN | ||
81 | PS1+="\w" | ||
82 | PS1+=$PS1_COLOR_RESET | ||
83 | |||
84 | PS1+=$PS1_COLOR_MAIN | ||
85 | PS1+="] >" | ||
86 | PS1+=$PS1_COLOR_RESET | ||
87 | |||
88 | ########################################################################## | ||