-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
150 lines (123 loc) · 3.95 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# -*- bash -*-
# ~/.bashrc: executed by bash(1) for non-login shells.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# append to the history file, don't overwrite it
shopt -s histappend
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# Load bash completions
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# shellcheck source=/dev/null
source /etc/bash_completion
fi
# Load common alias definitions
if [ -f ~/.bash_aliases ]; then
# shellcheck source=/dev/null
source ~/.bash_aliases
fi
# Load common export definitions
if [ -f ~/.bash_exports ]; then
# shellcheck source=/dev/null
source ~/.bash_exports
fi
# If we have a private bin, include it at the FRONT of the path
if [ -d "$HOME/bin/" ]; then
PATH="$HOME/bin:$PATH"
fi
# Let's handle specific systems now
# OSX
if [ "$(uname)" == "Darwin" ]; then
if [ -f ~/.bash_osx ]; then
# shellcheck source=/dev/null
. ~/.bash_osx
fi
fi
# Configure pyenv
if [ -x "$(command -v pyenv)" ]; then
export PYENV_ROOT="${HOME}/.pyenv"
export PATH="${PYENV_ROOT}/bin:${PATH}"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# v--- Custom Functions ---v
deactivate () {
pyenv shell --unset
}
lsvirtualenv () {
pyenv virtualenvs --bare --skip-aliases
}
mkvirtualenv () {
pyenv virtualenv "${@}"
}
rmvirtualenv() {
pyenv uninstall "${@}"
}
workon () {
pyenv shell "${@}"
}
fi
set_ps1() {
# Define some box drawing hex
local double_horizontal=$'\xE2\x95\x90' # ═
local double_down_right=$'\xE2\x95\x94' # ╔
local double_vertical_right=$'\xE2\x95\xa0' # ╠
local double_up_and_right=$'\xE2\x95\x9A' # ╚
# Set prompt variables
local BBlue='\[\e[1;34m\]'
local BGreen='\[\e[1;32m\]'
local BRed='\[\e[1;31m\]'
local BWhite='\[\e[1;37m\]'
local Color_Off='\[\e[0m\]'
local Outline=$BWhite
local TermChar='$'
# Determine if root
if (( EUID == 0 )); then
# We ARE root, change prompt details
local Outline=$BRed
local TermChar='#'
fi
# Configure first prompt line
#
# ╔═[user@host : /current/working/directory]
PS1="$Outline${double_down_right}${double_horizontal}[$BGreen\\u@\\h$Color_Off $Outline: $BBlue\\w$Outline]$Outline\\n$Color_Off"
# Screen Checks
#
# ╠═[screen : screen_name]
if [ -n "$STY" ]; then
# Screen is up
PS1+="$Outline${double_vertical_right}${double_horizontal}[${BGreen}screen$Color_Off $Outline: $BBlue$STY$Outline]$Color_Off\\n"
fi
# Git check
#
# ╠═[git : branch_name]
if type __git_ps1 > /dev/null 2>&1 ; then
# Git is available, is this a git repo?
local Git_Branch
local Git_Branch_Length
Git_Branch=$(__git_ps1 "%s")
Git_Branch_Length=${#Git_Branch}
if (( "$Git_Branch_Length" > 0 )); then
# We indeed do have branch info
PS1+="$Outline${double_vertical_right}${double_horizontal}[${BGreen}git$Color_Off $Outline: $BBlue$Git_Branch$Outline]$Color_Off\\n"
fi
fi
# virtualenv check
#
# ╠═[virtualenv : virtualenv_name]
local venv="${PYENV_VERSION}"
if [[ ${venv} != "" ]]; then
# ${string##substring}
# Deletes longest match of $substring from front of $string.
PS1+="$Outline${double_vertical_right}${double_horizontal}[${BGreen}virtualenv${Color_Off} ${Outline}: ${BBlue}${venv}${Outline}]${Color_Off}\\n"
fi
# Configure final prompt line
#
# ╚═ $
PS1+="$Outline${double_up_and_right}${double_horizontal} $TermChar$Color_Off "
}
# Use function for prompts
PROMPT_COMMAND=set_ps1