-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbashrc
54 lines (51 loc) · 1.63 KB
/
bashrc
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
#!/usr/bin/env bash
# if not running interactively, don't do anything
[[ $- != *i* ]] && return
source "/share/bash-completion/completions/git-prompt.sh"
# shell prompt
__red_ps="$(tput setaf 1)"
__green_ps="$(tput setaf 2)"
__orange_ps="$(tput setaf 3)"
__blue_ps="$(tput setaf 4)"
__purple_ps="$(tput setaf 5)"
__yellow_ps="$(tput setaf 11)"
__bold_ps="$(tput bold)"
__normal_ps="$(tput sgr0)"
function __exit_ps1() {
local EXIT="${?}"
local EXIT_COLOR=""
if [ "${EXIT}" = 0 ]; then
EXIT_COLOR="${__green_ps}"
else
EXIT_COLOR="${__red_ps}"
fi
printf '\001%s\002' "${EXIT_COLOR}"
return "${EXIT}"
}
function __hostname_ps1() {
local EXIT="${?}"
if [ -n "${SSH_CONNECTION}" ]; then
printf "\001%s\002@\001%s\002%s" "${__normal_ps}" "${__purple_ps}" "${1}"
fi
return "${EXIT}"
}
PS1='\001${__normal_ps}\002[$(__exit_ps1)\u$(__hostname_ps1 \h) \001${__blue_ps}\002\W$(__git_ps1 " \001${__normal_ps}\002@\001${__orange_ps}\002%s")\001${__normal_ps}\002]\001${__bold_ps}\002\$\001${__normal_ps}\002 '
function __whitespace_ps2() {
local EXIT="${?}"
local EXTRA_SPACE="3"
local USERNAME="${1}"
local HOSTNAME=""
if [ -n "${SSH_CONNECTION}" ]; then
HOSTNAME="@${2}"
fi
local DIRECTORY="${3}"
if [ "${DIRECTORY}" = "${HOME}" ]; then
DIRECTORY="~"
fi
local GIT_BRANCH
GIT_BRANCH="$(__git_ps1 " @%s")"
local LENGTH="$(( EXTRA_SPACE + ${#USERNAME} + ${#HOSTNAME} + ${#DIRECTORY} + ${#GIT_BRANCH} ))"
printf '%*s' "${LENGTH}" ""
return "${EXIT}"
}
PS2='$(__whitespace_ps2 \u \h \W)\001${__yellow_ps}${__bold_ps}\002|\001${__normal_ps}\002 '