-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzshrc
195 lines (168 loc) · 5.85 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
umask 022
bindkey -v
# https://unix.stackexchange.com/questions/608842/zshrc-export-gpg-tty-tty-says-not-a-tty
export GPG_TTY=$(tty)
alias vi="nvim"
alias vim="nvim"
alias realpath="readlink"
alias bt="bluetoothctl"
alias cal="ncal -C"
alias help="run-help"
case "$(uname -s)" in
"Darwin")
if [ -f "$(which gls)" ]; then
alias ls="gls --color";
else
alias ls="ls -G";
fi
alias zcat="gunzip -c"
;;
"Linux")
alias ls="ls --color"
alias diff="diff --color"
;;
esac
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^P" history-beginning-search-backward-end
bindkey "^N" history-beginning-search-forward-end
HISTFILE=~/.zsh_histfile
HISTSIZE=1000000
SAVEHIST=1000000
setopt hist_ignore_dups
setopt share_history
setopt magic_equal_subst
export EDITOR=nvim
export VISUAL=nvim
export PAGER=less
export LC_ALL=en_US.UTF-8
export LANG="en_US.UTF-8"
export PATH=$HOME/.cargo/bin:$HOME/.local/google-cloud-sdk/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:$PATH
export RIPGREP_CONFIG_PATH=$HOME/.ripgreprc
# .ssh/config to have `HashKnownHosts no` will help
_cache_hosts=($([ -f ~/.ssh/known_hosts ] && cat ~/.ssh/known_hosts | cut -d',' -f1))
# FZF specifically look for this line, so leaving it as it is
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export CARGO_NET_GIT_FETCH_WITH_CLI=true
for src in .cargo/env .rye/env .goenv.zsh .luarocks.zsh .nvm.zsh .plenv.zsh .pyenv.zsh .travis.zsh .local.zsh; do
[ -f $HOME/$src ] && source $HOME/$src;
done
# brew install coreutils
GNUBIN=/opt/homebrew/opt/coreutils/libexec/gnubin
if [ -d $GNUBIN ]; then
PATH=$GNUBIN:$PATH;
fi
autoload -Uz compinit && compinit
autoload -U +X bashcompinit && bashcompinit
[ -f /usr/bin/terraform ] && complete -o nospace -C /usr/bin/terraform terraform
# start starship if available
which starship 1>/dev/null && eval "$(starship init zsh)"
export AWS_REGION=ap-northeast-1
export AWS_VAULT_BACKEND=pass
export AWS_VAULT_PASS_PREFIX=aws-vault
export AWS_SESSION_TOKEN_TTL=6h
export AWS_ASSUME_ROLE_TTL=6h
export AWS_FEDERATION_TOKEN_TTL=6h
# The next line updates PATH for the Google Cloud SDK.
if [ -f "$HOME/.local/google-cloud-sdk/path.zsh.inc" ]; then . "$HOME/.local/google-cloud-sdk/path.zsh.inc"; fi
# The next line enables shell command completion for gcloud.
if [ -f "$HOME/.local/google-cloud-sdk/completion.zsh.inc" ]; then . "$HOME/.local/google-cloud-sdk/completion.zsh.inc"; fi
function colorlist() {
for color in {000..015}; do
print -nP "%F{$color}$color %f"
done
printf "\n"
for color in {016..255}; do
print -nP "%F{$color}$color %f"
if [ $(($((color-16))%6)) -eq 5 ]; then
printf "\n"
fi
done
}
function aws-ec2() {
if [ "$AWS_PROFILE" = "" ]; then
echo '$AWS_PROFILE is required';
return;
fi
aws-vault exec $AWS_PROFILE -- \
aws ec2 describe-instances \
--output=json \
--filters "Name=tag:Name,Values=$1" "Name=instance-state-name,Values=running" \
--query "Reservations[].Instances[] | sort_by(@, &LaunchTime)" \
| jq '.[] | [
.InstanceId,
.PrivateIpAddress,
.PublicIpAddress,
.LaunchTime,
.State.Name,
(.Tags | map(select(.Key | test("^[A-Z]")) | [.Key, .Value] | join(":")) | join(","))
] | @tsv' -r
}
function aws-session() {
aws-vault exec $AWS_PROFILE -- \
aws ssm start-session --target $1
}
function ssh-proxy() {
if [ "$SSH_PROXY_HOST" = "" ]; then
echo '$SSH_PROXY_HOST is required';
return;
fi
if [ "$SSH_REMOTE_USER" = "" ]; then
echo '$SSH_REMOTE_USER is required';
return;
fi
SSH_PROXY_OPTIONS=(
-o ProxyCommand="ssh -W %h:%p $SSH_PROXY_HOST"
-o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null
-o TCPKeepAlive=yes
);
ssh-copy-id "${SSH_PROXY_OPTIONS[@]}" $SSH_REMOTE_USER@$1 2>/dev/null;
ssh "${SSH_PROXY_OPTIONS[@]}" -t -t $SSH_REMOTE_USER@$1;
}
function cert-check() {
echo \
| openssl s_client -showcerts -servername $1 -connect $1:${2:-443} 2>/dev/null \
| openssl x509 -inform pem -noout -text
}
function git-url() {
git remote get-url $1 \
| sed 's/^.*@//; s/:/\//; s/\.git$//' \
| while read -r url; do echo "https://${url}/commit/${2}"; done
}
function pin() {
for pin in $(shuf --random-source=/dev/urandom -i0-9999 -n5); do printf '%04d\n' $pin; done
}
function ssh-agent-start() {
if [ ! -z "$(which ssh-agent)" ]; then
if [ -z "$(pgrep -U $(whoami) ssh-agent)" ]; then
# update/create symlink so that I can find the path easily later on
eval $(ssh-agent) && \
ln -nsf $SSH_AUTH_SOCK /tmp/ssh-auth.sock
else
# some environment ssh-agent starts automatically
[ -z $SSH_AGENT_PID ] && \
export SSH_AGENT_PID=$(pgrep ssh-agent | head -n1);
# find the path to sock and and restore the env
[ -L /tmp/ssh-auth.sock ] && \
export SSH_AUTH_SOCK=$(realpath /tmp/ssh-auth.sock);
fi
for key in $HOME/.ssh/id_rsa $HOME/.ssh/id_ed25519; do \
# add a key if its fingerprint is not in the agent
[ -f $key ] \
&& [ -z "$(ssh-add -l | grep $(ssh-keygen -lf $key | cut -d' ' -f2))" ] \
&& ssh-add $key; \
done;
fi
}
function ssh-agent-stop() {
if [ ! -z "$(which ssh-agent)" ]; then
if [ ! -z "$(pgrep -U $(whoami) ssh-agent)" ]; then
pgrep -U $(whoami) ssh-agent | xargs kill -HUP;
unset SSH_AGENT_PID;
unset SSH_AUTH_SOCK;
fi
fi
}
ssh-agent-start