forked from xingchensong/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
214 lines (188 loc) · 5.3 KB
/
bashrc
File metadata and controls
214 lines (188 loc) · 5.3 KB
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
# History control
HISTCONTROL=ignoredups:ignorespace
HISTSIZE=100000
HISTFILESIZE=2000000
shopt -s histappend
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
alias grep='grep --color=auto'
alias gg='git grep -ni'
alias phpunit='phpunit --colors'
alias vimpress="VIMENV=talk vim"
alias biggest="du -h --max-depth=1 | sort -h"
alias tnn="cd ~/src/github.com/tomnomnom"
alias :q="exit"
alias norg="gron --ungron"
alias ungron="gron --ungron"
alias follow="tail -f -n +1"
# vi alias
alias vi='vim'
# git aliasess
if git --version > /dev/null 2>&1; then
alias gb='git branch'
alias gad='git add'
alias gc='git checkout'
alias gcb='git checkout -b'
alias gs='git status'
alias gst='git status'
alias gcm='git checkout master'
alias gpom='git pull origin master'
alias gmm='git merge master'
fi
# ls aliases for linux (macos use bsd ls, which does not have --color option)
export LSCOLORS=Exfxcxdxbxegedabagacad
if [[ $(uname) != Darwin ]]; then
alias ls="ls --color"
alias ll="ls -l --color"
alias la="ls -la --color"
alias lsd="ls -lF -color | grep --color=never '^d'"
fi
# grep aliases
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# avoid overwriting another file
alias mv='mv -i'
alias cp='cp -i'
alias rm='rm -i'
# cd aliases
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
# gpustat aliases
alias nv='gpustat'
alias ns='nvidia-smi'
# COLOURS! YAAAY!
export TERM=xterm-256color
# Obviously.
export EDITOR=/usr/bin/vim
# Personal binaries
export PATH=${PATH}:~/bin:~/.local/bin:~/etc/scripts
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$HOME/.local/lib:/usr/lib
# I'd quite like for Go to work please.
export PATH=${PATH}:/usr/local/go/bin
export GOPATH=~
# Change up a variable number of directories
# E.g:
# cu -> cd ../
# cu 2 -> cd ../../
# cu 3 -> cd ../../../
function cu {
local count=$1
if [ -z "${count}" ]; then
count=1
fi
local path=""
for i in $(seq 1 ${count}); do
path="${path}../"
done
cd $path
}
# Open all modified files in vim tabs
function vimod {
vim -p $(git status -suall | awk '{print $2}')
}
# Open files modified in a git commit in vim tabs; defaults to HEAD. Pop it in your .bashrc
# Examples:
# virev 49808d5
# virev HEAD~3
function virev {
commit=$1
if [ -z "${commit}" ]; then
commit="HEAD"
fi
rootdir=$(git rev-parse --show-toplevel)
sourceFiles=$(git show --name-only --pretty="format:" ${commit} | grep -v '^$')
toOpen=""
for file in ${sourceFiles}; do
file="${rootdir}/${file}"
if [ -e "${file}" ]; then
toOpen="${toOpen} ${file}"
fi
done
if [ -z "${toOpen}" ]; then
echo "No files were modified in ${commit}"
return 1
fi
vim -p ${toOpen}
}
# 'Safe' version of __git_ps1 to avoid errors on systems that don't have it
function gitPrompt {
command -v __git_ps1 > /dev/null && __git_ps1 " (%s)"
}
# Colours have names too. Stolen from Arch wiki
txtblk='\[\e[0;30m\]' # Black - Regular
txtred='\[\e[0;31m\]' # Red
txtgrn='\[\e[0;32m\]' # Green
txtylw='\[\e[0;33m\]' # Yellow
txtblu='\[\e[0;34m\]' # Blue
txtpur='\[\e[0;35m\]' # Purple
txtcyn='\[\e[0;36m\]' # Cyan
txtwht='\[\e[0;37m\]' # White
bldblk='\[\e[1;30m\]' # Black - Bold
bldred='\[\e[1;31m\]' # Red
bldgrn='\[\e[1;32m\]' # Green
bldylw='\[\e[1;33m\]' # Yellow
bldblu='\[\e[1;34m\]' # Blue
bldpur='\[\e[1;35m\]' # Purple
bldcyn='\[\e[1;36m\]' # Cyan
bldwht='\[\e[1;37m\]' # White
unkblk='\[\e[4;30m\]' # Black - Underline
undred='\[\e[4;31m\]' # Red
undgrn='\[\e[4;32m\]' # Green
undylw='\[\e[4;33m\]' # Yellow
undblu='\[\e[4;34m\]' # Blue
undpur='\[\e[4;35m\]' # Purple
undcyn='\[\e[4;36m\]' # Cyan
undwht='\[\e[4;37m\]' # White
bakblk='\[\e[40m\]' # Black - Background
bakred='\[\e[41m\]' # Red
badgrn='\[\e[42m\]' # Green
bakylw='\[\e[43m\]' # Yellow
bakblu='\[\e[44m\]' # Blue
bakpur='\[\e[45m\]' # Purple
bakcyn='\[\e[46m\]' # Cyan
bakwht='\[\e[47m\]' # White
txtrst='\[\e[0m\]' # Text Reset
# Prompt colours
atC="${txtcyn}"
nameC="${txtcyn}"
hostC="${txtcyn}"
pathC="${txtwht}"
gitC="${txtcyn}"
pointerC="${txtwht}"
normalC="${txtwht}"
# Red name for root
if [ "${UID}" -eq "0" ]; then
nameC="${txtred}"
fi
# Patent Pending Prompt
export PS1="${nameC}\u${atC}@${hostC}\h:${pathC}\w${gitC}\$(gitPrompt)${pointerC}\n▶${normalC} "
# Local settings go last
if [ -f ~/.localrc ]; then
source ~/.localrc
fi
conda_path="/bucket/output/jfs-hdfs/user/xingchen.song/tools/miniconda3/bin"
if [ ! -e "${conda_path}/conda" ]; then
conda_path="${HOME}/tools/miniconda3/bin"
fi
conda_bin=${conda_path}/conda
if [ -e "${conda_bin}" ]; then
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
unset CONDA_SHLVL
__conda_setup="$(${conda_bin} 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "${conda_path}/../../../tools/miniconda3/etc/profile.d/conda.sh" ]; then
. "${conda_path}/../../../tools/miniconda3/etc/profile.d/conda.sh"
else
export PATH="${conda_path}/../../../tools/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
fi
[[ -s ${HOME}/.autojump/etc/profile.d/autojump.sh ]] && source ${HOME}/.autojump/etc/profile.d/autojump.sh