-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzshrc.symlink
206 lines (170 loc) · 4.72 KB
/
zshrc.symlink
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
setopt prompt_subst
# https://arjanvandergaag.nl/blog/customize-zsh-prompt-with-vcs-info.html
# https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#Version-Control-Information
autoload -Uz vcs_info
precmd() { vcs_info }
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr '!'
zstyle ':vcs_info:*' stagedstr '+'
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
+vi-git-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
git status --porcelain | grep -m 1 -e '^??' -e '^[MTADRCU]' -e '^ [MTADRCU]' &>/dev/null
then
hook_com[misc]=' '
if git status --porcelain | grep -m 1 '^??' &>/dev/null
then
hook_com[misc]+='?'
fi
fi
}
zstyle ':vcs_info:*' formats ' (%b%F{yellow}%m%f%F{red}%u%f%F{green}%c%f)'
zstyle ':vcs_info:*' actionformats ' (%b|%a %F{yellow}%m%f%F{red}%u%f%F{green}%c%f)'
PS1='%F{green}%n%f:%F{cyan}%~%f${vcs_info_msg_0_}%F{red} ✪%f '
# https://zsh.sourceforge.io/Doc/Release/Options.html
# Tune history tracking
HISTSIZE=100000
SAVEHIST=50000
HISTFILE=~/.zsh_history
# todo: erase duplicates
# Map Home/End keys on Mac
bindkey "\e[F" end-of-line
bindkey "\e[H" beginning-of-line
###################
# Shell Completes #
###################
# Homebrew
if [ -f /opt/homebrew/bin/brew ]
then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
fi
autoload -Uz compinit && compinit
# AWS
if type aws_completer &>/dev/null
then
autoload bashcompinit && bashcompinit
complete -C '/usr/local/bin/aws_completer' aws
fi
#######
# fzf #
#######
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
########
# ASDF #
########
type brew &>/dev/null && [ -f $(brew --prefix asdf)/libexec/asdf.sh ] && source $(brew --prefix asdf)/libexec/asdf.sh
##########
# Neovim #
##########
if type nvim > /dev/null 2>&1; then
export EDITOR="nvim"
export VISUAL="nvim"
alias vim="nvim"
fi
##########
# direnv #
##########
if type direnv > /dev/null 2>&1; then
eval "$(direnv hook zsh)"
fi
# gpg-agent for SSH
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
if ! ps aux | grep gpg-agent | grep -v grep > /dev/null; then
gpgconf --launch gpg-agent &|
fi
# Android SDK (macOS)
if [ -d $HOME/Library/Android/sdk ]; then
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
fi
if [ -d $HOME/.asdf/installs/rust/stable/bin ]; then
export PATH=$PATH:$HOME/.asdf/installs/rust/stable/bin
fi
#######################
# Helpers and Aliases #
#######################
# figure out what is listening on a port
function onport {
PID="$(lsof -i ":$1" | grep -v COMMAND | awk '{print $2}')"
if [[ "$PID" == "" ]]; then
echo "error: no listener on $1" > /dev/stderr
else
ps aux $PID
fi
}
# create a diff comparison of two images
function imgdiff () {
convert '(' "$1" -flatten -grayscale Rec709Luminance ')' \
'(' "$2" -flatten -grayscale Rec709Luminance ')' \
'(' -clone 0-1 -compose darken -composite ')' \
-channel RGB -combine /tmp/imgdiff.png \
&& open /tmp/imgdiff.png
}
# cd, but relative to closest .git root
function gcd {
GIT_ROOT="$(git root)"
if [ "0" != "$?" ]; then
echo "Not in a git repo!"
else
cd "$GIT_ROOT/$1"
fi
}
# gzcat isn't everywhere, but is great
if ! type gzcat > /dev/null 2>&1
then
alias gzcat='gunzip -c'
fi
# Better man pages
if type most > /dev/null 2>&1
then
export MANPAGER="most"
else
man() {
env \
LESS_TERMCAP_mb=$'\e[1;31m' \
LESS_TERMCAP_md=$'\e[1;31m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[1;44;33m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[1;32m' \
man "$@"
}
fi
# Open vimr in a new window, not a tab
if type vimr > /dev/null 2>&1
then
alias vimr="vimr -s"
fi
# Look, Buildkit, you're great, but I want to see my output
export BUILDKIT_PROGRESS=plain
# Default colors on for ls in BSD/MacOS
export CLICOLOR=1
# Import LS_COLORS from trapd00r/LS_COLORS
if [ -f "$HOME/.lscolors.sh" ]; then
source "$HOME/.lscolors.sh"
fi
# Curl, but with timings
alias curltime='curl -L -w "
== TIME ==
namelookup: %{time_namelookup}
connect: %{time_connect}
appconnect: %{time_appconnect}
pretransfer: %{time_pretransfer}
redirect: %{time_redirect}
starttransfer: %{time_starttransfer}
total: %{time_total}
"'
# Terraform is a long command
alias tf="terraform"
# The way I currently use overmind I usually don't want port allocation
alias om="overmind s -N"
# libpq without postresql installed
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
# Don't auto download/switch Go versions (manage with asdf)
export GOTOOLCHAIN=local