-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc
267 lines (222 loc) · 7.23 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
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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# if not running interactively, don't do anything
#[ -z "$PS1" ] && return
case $- in
*i*) ;;
*) return;;
esac
# if this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
#bindirs=("/bin" "/sbin")
#bindir=${bindirs[$RANDOM % ${#bindirs[@]} ]}
#echo "Did you know this command: $(whatis $(ls ${bindir} | shuf -n 1)) ?"
#echo $(ddate)
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth:erasedups
# history size
HISTSIZE=1000
HISTFILESIZE=2000
# append to the history file, don't overwrite it
shopt -s histappend
# allow to review a history substitution result by loading the resulting line
# into the editing buffer, rather than directly executing it.
shopt -s histverify
# save multi-line commands as one command
shopt -s cmdhist
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# bash completion auto-correction
shopt -s cdspell
# 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 ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# add an "alert" alias for long running commands; use like so: sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Working autocompletion for aliases, see:
# http://ubuntuforums.org/showthread.php?t=733397
function make-completion-wrapper () {
local function_name="$2"
local arg_count=$(($#-3))
local comp_function_name="$1"
shift 2
local function="
function $function_name {
((COMP_CWORD+=$arg_count))
COMP_WORDS=( "$@" \${COMP_WORDS[@]:1} )
"$comp_function_name"
return 0
}"
eval "$function"
}
# !!<space> will replace the !! with your last command
bind Space:magic-space
# treat hyphens and underscores as equivalent for completion
bind "set completion-map-case on"
# display completion matches for ambiguous patterns at first tab press
bind "set show-all-if-ambiguous on"
source /home/tudor/src/dotfiles/scripts/git-completion.sh
source /home/tudor/src/dotfiles/scripts/git-prompt.sh
# general aliases
alias q='exit'
alias d='du -h'
alias l='ls -oAhpv --color --group-directories-first'
alias k='killall -v -i -s 9 -u $USER'
alias rm='rm -I'
alias t2='tmux -2'
alias t='tmux attach'
alias ~='cd ~'
alias b='cd -'
alias v='nvim'
alias gp='grep --color=auto -rn . -e'
alias c='reset'
alias gg='gitk'
alias f='find . -name'
alias src='source ~/.bashrc'
alias srcd='cd ~/src/dotfiles'
alias _='sudo'
alias p='ps -alyH --forest'
alias pn='ping -OD'
alias pud='pushd'
alias pudd='pushd .'
alias pod='popd'
alias dr='dirs'
alias vrc='nvim ~/.vimrc'
alias mp='mkdir -p'
alias tree='tree -aFC --dirsfirst -L 7 -I .git'
alias r='ranger .'
alias js='node'
alias cdv='cdvirtualenv'
alias ds='dig +short'
alias off='sudo poweroff'
alias fuck='sudo $(history -p \!\!)' # repeat last command with sudo
alias epoch='date +%s'
alias wan='dig +short myip.opendns.com @resolver1.opendns.com'
alias u='uptime'
alias rlf='readlink -f'
alias vimdiff='nvim -d'
alias g='git'
complete -o default -o nospace -F _git g
alias gnwd='~/bin/git-new-workdir.sh'
alias ..='cd ..'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
# kills a process tree specified by the root
function exterminate() {
kill -9 -$(ps | grep $1 | grep -v grep | awk '{print $1}')
}
# creates a directory tree (linear) with a file leaf
function mktree() {
mkdir -p $1
touch $1/$2
}
# creates a directory and navigates to it
function mkcd() {
mkdir -p "$1"
cd "$1";
}
# navigates to a directory and lists it
function cl() {
if [ -d $1 ]; then
cd $1
else
cd $HOME
fi
ls
}
# other aliases go in a separate file
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# vim bash shell mode
set -o vi
LASTCMD=$(date +%s)
# the bash shell prompt; shows the load(1), time, day-of-month, login, host path,
# git branch, and virtualenv
function set_ps1 {
green="\[\e[32;2m\]"
orange="\[\e[33;1m\]"
red="\[\e[31;1m\]"
cyan="\[\e[34;1m\]"
purple="\[\e[38;5;91;1m\]"
nocol="\e[m"
# calcultate time since last prompt
local _now=$(date +%s)
local _diff=$( printf "%02d:%02d:${orange}%02d${nocol}" \
$(( ( _now - LASTCMD ) / 3600)) \
$(( (( _now - LASTCMD ) % 3600) / 60 )) \
$(( ( _now - LASTCMD ) % 60)) \
)
LASTCMD=${_now}
local git=$(__git_ps1 " (%s)")
if [[ -z $git ]]; then
git=" "
fi
if [[ -z ${VIRTUAL_ENV##*/} ]]; then
local venv=""
else
local venv="<${VIRTUAL_ENV##*/}>"
fi
local load=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g")
export PS1="${red}${load}${nocol}|${cyan}\j${nocol}|${_diff}|$(date +"%H:%M.")${cyan}$(date +"%d")${nocol}|\u@${red}\h${nocol}:${green}\w${nocol}${purple}${git}${nocol}${red}${venv}${nocol}\n$ ";
}
export PROMPT_COMMAND=set_ps1
# after each command, save and reload history: http://unix.stackexchange.com/questions/1288
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"
# include user's bin/ directory
if [ -d "$HOME/bin" ]; then
export PATH=$HOME/bin:$PATH
fi
# we prefer nvim for SVN, Git, etc.
export SVN_EDITOR=nvim
export EDITOR=nvim
export VISUAL=nvim
# git-prompt exports
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM="auto git"
#export GIT_PS1_DESCRIBE_STYLE=branch
# actually see Python output in some environments like Foreman
#export PYTHONUNBUFFERED=True
# Heroku Toolbelt: https://toolbelt.heroku.com/
export PATH="/usr/local/heroku/bin:$PATH"
# Go development
#export PATH=$PATH:$(go env GOPATH)/bin
#export GOPATH=$(go env GOPATH)
#source /usr/share/virtualenvwrapper/virtualenvwrapper.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
export PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV="true"
export WORKON_HOME=$HOME/.virtualenvs
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
pyenv virtualenvwrapper_lazy
. "$HOME/.cargo/env"