-
Notifications
You must be signed in to change notification settings - Fork 0
/
zshrc
234 lines (185 loc) · 6.38 KB
/
zshrc
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
main() {
setup_aliases() {
alias vim=nvim
alias vi=nvim
alias ll="ls -al"
alias drm='docker rm $(docker ps -a -q)'
alias drmi='docker rmi $(docker images -q)'
alias h\?="history | grep"
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias localip="ipconfig getifaddr en0"
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"
alias ifactive="ifconfig | pcregrep -M -o '^[^\t:]+:([^\n]|\n\t)*status: active'"
# Empty the Trash on all mounted volumes and the main HDD.
# Also, clear Apple’s System Logs to improve shell startup speed.
# Finally, clear download history from quarantine. https://mths.be/bum
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl; sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'"
# Intuitive map function
# For example, to list all directories that contain a certain file:
# find . -name .gitattributes | map dirname
alias map="xargs -n1"
# Lock the screen (when going AFK)
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
# Print each PATH entry on a separate line
alias path='echo -e ${PATH//:/\\n}'
# kubernetes alias
alias k=kubectl
}
setup_environment() {
export CLICOLOR=1
export LSCOLORS exfxcxdxbxegedabagacad
# go environment
export GOPATH=$HOME/go
# setup path
export PATH=$GOPATH/bin:$PATH:/usr/local/go/bin:$HOME/scripts:/usr/local/opt/apr/bin:/usr/local/opt/apr-util/bin
export EDITOR=nvim
export FZF_COMPLETION_TRIGGER='~~'
export FZF_COMPLETION_OPTS='+c -x'
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border --inline-info'
export PATH=/usr/local/sbin:$PATH
export PATH=/usr/local/opt/gnu-tar/libexec/gnubin:$PATH
export PATH=/usr/local/opt/grep/libexec/gnubin:$PATH
export PATH=/usr/local/opt/gnu-sed/libexec/gnubin:$PATH
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
GPG_TTY=$(tty)
export GPG_TTY
}
setup_fzf() {
_fzf_compgen_path() {
fd --hidden --follow --exclude ".git" . "$1"
}
# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
fd --type d --hidden --follow --exclude ".git" . "$1"
}
}
setup_fasd() {
local fasd_cache
fasd_cache="$HOME/.fasd-init-zsh"
if [ "$(command -v fasd)" -nt "$fasd_cache" -o ! -s "$fasd_cache" ]; then
fasd --init posix-alias zsh-hook zsh-ccomp zsh-ccomp-install >| "$fasd_cache"
fi
source "$fasd_cache"
unset fasd_cache
eval "$(fasd --init auto)"
}
setup_direnv() {
eval "$(direnv hook zsh)"
}
setup_ssh_agent() {
if [[ ! -e ~/.ssh_agent ]]; then
if [[ -n ${SSH_AUTH_SOCK} ]]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh_agent
fi
fi
export SSH_AUTH_SOCK=~/.ssh_agent
}
setup_colors() {
local colorscheme
colorscheme="${HOME}/.config/colorschemes/scripts/base16-monokai.sh"
[[ -s "${colorscheme}" ]] && source "${colorscheme}"
}
setup_starship() {
ln -sf $HOME/dolfolife/dotfiles/starship.toml ~/.config/starship.toml
eval "$(starship init zsh)"
}
setup_nvm() {
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
}
setup_pyenv() {
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
}
local dependencies
dependencies=(
aliases
colors
direnv
environment
fasd
fzf
nvm
pyenv
ssh_agent
starship
)
for dependency in "${dependencies[@]}"; do
eval "setup_${dependency}"
unset -f "setup_${dependency}"
done
# Autocorrect typos in path names when using `cd`
setopt autocd;
}
mainpath="$0:A"
main
unset -f main
# FUNCTIONS
function reload() {
source "${HOME}/.zshrc"
}
pullify() {
git config --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
git fetch origin
}
default_hours() {
local current_hour=$(date +%H | sed 's/^0//')
local result=$((17 - current_hour))
if [[ ${result} -lt 1 ]]; then
result=1
fi
echo -n ${result}
}
function current_branch() { # Gets current branch
git rev-parse --abbrev-ref HEAD
}
function parse_branch() { # Gets current branch with parens around it for some legacy things
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
function gh_remote_path() { # Parses the 'remote path' of the repo: username/repo
REMOTE=${1:-origin}
GH_PATH=`git remote -v | tr ':' ' ' | tr '.' ' ' | grep $REMOTE | awk '/push/ {print $4}'`
echo ${GH_PATH#com/}
}
function gh() { # Opens current branch on Github, works for all repos
REMOTE=${1:-origin}
echo 'Opening branch on Github...'
open "https://github.com/$(gh_remote_path $REMOTE)/tree/$(current_branch)"
}
function newpr() { # Opens current branch on Github in the "Open a pull request" compare view
echo 'Opening compare on Github...'
open "https://github.com/$(gh_remote_path)/compare/$(current_branch)?expand=1"
}
function gpu() { # Push upstream
git push --set-upstream origin `current_branch`
}
function mkd() { # Create a new directory and enter it
mkdir -p "$@" && cd "$_";
}
function loop() { # Repeats a given command forever
local i=2 t=1 cond
[ -z ${1//[0-9]/} ] && i=$1 && shift
[ -z ${1//[0-9]/} ] && t=$1 && shift && cond=1
while [ $t -gt 0 ]; do
sleep $i
[ $cond ] && : $[--t]
$@
done
}
function nuke() { # Straight up murders all processes matching first arg
ps ax | grep $1 | awk '{print $1}' | xargs kill -9
}
function politely_nuke() { # As above but nicely
ps ax | grep $1 | awk '{print $1}' | xargs kill
}
function clear_port() { # Finds whatever is using a given port (except chrome) and kills it
lsof -t -i tcp:$1 | ag -v "$(ps aux|ag Chrome|tr -s ' '|cut -d ' ' -f 2|fmt -1024|tr ' ' '|')"| xargs kill -9
}
function v() { # Use fasd to open a file in vim from anywhere
nvim `f "$1" | awk "{print $2}"`
}
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
alias python=/usr/bin/python3
export PATH="$PATH:$HOME/.local/bin"