-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbash.sh
executable file
·312 lines (281 loc) · 8 KB
/
bash.sh
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# Combined bash configuration file, sourced by both bashrc and
# bash_profile.
export PATH="$HOME/.local/bin:$HOME/.cache/npm/bin:${PATH}"
# export LANG=POSIX
export LC_CTYPE=de_DE.UTF-8
export LC_NUMERIC=POSIX
export LC_TIME=POSIX
export LC_COLLATE=de_DE.UTF-8
export LC_MONETARY=POSIX
export LC_MESSAGES=POSIX
export LC_PAPER=POSIX
export LC_NAME=POSIX
export LC_ADDRESS=POSIX
export LC_TELEPHONE=POSIX
export LC_MEASUREMENT=POSIX
export LC_IDENTIFICATION=POSIX
export LC_ALL=
export EDITOR=vi
if [ -f "$HOME/.email" ]
then
export EMAIL=$(cat "$HOME/.email")
fi
export HISTCONTROL=ignoredups
export LESS="-MIRnX"
export LESSCHARSET=utf-8
export SCREENDIR="$HOME/.cache/screen"
export PYTHONSTARTUP="$HOME/Projects/Config/pythonrc.py"
unset PYTHONDONTWRITEBYTECODE
# Utterly ridiculous Debian whackery:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=852398
export CHROMIUM_FLAGS="--enable-remote-extensions"
export PROJECT_HOME="$HOME/Projects"
alias rot13='tr a-zA-Z n-za-mN-ZA-M'
alias mv='mv -i'
alias %='fg'
alias sc="screen -rd"
alias be="bundle exec"
alias fr="bundle exec foreman run"
if type virtualenvwrapper.sh &>/dev/null
then
if [ -z "$VIRTUALENVWRAPPER_PYTHON" ]
then
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
fi
. virtualenvwrapper.sh
fi
if [ -f "/etc/bash_completion" ]
then
. /etc/bash_completion
fi
if [ -f "$HOME/.virtualenvs/aws/bin/aws_bash_completer" ]
then
. "$HOME/.virtualenvs/aws/bin/aws_bash_completer"
fi
if [ -d "$HOME/Programs/pyenv" ]
then
export PYENV_ROOT="$HOME/Programs/pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
# eval "$(pyenv init -)"
fi
if [ -d "$HOME/Programs/go" ]
then
export GOROOT="$HOME/Programs/go"
export PATH="$GOROOT/bin:$PATH"
fi
if [ -d "$HOME/.local/gopath/" ]
then
export GOPATH="$HOME/.local/gopath/"
export PATH="$GOPATH/bin:$PATH"
fi
if [ -d "$HOME/.nvm" ]
then
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
fi
if [ -d "$HOME/.rbenv" ]
then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
fi
if [ -d "/usr/lib/chromium" ]
then
export PATH="/usr/lib/chromium:$PATH"
fi
# Only in interactive shells
if [ -n "$PS1" ]
then
shopt -s checkwinsize
set nocaseglob
# cd with history
cd () {
if [ "$1" = "-" ]
then
popd &>/dev/null
elif [ "$1" = "" ]
then
pushd ~ &>/dev/null
elif [ ! -d "$1" ]
then
echo "cd: $1: Not a directory" >&2
return 1
else
pushd "$@" &>/dev/null
fi
}
# Colors in non-dumb terminals or in Emacs
if [ "$EMACS" = "t" ] || [ "$TERM" != "dumb" ]
then
eval `dircolors -b`
alias ls='ls -F --color=auto'
alias grep='grep --color --exclude-dir=.svn --exclude-dir=.git --exclude="*.pyc"'
else
alias ls='ls -F'
alias grep='grep --exclude-dir=.svn --exclude-dir=.git'
fi
# A workon command for generic projects
function wo () {
local name="$1"
if [ -z "$name" ]
then
echo "usage: wo <project>" >&2
echo >&2
echo "Possible projects:" >&2
echo >&2
/bin/ls "$HOME/Projects" >&2
fi
if [ ! -d "$HOME/Projects/$name" ]
then
echo "No such project: $name" >&2
return 1
fi
cd "$HOME/Projects/$name"
if [ -f ".env" ]
then
set -a
. .env
set +a
fi
if [ -d "$HOME/.virtualenvs/$name" ]
then
workon "$name"
fi
}
complete -o default -o nospace -F _projects wo
function _projects () {
COMPREPLY=($(compgen -W "`/bin/ls "$HOME/Projects"`" -- "$2"))
}
# And now, the prompt
if type tput &>/dev/null && tput setaf 1 >&/dev/null
then
c_reset="\\[`tput sgr0`\\]"
c_bold="\\[`tput bold`\\]"
c_underline="\\[`tput smul`\\]"
c_nounderline="\\[`tput rmul`\\]"
c_reverse="\\[`tput rev`\\]"
c_standout="\\[`tput smso`\\]"
c_nostandout="\\[`tput rmso`\\]"
c_black="\\[`tput setaf 0`\\]"
c_red="\\[`tput setaf 1`\\]"
c_green="\\[`tput setaf 2`\\]"
c_yellow="\\[`tput setaf 3`\\]"
c_blue="\\[`tput setaf 4`\\]"
c_magenta="\\[`tput setaf 5`\\]"
c_cyan="\\[`tput setaf 6`\\]"
c_white="\\[`tput setaf 7`\\]"
c_bgblack="\\[`tput setab 0`\\]"
c_bgred="\\[`tput setab 1`\\]"
c_bggreen="\\[`tput setab 2`\\]"
c_bgyellow="\\[`tput setab 3`\\]"
c_bgblue="\\[`tput setab 4`\\]"
c_bgmagenta="\\[`tput setab 5`\\]"
c_bgcyan="\\[`tput setab 6`\\]"
c_bgwhite="\\[`tput setab 7`\\]"
else
c_reset=""
c_bold=""
c_underline=""
c_nounderline=""
c_reverse=""
c_standout=""
c_nostandout=""
c_black=""
c_red=""
c_green=""
c_yellow=""
c_blue=""
c_magenta=""
c_cyan=""
c_white=""
c_bgblack=""
c_bgred=""
c_bggreen=""
c_bgyellow=""
c_bgblue=""
c_bgmagenta=""
c_bgcyan=""
c_bgwhite=""
fi
export PROMPT_COMMAND=set_prompt
function set_prompt () {
# Store this for later
local last_exit="$?"
local cwd_info=""
if [[ "$USER" != 'forcer' && "$USER" != 'schaefer' && "$USER" != 'jorgen' ]]
then
# If we are not our usual users, add the username
cwd_info='\u@\h:\w'
elif [[ -n "$SSH_CONNECTION" ]]
then
# If not, but we are logged in remotely, use the host name
cwd_info='\h:\w'
else
# Otherwise, working directory only
cwd_info='\w'
fi
local ret_info=""
if [[ "$last_exit" != 0 ]]
then
ret_info="$last_exit"
fi
local venv_info=""
if [[ -n "$VIRTUAL_ENV" ]]
then
venv_info="$(basename "$VIRTUAL_ENV")"
fi
local git_dirty_info=""
local git_clean_info=""
if git rev-parse --git-dir > /dev/null 2>&1
then
local git_branch=$(git branch 2>/dev/null | sed -ne 's/^\* //p')
if [ $(git status --porcelain 2>/dev/null | wc -l) -gt 0 ]
then
git_dirty_info="$git_branch"
git_clean_info=""
else
git_dirty_info=""
git_clean_info="$git_branch"
fi
fi
local na_docker_info=""
if [ -n "$DOCKER_HOST" ]
then
local na_docker_host
local na_docker_env="$(echo "$DOCKER_HOST" | awk -F. '{print $3}')"
if [[ "$DOCKER_HOST" == *'swarm'* ]]
then
na_docker_host=swarm
else
na_docker_host="$(echo "$DOCKER_HOST" | sed -e 's,tcp://\([^.]*\)\..*,\1,')"
fi
na_docker_info="${na_docker_env}@${na_docker_host}"
fi
local info_line=""
function add_info () {
local col="$1"
local name="$2"
local val="$3"
if [[ -n "$val" ]]
then
local this_line="$col$c_bold$name$c_reset$col:$val$c_reset"
info_line="$info_line $this_line"
fi
}
add_info "$c_red" ret "$ret_info"
add_info "$c_blue" venv "$venv_info"
add_info "$c_blue" git "$git_clean_info"
add_info "$c_magenta" git "$git_dirty_info"
add_info "$c_blue" docker "$na_docker_info"
if [[ -n "$info_line" ]]
then
local line1="$c_reset[${info_line# }]$c_reset"
local line2="$c_blue$cwd_info$c_reset"
local line3="$c_blue\\\$$c_reset "
PS1="$c_reset\n$line1\n$line2\n$line3"
else
local line1="$c_blue$cwd_info$c_reset"
local line2="$c_blue\\\$$c_reset "
PS1="$c_reset\n$line1\n$line2"
fi
}
fi