-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_prompt
111 lines (91 loc) · 2.74 KB
/
.bash_prompt
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Enable 256 colors
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color &> /dev/null; then
export TERM="gnome-256color"
elif infocmp xterm-256color &> /dev/null; then
export TERM="xterm-256color"
fi
prompt_git() {
local branchName=""
local state=""
# Check if the current directory is in a git repository
! git rev-parse &> /dev/null && return
# Check if inside of .git
[ "$(git rev-parse --is-inside-git-dir)" == "true" ] && return
# Check for uncommitted changes in the index
if ! git diff --quiet --ignore-submodules --cached; then
state+="+"
fi
# Check for unstaged changes
if ! git diff-files --quiet --ignore-submodules --; then
state+="!"
fi
# Check for untracked files
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
state+="?"
fi
# Check for stashed files
if git rev-parse --verify refs/stash &> /dev/null; then
state+="$"
fi
[ -n "$state" ] && state=" [$state]"
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
git rev-parse --short HEAD 2> /dev/null || \
printf "(unknown)" )"
printf "%s" "$1$branchName$state"
}
prompt_virtualenv() {
! [ -n "$VIRTUAL_ENV" ] && return
virtualName="(`basename $VIRTUAL_ENV`)"
printf "%s" "$1$virtualName "
}
# Setup terminal style and colors
if tput setaf 1 &> /dev/null; then
# Reset colors
tput sgr0
bold=$(tput bold)
reset=$(tput sgr0)
# Gruvbox colors from https://github.com/morhetz/gruvbox
black=$(tput setaf 0)
blue=$(tput setaf 66)
cyan=$(tput setaf 71)
green=$(tput setaf 100)
magenta=$(tput setaf 132)
orange=$(tput setaf 166)
red=$(tput setaf 160)
white=$(tput setaf 15)
yellow=$(tput setaf 172)
else
bold="\e[1m"
reset="\e[0m"
black="\e[1;30m"
blue="\e[1;34m"
cyan="\e[1;36m"
green="\e[1;32m"
magenta="\e[1;35m"
orange="\e[1;33m"
red="\e[1;31m"
violet="\e[1;35m"
white="\e[1;37m"
yellow="\e[1;33m"
fi
# Setup terminal title and prompt
PS1="\[\033]0;\W\007\]" # Current working directory
PS1+="\n"
PS1+="\[$bold\]"
PS1+="\$(prompt_virtualenv \"$blue\")" # Virtualenv details
PS1+="\[$orange\]\u" # Username
PS1+="\[$white\] at "
PS1+="\[$yellow\]\h" # Host
PS1+="\[$white\] in "
PS1+="\[$green\]\w" # Working directory
# Solarized Git details
# PS1+="\$(prompt_git \"$white on $violet\")" # Git details
# Gruvbox Git details
PS1+="\$(prompt_git \"$white on $blue\")"
PS1+="\n"
PS1+="\[$white\]\$ \[$reset\]" # End symbol
export PS1
# Setup continuation prompt
PS2="\[$yellow\]> \[$reset\]"
export PS2