-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
161 lines (133 loc) · 4.2 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
# .bashrc for OS X and Ubuntu
# ====================================================================
# System default
# --------------------------------------------------------------------
export BASH_SILENCE_DEPRECATION_WARNING=1
[[ $- != *i* ]] && return
export PLATFORM=$(uname -s)
[ -f /etc/bashrc ] && . /etc/bashrc
# Options
# --------------------------------------------------------------------
### Bash completion
[ -f /etc/bash_completion ] && . /etc/bash_completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
### Disable CTRL-S and CTRL-Q
stty -ixon && bind '\C-w:backward-kill-word'
# Environment variables
# --------------------------------------------------------------------
### Append to the history file
shopt -s histappend
export HISTCONTROL=ignoreboth:erasedups
export PROMPT_COMMAND="history -n; history -w; history -c; history -r; $PROMPT_COMMAND"
export HISTSIZE=1000
export HISTFILESIZE=
### man bash
export HISTIGNORE='fg'
### Global
export GOPATH="$HOME/tools/go"
if [ -z "$PATH_EXPANDED" ]; then
export PATH="$HOME/.local/bin:$HOME/.bin:$HOME/.cargo/bin:$GOPATH/bin:/usr/local/bin:/usr/local/sbin:$PATH"
export LESS='-F -X -R '$LESS
export PATH_EXPANDED=1
fi
export EDITOR=vim
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
### OS X
export COPYFILE_DISABLE=true
if [ -x /usr/bin/dircolors ]; then
eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias grep='grep --color=auto'
elif [ "$PLATFORM" = Darwin ]; then
alias ls='ls -G'
fi
alias ..='cd ..'
alias ...='cd ../..'
alias l='ls -alF'
alias ll='ls -l'
alias cdpath="export CDPATH=.:$PWD"
# Prompt
# --------------------------------------------------------------------
if [ -n "$SSH_CONNECTION" ]; then
PS1="\h:\w> "
else
PS1="\w> "
fi
# Shortcut functions
# --------------------------------------------------------------------
mvim() {
if [ -n "$1" ]; then
command mvim --remote-silent "$@"
elif [ -n "$(command mvim --serverlist)" ]; then
command mvim --remote-send ":call foreground()<CR>:enew<CR>:<BS>"
else
command mvim
fi
}
viw() {
vim "$(which "$1")"
}
# fzf (https://github.com/junegunn/fzf)
# --------------------------------------------------------------------
export FZF_DEFAULT_COMMAND='rg --files'
export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden:wrap --bind '?:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --header 'Press CTRL-Y to copy command into clipboard' --border"
export FZF_DEFAULT_OPTS="--no-bold"
# v - open files in ~/.viminfo
v() {
local files
files=$(grep '^>' ~/.viminfo | cut -c3- |
while read line; do
[ -f "${line/\~/$HOME}" ] && echo "$line"
done | fzf -d -m -q "$*" -1) && vim ${files//\~/$HOME}
}
unalias z 2>/dev/null
z() {
[ $# -gt 0 ] && _z "$*" && return
cd "$(_z -l 2>&1 | fzf --height 40% --nth 2.. --reverse --inline-info +s --tac --query "${*##-* }" | sed 's/^[0-9,.]* *//')"
}
# fzf end
# --------------------------------------------------------------------
TMUX_SESSION=$USER
if [[ -n "$BASHRC_TMUX_SESSION" ]]; then
TMUX_SESSION="$TMUX_SESSION-$BASHRC_TMUX_SESSION"
fi
if [[ -z "$TMUX" && -n "$SSH_TTY" ]] && which tmux >&/dev/null; then
if ! tmux ls -F '#{session_name}' | egrep -q "^$TMUX_SESSION$"; then
tmux new-session -s $TMUX_SESSION \; detach
fi
session_max=$(tmux ls -F '#{session_name}' |
egrep "^$TMUX_SESSION-[0-9]+$" |
sed "s/^$TMUX_SESSION-//" |
sort -rn |
head -n1)
session_index=$((${session_max:--1} + 1))
exec tmux new-session -s $TMUX_SESSION-$session_index -t $TMUX_SESSION
fi
[ -f ~/.bashrc.local ] && source ~/.bashrc.local
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.tar.xz) tar xvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "I don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
mcd() { mkdir -p "$@" && eval cd "\"\$$#\""; }
. "$HOME/.cargo/env"
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[ -f ~/.fzf.bash ] && source ~/.fzf.bash