-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
239 lines (202 loc) · 6.77 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Add local/bin and .local/bin
export PATH=/usr/local/bin:~/.local/bin:$PATH
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
if [[ $- != *i* ]] ; then
# Shell is non-interactive. Be done now!
return
fi
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export GOPATH=~/.go
if [ -e /usr/share/terminfo/x/xterm-256color ]; then
export TERM='xterm-256color'
elif [ -e /usr/share/terminfo/g/gnome-256color ]; then
export TERM='gnome-256color'
elif [ -e /usr/share/terminfo/x/xterm+256color ]; then
export TERM='xterm-256color'
elif [ -e /usr/share/terminfo/78/xterm-256color ]; then
export TERM='xterm-256color'
else
export TERM='screen-256color'
fi
# VIM is the best
if [ -x /usr/local/bin/vim ]; then
export EDITOR=/usr/local/bin/vim
elif [ -x /usr/bin/vim ]; then
export EDITOR=/usr/bin/vim
elif [ -x /usr/local/bin/vi ]; then
export EDITOR=/usr/local/bin/vi
elif [ -x /usr/bin/vi ]; then
export EDITOR=/usr/bin/vi
fi
# Defining Colors Used
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 190)
PURPLE=$(tput setaf 141)
WHITE=$(tput setaf 255)
BLACK=$(tput setaf 80)
else
MAGENTA=$(tput setaf 5)
ORANGE=$(tput setaf 4)
GREEN=$(tput setaf 2)
PURPLE=$(tput setaf 1)
WHITE=$(tput setaf 7)
BLACK=$(tput setaf 0)
fi
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
MAGENTA="\e[1;31m"
ORANGE="\e[1;33m"
GREEN="\e[1;32m"
BLUE="\e[1;34m"
PURPLE="\e[1;35m"
WHITE="\e[1;37m"
BOLD=""
BLACK="\e[0;0m"
RESET="\e[0m"
fi
# Simple colors for functions
BORDER=$BOLD$WHITE
USERCOLOR=$ORANGE
RETOKCOLOR=$GREEN
RETNOKCOLOR=$BOLD$MAGENTA
HOSTCOLOR=$BLACK
PWDCOLOR=$BOLD$GREEN
# Set the virtualenvwrapper variables
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/devel
# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# append to the history file, don't overwrite it
shopt -s histappend
# make sure variables are expanded on prompts
shopt -s promptvars
# mac cases... ugh
bind "set completion-ignore-case on"
# 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 ] && export LESSOPEN="|lesspipe %s"
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
eval "`dircolors -b`"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# Enable virtualenvwrapper if available
if [ -f /usr/local/bin/virtualenvwrapper.sh ]; then
. /usr/local/bin/virtualenvwrapper.sh
fi
SSH_ENV="$HOME/.ssh/env"
function start_agent {
if [ -n "$SSH_AUTH_SOCK" ]; then
# agent was forwarded, don't spawn
return
fi
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add
}
# Source SSH settings, if applicable
if [ -r /usr/local/bin/agent.sh ]; then
. /usr/local/bin/agent.sh
elif [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo -e "${PURPLE}*${BORDER}"
}
function parse_git_branch {
echo -ne "${ORANGE}"
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
function return_code() {
echo -ne "$BORDER<"
if [ $1 != "0" ]; then
echo -ne "${RETNOKCOLOR}${1}"
else
echo -ne "${RETOKCOLOR}${1}"
fi
echo -ne "$BORDER>"
}
function gitignore() {
if [ "$1" == "" ]; then
echo "Usage: gitignore <language name>"
echo ""
echo "Downloads a handy pre-made gitignore file for a given language."
echo "Full list available at https://github.com/github/gitignore."
return 1
fi
if [ -f ./.gitignore -a "$2" != "a" ]; then
echo ".gitignore already exists!" >&2
return 1
fi
lang=$1
base_url="https://raw.githubusercontent.com/github/gitignore/master"
url="$base_url/$lang.gitignore"
curl -fs $url >> .gitignore
if [ $? -gt 0 ]; then
echo "Could not fetch $url" >&2
return 1
fi
echo "Fetched $url"
}
function get_virtualenv() {
if [ -n "$VIRTUAL_ENV" ]; then
echo $(basename $VIRTUAL_ENV)
else
echo "no venv"
fi
}
# export PS1="${BORDER}┌─[${USERCOLOR}\u${BORDER}]─[\$(return_code \$?)${BORDER}]──[${HOSTCOLOR}${HOSTNAME%%.*}${BORDER}]:${PWDCOLOR}\w${BORDER}\n${BORDER}└──(${GREEN}\$(get_virtualenv)${BORDER})>>\$(parse_git_branch)${RESET}${BORDER}$ ${RESET}"
# export PS1="${BORDER}[${USERCOLOR}\u${BORDER}]\$(return_code \$?)${BORDER}[${HOSTCOLOR}${HOSTNAME%%.*}${BORDER}]:${PWDCOLOR}\w${GREEN}\$(get_virtualenv)${BORDER})>>\$(parse_git_branch)${BORDER}$ "
PS1_USER="${USERCOLOR}\u${RESET}"
PS1_HOST="${HOSTCOLOR}${HOSTNAME%%.*}${RESET}"
SEP="${BOLD}${BORDER},${RESET}"
BOXIN="${BORDER}[${RESET}"
BOXOUT="${BORDER}]${RESET}"
VENV="${ORANGE}\$(get_virtualenv)${RESET}"
GIT="\$(parse_git_branch)${RESET}"
CWD="${PWDCOLOR}\w${RESET}"
export PS1="${BOXIN}${PS1_USER}${SEP}${PS1_HOST}${BOXOUT}\$(return_code \$?)${BOXIN}${VENV}${SEP}${GIT}${BOXOUT}${CWD}${RESET}\n\$ "