forked from addyosmani/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.bash_prompt
100 lines (77 loc) · 2.84 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
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
default_username='will-never-match'
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
YELLOW=$(tput setaf 3)
PINK=$(tput setaf 5)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
CYAN=$(tput setaf 6)
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 10)
PURPLE=$(tput setaf 141)
WHITE=$(tput setaf 256)
LIGHTGREY="$(tput setaf 8)"
GREY="$(tput setaf 7)"
GREYBG="$(tput setab 7)"
LIGHTGREYBG="$(tput setab 8)"
BRIGHT=$(tput bold)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
BOLD=$(tput bold)
RESET=$(tput sgr0)
function git_info() {
# check if we're in a git repo
git rev-parse --is-inside-work-tree &>/dev/null || return
# quickest check for what branch we're on
branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
# check if it's dirty (via github.com/sindresorhus/pure)
dirty=$(git diff --quiet --ignore-submodules HEAD &>/dev/null; [ $? -eq 1 ]&& echo -e "*")
echo $WHITE" on "$PURPLE$UNDERLINE$branch$RESET $BRIGHT$CYAN$dirty$RESET
}
# Only show username/host if not default
function usernamehost() {
echo "${MAGENTA}$USER ${GREY}@${ORANGE} $HOSTNAME${GREY} in ${YELLOW}$(current_dir)${RESET}";
}
function current_dir() {
local pwd_length=42 # The maximum length we want (seems to fit nicely
# in a default length Terminal title bar).
# Get the current working directory. We'll format it in $dir.
local dir="$PWD"
# Substitute a leading path that's in $HOME for "~"
if [[ "$HOME" == ${dir:0:${#HOME}} ]] ; then
dir="~${dir:${#HOME}}"
fi
# Truncate if we're too long.
# We preserve the leading '/' or '~/', and substitute
# ellipses for some directories in the middle.
if [[ "$dir" =~ (~){0,1}/.*(.{${pwd_length}}) ]] ; then
local tilde=${BASH_REMATCH[1]}
local directory=${BASH_REMATCH[2]}
# At this point, $directory is the truncated end-section of the
# path. We will now make it only contain full directory names
# (e.g. "ibrary/Mail" -> "/Mail").
if [[ "$directory" =~ [^/]*(.*) ]] ; then
directory=${BASH_REMATCH[1]}
fi
dir="$tilde/…$directory"
fi
echo $dir
}
# function current_dir() {
# dir=$PWD
# pushd "$dir" > /dev/null # Switch to the given directory; suppress output.
# dirs -0 # Run "dirs" and save to variable.
# popd > /dev/null # Switch back to where we were
# }
PS1="\[\e]2;[bash] \h::\]\W\[\a\]\[\e]1;\]/\W\[\a\]${BOLD}\$(usernamehost)\[$RESET\]\n\$ "
export PROMPT_COMMAND='history -a'