Skip to content

Commit d36fe05

Browse files
committed
Initial commit
0 parents  commit d36fe05

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 HypeMC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Simple bash prompt
2+
3+
Clone the repo to your home folder:
4+
5+
```shell
6+
cd ~
7+
git clone https://github.com/HypeMC/bash-prompt.git .bash_prompt
8+
```
9+
10+
Add the following to your `.bashrc`:
11+
12+
```shell
13+
. ~/.bash_prompt/prompt.sh
14+
15+
PROMPT_COMMAND="__prompt $color_prompt"
16+
```
17+
18+
![Without the hostname](screen1.png)
19+
20+
With the hostname displayed:
21+
22+
```shell
23+
. ~/.bash_prompt/prompt.sh
24+
25+
PROMPT_COMMAND="__prompt $color_prompt yes"
26+
```
27+
28+
![With the hostname](screen2.png)

prompt.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function __prompt() {
2+
local -r use_color=$1
3+
local -r show_host=${2:-no}
4+
5+
local -r C_NONE='\[\e[00m\]'
6+
local -r C_RED='\[\e[31m\]'
7+
local -r C_GREEN='\[\e[32m\]'
8+
local -r C_YELLOW='\[\e[33m\]'
9+
local -r C_CYAN='\[\e[36m\]'
10+
local -r C_WHITE='\[\e[37m\]'
11+
local -r C_BOLD_RED='\[\e[01;31m\]'
12+
local -r C_BOLD_GREEN='\[\e[01;32m\]'
13+
local -r C_BOLD_YELLOW='\[\e[01;33m\]'
14+
local -r C_BOLD_PURPLE='\[\e[01;35m\]'
15+
16+
local git_prompt=''
17+
if git rev-parse --git-dir >/dev/null 2>&1; then
18+
19+
local git_untracked_files=''
20+
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
21+
git_untracked_files='*'
22+
fi
23+
24+
if [ "$use_color" = yes ]; then
25+
local git_color=''
26+
if ! git diff --quiet; then
27+
git_color=${C_RED}
28+
elif ! git diff --cached --quiet; then
29+
git_color=${C_YELLOW}
30+
else
31+
git_color=${C_GREEN}
32+
fi
33+
34+
git_prompt="[${git_color}\$(__git_ps1 \"%s\")${C_NONE}${git_untracked_files}]"
35+
else
36+
git_prompt="[\$(__git_ps1 \"%s\")${git_untracked_files}]"
37+
fi
38+
39+
fi
40+
41+
local host=''
42+
if [ "$show_host" = yes ]; then
43+
if [ "$use_color" = yes ]; then
44+
host="${C_YELLOW}@${C_BOLD_RED}<${C_BOLD_GREEN}\h${C_BOLD_RED}>${C_NONE}"
45+
else
46+
host='@!\h!'
47+
fi
48+
fi
49+
50+
if [ "$use_color" = yes ]; then
51+
PS1="╭─${C_WHITE}\t${C_NONE} \${debian_chroot:+(\$debian_chroot)}${C_CYAN}\u${C_NONE}${host}: ${C_BOLD_YELLOW}\w${C_NONE}${git_prompt}\n╰─${C_BOLD_PURPLE}\$${C_NONE} "
52+
else
53+
PS1="╭─\t \${debian_chroot:+(\$debian_chroot)}\u${host}: \w${git_prompt}\n╰─\$ "
54+
fi
55+
}

screen1.png

31.9 KB
Loading

screen2.png

7.97 KB
Loading

0 commit comments

Comments
 (0)