forked from CoreyMSchafer/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.shared_prompt
64 lines (55 loc) · 1.96 KB
/
.shared_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
# Define the prompt_git function for git repository status
prompt_git() {
local git_status=''
local branchName=''
# Check if the current directory is in a Git repository.
if git rev-parse --is-inside-work-tree &>/dev/null; then
# Get the status summary.
local gitSummary=$(git status --porcelain)
# Check for uncommitted changes in the index, unstaged changes, untracked files, and stashed files.
[[ -n $(echo "$gitSummary" | grep '^M') ]] && git_status+='+'
[[ -n $(echo "$gitSummary" | grep '^ M') ]] && git_status+='!'
[[ -n $(echo "$gitSummary" | grep '^\?\?') ]] && git_status+='?'
[[ $(
git rev-parse --verify refs/stash &>/dev/null
echo "${?}"
) == '0' ]] && git_status+='$'
# Get the short symbolic ref or the short SHA for the latest commit.
branchName="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo '(unknown)')"
[ -n "${git_status}" ] && git_status=" [${git_status}]"
printf "%b on %b%s%s" "${white}" "${blue}" "${branchName}" "${git_status}"
else
return
fi
}
export VIRTUAL_ENV_DISABLE_PROMPT=1
prompt_venv() {
if [[ -n "$VIRTUAL_ENV" ]]; then
# Extract the last directory name in the $VIRTUAL_ENV path
venv_name=$(basename "$VIRTUAL_ENV")
printf "\n%b(%s)\n" "${steel_blue}" "${venv_name}"
fi
}
# Using tput for colors and formatting.
tput sgr0 # reset colors
bold=$(tput bold)
reset=$(tput sgr0)
blue=$(tput setaf 153)
steel_blue=$(tput setaf 67)
green=$(tput setaf 71)
orange=$(tput setaf 166)
red=$(tput setaf 167)
white=$(tput setaf 15)
yellow=$(tput setaf 228)
# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="${red}"
else
userStyle="${orange}"
fi
# Highlight the hostname when connected via SSH.
if [[ "${SSH_TTY}" ]]; then
hostStyle="${bold}${red}"
else
hostStyle="${yellow}"
fi