forked from larrylv/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbashrc
242 lines (198 loc) · 6.93 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
# vim:ft=sh:
# alias
alias af='git ls-files | ack --smart-case --no-column --noenv'
alias be='bundle exec'
alias bi='bundle install --path=vendor/bundle --binstubs=.binstubs'
alias cat='ccat'
alias grep='grep --color=auto'
alias gtags='ctags -R --languages=-javascript --exclude=.git --exclude=log --exclude=target --fields=+ialS --extra=+q .'
alias ki='kiex'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias mcopy='reattach-to-user-namespace pbcopy'
alias mpaste='reattach-to-user-namespace pbpaste'
alias nvs='nvim -S Session.vim'
alias pt='pstree'
alias rb='rbenv'
alias rtags='~/.rbenv/versions/2.3.0/gemsets/global/bin/ripper-tags -R'
alias ssh='TERM=xterm ssh'
alias tailf='tail -f'
alias tigs='tig status'
alias vless='/usr/local/opt/vim/share/vim/vim74/macros/less.sh'
alias vs='vim -S Session.vim'
# bash-sensible (https://github.com/mrzool/bash-sensible/blob/master/sensible.bash)
## Prevent file overwrite on stdout redirection
## # Use `>|` to force redirection to an existing file
set -o noclobber
## Enable history expansion with space
## E.g. typing !!<space> will replace the !! with your last command
bind Space:magic-space
## Turn on recursive globbing (enables ** to recurse all directories)
shopt -s globstar 2> /dev/null
## SMARTER TAB-COMPLETION (Readline bindings) ##
## Perform file completion in a case insensitive fashion
bind "set completion-ignore-case on"
## Treat hyphens and underscores as equivalent
bind "set completion-map-case on"
## Display matches for ambiguous patterns at first tab press
bind "set show-all-if-ambiguous on"
## Save multi-line commands as one command
shopt -s cmdhist
## Enable incremental history search with up/down arrows (also Readline goodness)
## Learn more about this here: http://codeinthehole.com/writing/the-most-important-command-line-tip-incremental-history-searching-with-inputrc/
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[C": forward-char'
bind '"\e[D": backward-char'
## Prepend cd to directory names automatically
shopt -s autocd 2> /dev/null
## Correct spelling errors during tab-completion
shopt -s dirspell 2> /dev/null
## Correct spelling errors in arguments supplied to cd
shopt -s cdspell 2> /dev/null
# environment
export CLICOLOR=1
export EDITOR=vim
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
## go
### For Mac: brew install go && sudo ln -s /usr/local/opt/go/libexec /usr/local/go
### For Ubuntu: sudo tar -C /usr/local -xzf go{version}.src.tar.gz
export GOROOT=/usr/local/go
export GOPATH=$HOME/.gopath
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
## rbenv
export PATH=$HOME/.rbenv/bin:$PATH
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
## kiex
# shellcheck disable=SC1090
[[ -s "$HOME/.kiex/scripts/kiex" ]] && source "$HOME/.kiex/scripts/kiex"
## jEnv
export PATH="$HOME/.jenv/bin:$PATH"
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
## binstubs
export PATH=.binstubs:$PATH
## history
shopt -s histappend
export HISTSIZE=100000
export HISTFILESIZE=100000
export HISTCONTROL=ignoredups
## Use standard ISO 8601 timestamp
## %F equivalent to %Y-%m-%d
## %T equivalent to %H:%M:%S (24-hours format)
export HISTTIMEFORMAT='%F %T '
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"
# source scripts -----------------------------------------------------------#{{{
## bash completion
bash_completion="$(brew --prefix 2>/dev/null)/etc/bash_completion"
if [ -r "$bash_completion" ]; then
# shellcheck disable=SC1090
source "$bash_completion"
fi
unset bash_completion
## git completion
git_completion="$(brew --prefix 2>/dev/null)/etc/bash_completion.d/git-completion.bash"
if [ -r "$git_completion" ]; then
# shellcheck disable=SC1090
source "$git_completion"
fi
unset git_completion
## vagrant completion
vagrant_completion="$(brew --prefix 2>/dev/null)/etc/bash_completion.d/vagrant"
if [ -r "$vagrant_completion" ]; then
# shellcheck disable=SC1090
source "$vagrant_completion"
fi
unset vagrant_completion
## tmuxinator completion
tmuxinator_completion="$HOME/.tmuxinator.bash"
if [ -r "$tmuxinator_completion" ]; then
# shellcheck disable=SC1090
source "$tmuxinator_completion"
fi
unset tmuxinator_completion
## autojump script
autojump_script="$(brew --prefix 2>/dev/null)/etc/profile.d/autojump.sh"
if [ -r "$autojump_script" ]; then
# shellcheck disable=SC1090
source "$autojump_script"
fi
unset autojump_script
## colors script
# shellcheck disable=SC1090
[[ -s "$HOME/.colors.bash" ]] && source "$HOME/.colors.bash"
#}}}
# PS1 -------------------------------------------------------------------------#{{{
# shellcheck disable=SC2154
GIT_PROMPT_CLEAN=" ${echo_bold_green}✔"
# shellcheck disable=SC2154
GIT_PROMPT_DIRTY=" ${echo_bold_red}✗"
# shellcheck disable=SC2154
GIT_PROMPT_STASH=" ${echo_bold_purple}#"
GIT_PROMPT_NOSTASH=""
function parse_git_dirty () {
if [[ $(git status 2> /dev/null | tail -n1 | cut -c 1-17) != "nothing to commit" ]]; then
echo -e "$GIT_PROMPT_DIRTY"
else
echo -e "$GIT_PROMPT_CLEAN"
fi
}
function parse_git_stash() {
if [[ -n $(git stash list 2> /dev/null) ]]; then
echo -e "$GIT_PROMPT_STASH"
else
echo -e "$GIT_PROMPT_NOSTASH"
fi
}
function git_branch_name() {
echo -e "${echo_bold_purple}$(git symbolic-ref HEAD 2> /dev/null | sed -e "s/refs\/heads\///")"
}
function git_prompt_info() {
# shellcheck disable=SC2155
local ref="$(command git symbolic-ref -q HEAD 2>/dev/null)"
if [ -n "$ref" ]; then
# shellcheck disable=SC2154
echo -e " ${echo_bold_cyan}git:($(git_branch_name)${echo_bold_cyan})$(parse_git_dirty)$(parse_git_stash)"
fi
}
function rbenv_prompt_info() {
if which rbenv > /dev/null; then
if [ -f "$PWD/Gemfile" ] || [ ! -f "$PWD/mix.exs" ] ; then
echo -e " ${echo_bold_cyan}ruby:(${echo_bold_purple}$(rbenv version-name)${echo_bold_cyan})"
fi
fi
}
function kiex_prompt_info() {
if which kiex > /dev/null; then
if [ -f "$PWD/mix.exs" ]; then
echo -e " ${echo_bold_cyan}elixir:(${echo_bold_purple}$ELIXIR_VERSION${echo_bold_cyan})"
fi
fi
}
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
# shellcheck disable=SC2154
PS1="${bold_green}\u@\h ${bold_yellow}➜ ${bold_blue}\w\$(rbenv_prompt_info)\$(kiex_prompt_info)\$(git_prompt_info)${reset_color}\n${bold_green}\$ ${reset_color}"
else
PS1="${bold_yellow}➜ ${bold_blue}\w\$(rbenv_prompt_info)\$(kiex_prompt_info)\$(git_prompt_info)${reset_color}\n${bold_green}\$ ${reset_color}"
fi
#}}}
# set terminal title#{{{
setTerminalTitle () {
# echo works in bash & zsh
local mode=$1 ; shift
# shellcheck disable=SC2145
echo -ne "\033]$mode;$@\007"
}
# shellcheck disable=SC2068
set_both_title () { setTerminalTitle 0 $@; }
# shellcheck disable=SC2068
set_tab_title () { setTerminalTitle 1 $@; }
# shellcheck disable=SC2068
set_window_title () { setTerminalTitle 2 $@; }
alias s='set_tab_title'
#}}}
# Local config
# shellcheck disable=SC1090
[[ -f ~/.bashrc.local ]] && source ~/.bashrc.local