-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_bashrc
More file actions
178 lines (145 loc) · 4.66 KB
/
all_bashrc
File metadata and controls
178 lines (145 loc) · 4.66 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
# vim: filetype=sh
#
# This file gets sourced by the .bashrc for all OS
#
# Contributors: Fong Chun Chan <fongchun@alumni.ubc.ca>
# Source global definitions
if [[ -f /etc/bashrc ]]; then
source /etc/bashrc
fi
umask 002
# Needed to fix <c-h> binding for neovim
export TERMINFO="$HOME/.terminfo"
#----------
# Functions
#----------
# Extract function
function extract(){
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $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 ;;
*.xz) xz -d $1 ;;
*) echo "'$1' cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Counts the Number of Columns in a File
function num_cols(){
awk '{print NF}' $1 | sort -nu | tail -n 1
}
# Gets the first line of the tsv file and then returns each column as a separate
# line
function print_colnames() {
head -n 1 $1 | tr '\t' '\n' | less -S
}
# Used in PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Allows you to run any git command on an git repository without having to be in
# the repository itself.
#
# gg /path/to/repo command args
function gg () {
local _gg="$1";
shift;
git --git-dir="${_gg}/.git" --work-tree="${_gg}" "$@"
}
# https://gurdiga.github.io/blog/2018/04/14/bind-warning-line-editing-not-enabled/
function is_interactive_shell() {
# https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html
[[ "$-" =~ "i" ]]
}
#----------
# Git
#----------
# Set git text editor to nvim
export GIT_EDITOR=nvim
# Set autocomplete for git
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
#---------
# User interface
#---------
# Base16 shell colors
# Make sure you have install base16-shell (https://github.com/chriskempson/base16-shell)
BASE16_SHELL="${HOME}/.config/base16-shell/scripts/base16-default-dark.sh"
[[ "$-" == *i* ]] && [[ -s ${BASE16_SHELL} ]] && source ${BASE16_SHELL}
# Customize linux prompt
export PS1="\n[\u@\h] \D{%F %T}\n \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\n$> "
#----------
# User specific aliases
#----------
# Line numbers (`-N`) and tabs width = 2 space (`-x 2`)
alias less="less -N -x 2"
alias rsync="rsync -avr --partial --progress --rsh=ssh"
alias ls="ls -F"
alias pd="pushd"
alias bd="popd"
alias make="make --warn-undefined-variables"
alias vi="nvim"
alias vim="nvim"
alias 'tl=tree --du -h --dirsfirst -C'
alias weather="curl -s wttr.in"
# For attaching to tmux sessions. Using this alias allows for autocompletion of
# session names via bash completion.
# https://www.nathankowald.com/blog/2014/03/tmux-attach-session-alias
alias tma='tmux attach -t $1'
# Build the ctags for vim
alias vim_tags="ctags -R ."
alias top="htop"
# Rodeo applications
alias rodeo="open -a /Applications/rodeo.app/"
#----------
# Nvim-R (formally known as Vim-R-Plugin)
#----------
# Change the TERM environment variable (to get 256 colors) even if you are
# accessing your system through ssh and using either Tmux or GNU Screen:
if [ "$TERM" = "xterm" ] || [ "$TERM" = "xterm-256color" ]; then
export TERM=xterm-256color
export HAS_256_COLORS=yes
fi
if [ "$TERM" = "screen" ] && [ "$HAS_256_COLORS" = "yes" ]; then
export TERM=screen-256color
fi
#----------
# fzf: Fuzzy finder
#----------
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# Bind ctrl-f to ctrl-t
# ctrl-t will also activate fzf_select
# https://github.com/junegunn/fzf/issues/546
if is_interactive_shell; then
bind "$(bind -s | grep __fzf_select | sed 's/\\C-t/\\C-f/')"
fi
#
# Miniconda
#
# If conda is installed, add the bin folder to your PATH variable.
# Check if the argcomplete conda package is available, if so enable tab
# complete (http://conda.pydata.org/docs/install/tab-completion.html)
if [[ -d ${HOME}/miniconda3 ]]; then
. "${HOME}/miniconda3/etc/profile.d/conda.sh";
fi
# For iTerm2 integration with shell
# https://www.iterm2.com/documentation-shell-integration.html
#test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
# If there is a .custom_bashrc in the home directory, then source it.
# This is designed to allow for machine specific setups (e.g. alias commands
# that only work on a particular machine).
if [[ -f "${HOME}/.custom_bashrc" ]]; then
. "${HOME}/.custom_bashrc";
fi