-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc
315 lines (251 loc) · 11.4 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#! /bin/zsh
#
# Uncomment line below to enable profiling of load times
# zmodload zsh/zprof
#
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
source /opt/homebrew/Cellar/antidote/1.9.6/share/antidote/antidote.zsh
export HOMEBREW_NO_AUTO_UPDATE=1 # Don't auto update everything with brew... let me decide.
export NVM_DIR="$HOME/.nvm"
#[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
zstyle ':omz:plugins:nvm' lazy yes
bindkey '^R' history-incremental-search-backward
eval $(gdircolors ~/.dircolors)
eval "$(starship init zsh)"
export VIRTUAL_ENV_DISABLE_PROMPT=1 # <--- Don't have venv modify the prompt when active, starship includes it
# Alias to interact with bare git repository for configuration.
# Used to add, update, delete, or otherwise manager configurations.
# Example: git checkout <branch> to get a configuration represented
# by a specific branch.
alias config='/usr/bin/git --git-dir=$HOME/.configurations/ --work-tree=$HOME'
eval "$(direnv hook zsh)" # <--- Enable direnv (auto load/unload .envrc files after approval)
# Better ls alias for Mac
alias ls='gls --color'
setopt COMPLETE_IN_WORD
# Enable save history of 1000 cmds, write to a certain file
HISTFILE=~/.histfile
HISTSIZE=5000
SAVEHIST=10000
setopt appendhistory # Append history to the history file (no overwriting)
setopt sharehistory # Share history across terminals
setopt incappendhistory # Immediately append to the history file, not just when a term is killed
# Export some global settings
export EDITOR="nvim"
export LESS="-R"
autoload -Uz compinit
typeset -i updated_at=$(date +'%j' -r ~/.zcompdump 2>/dev/null || stat -f '%Sm' -t '%j' ~/.zcompdump 2>/dev/null)
if [ $(date +'%j') != $updated_at ]; then
compinit -i
else
compinit -C -i
fi
autoload bashcompinit
bashcompinit
complete -C '/opt/homebrew/bin/aws_completer' aws
# To update, run: antidote bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.sh
source ~/.zsh_plugins.sh
# ---- Completion ----
# Force rehash when command not found
_force_rehash() {
(( CURRENT == 1 )) && rehash
return 1
}
zstyle ':completion:*:*:docker:*' option-stacking yes
zstyle ':completion:*:*:docker-*:*' option-stacking yes
# forces zsh to realize new commands
zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _match _ignored _approximate
# matches case insensitive for lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# pasting with tabs doesn't perform completion
zstyle ':completion:*' insert-tab pending
# menu if nb items > 2
zstyle ':completion:*' menu select=2
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
function awsclearshell {
echo unset AWS_SESSION_TOKEN
echo unset AWS_ACCESS_KEY_ID
echo unset AWS_SECRET_ACCCESS_KEY
}
function awsclear {
eval $(awsclearshell)
}
function awsrole {
aws sts get-caller-identity --duration-in-seconds 900 --profile $1 > /dev/null
eval $(jq -r '.Credentials | "export AWS_ACCESS_KEY_ID="+.AccessKeyId, "export AWS_SECRET_ACCESS_KEY="+.SecretAccessKey, "export AWS_SESSION_TOKEN="+.SessionToken' < ~/.aws/cli/cache/$1--*.json)
}
secret () {
output=~/"${1}".$(date +%s).enc
gpg --encrypt --armor --output ${output} "${1}" && echo "${1} -> ${output}"
}
reveal () {
output=$(echo "${1}" | rev | cut -c16- | rev)
gpg --decrypt --output ${output} "${1}" && echo "${1} -> ${output}"
}
export GPG_TTY="$(tty)"
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent
gpg-connect-agent updatestartuptty /bye > /dev/null
function get_failed_report_factory_executions() {
STATE_MACHINE_ARN=arn:aws:states:us-east-1:313750358190:stateMachine:ReportFactoryReportProcessStateMachine-prd
aws --profile ${AWS_PROFILE:?Run this comamnd with AWS_PROFILE set to a non-empty value} stepfunctions list-executions --state-machine-arn $STATE_MACHINE_ARN | jq --raw-output '.executions[] | select(.status == "FAILED") | {arn: .executionArn, startTime: .startDate | todate}'
}
function get_report_factory_executions_as_csv() {
STATE_MACHINE_ARN=arn:aws:states:us-east-1:313750358190:stateMachine:ReportFactoryReportProcessStateMachine-prd
aws --profile ${AWS_PROFILE:?Run this comamnd with AWS_PROFILE set to a non-empty value} stepfunctions list-executions --state-machine-arn $STATE_MACHINE_ARN | \
jq -r '.executions | map({startDate: .startDate | todate, stopDate: (try (.stopDate | todate) catch "STILL RUNNING"), name: .name, status: .status, executionArn: .executionArn})
| (map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv'
}
function get_report_factory_executions_raw() {
STATE_MACHINE_ARN=arn:aws:states:us-east-1:313750358190:stateMachine:ReportFactoryReportProcessStateMachine-prd
aws --profile ${AWS_PROFILE:?Run this comamnd with AWS_PROFILE set to a non-empty value} stepfunctions list-executions --state-machine-arn $STATE_MACHINE_ARN
}
function get_logs_for_machine_execution() {
EXECUTION_ARN=${1:?An execution ARN must be provided as the first argument}
AWS_PROFILE=${AWS_PROFILE:?Run this command with AWS_PROFILE set to a non-empty value}
EXECUTION_LOGSTREAM=$(aws --profile $AWS_PROFILE stepfunctions get-execution-history --execution-arn $EXECUTION_ARN \
| jq --raw-output '.events[-2].stateEnteredEventDetails.input | fromjson | .error.Cause | fromjson | .Attempts[0].Container.LogStreamName')
aws --profile $AWS_PROFILE logs get-log-events --log-group-name /aws/batch/job --log-stream-name $EXECUTION_LOGSTREAM | jq --raw-output '.events[].message'
}
#########################################################################
# From: https://gist.github.com/benkehoe/0d2985e56059437e489314d021be3fbe
# MIT No Attribution
#
# Copyright 2022 Ben Kehoe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# There are lots of well-built tools that completely manage your
# AWS profiles and login and credentials, like aws-vault and AWSume.
# This isn't that.
# I tend to prefer to go as lightweight as possible around AWS-produced tools.
# So all this does is set and unset your AWS_PROFILE environment variable.
# This code requires the AWS CLI v2 to function correctly, because it uses the
# aws configure list-profiles command for validation and auto-completion,
# and this command does not exist in the AWS CLI v1.
# AWS CLI v2 install instructions:
# https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
# You might also be interested in aws-whoami
# which improves upon `aws sts get-caller-identity`
# https://github.com/benkehoe/aws-whoami
#########################################################################
aws-profile () {
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "USAGE:"
echo "aws-profile <- print out current value"
echo "aws-profile PROFILE_NAME <- set PROFILE_NAME active"
echo "aws-profile --unset <- unset the env vars"
elif [ -z "$1" ]; then
if [ -z "$AWS_PROFILE$AWS_DEFAULT_PROFILE" ]; then
echo "No profile is set"
return 1
else
echo "$AWS_PROFILE$AWS_DEFAULT_PROFILE"
fi
elif [ "$1" = "--unset" ]; then
AWS_PROFILE=
AWS_DEFAULT_PROFILE=
# removing the vars is needed because of https://github.com/aws/aws-cli/issues/5016
export -n AWS_PROFILE AWS_DEFAULT_PROFILE
else
# this check needed because of https://github.com/aws/aws-cli/issues/5546
# requires AWS CLI v2
if ! aws configure list-profiles | grep --color=never -Fxq -- "$1"; then
echo "$1 is not a valid profile"
return 2
else
AWS_DEFAULT_PROFILE=
export AWS_PROFILE=$1
export -n AWS_DEFAULT_PROFILE
fi;
fi;
}
# completion is kinda slow, operating on the files directly would be faster but more work
# aws configure list-profiles is only available with the AWS CLI v2.
_aws-profile-completer () {
COMPREPLY=(`aws configure list-profiles | grep --color=never ^${COMP_WORDS[COMP_CWORD]}`)
}
complete -F _aws-profile-completer aws-profile
### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
export PATH="/Users/mylesloffler/.rd/bin:$PATH"
### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)
# Created by `pipx` on 2022-09-14 14:52:06
export PATH="$PATH:/Users/mylesloffler/.local/bin"
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/mylesloffler/tools/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/mylesloffler/tools/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/mylesloffler/tools/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/mylesloffler/tools/google-cloud-sdk/completion.zsh.inc'; fi
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# Output of: eval "$(github-copilot-cli alias -- "$0")"
copilot_what-the-shell () {
TMPFILE=$(mktemp);
trap 'rm -f $TMPFILE' EXIT;
if /Users/mylesloffler/.nvm/versions/node/v18.16.0/bin/github-copilot-cli what-the-shell "$@" --shellout $TMPFILE; then
if [ -e "$TMPFILE" ]; then
FIXED_CMD=$(cat $TMPFILE);
print -s "$FIXED_CMD";
eval "$FIXED_CMD"
else
echo "Apologies! Extracting command failed"
fi
else
return 1
fi
};
alias '??'='copilot_what-the-shell';
copilot_git-assist () {
TMPFILE=$(mktemp);
trap 'rm -f $TMPFILE' EXIT;
if /Users/mylesloffler/.nvm/versions/node/v18.16.0/bin/github-copilot-cli git-assist "$@" --shellout $TMPFILE; then
if [ -e "$TMPFILE" ]; then
FIXED_CMD=$(cat $TMPFILE);
print -s "$FIXED_CMD";
eval "$FIXED_CMD"
else
echo "Apologies! Extracting command failed"
fi
else
return 1
fi
};
alias 'git?'='copilot_git-assist';
copilot_gh-assist () {
TMPFILE=$(mktemp);
trap 'rm -f $TMPFILE' EXIT;
if /Users/mylesloffler/.nvm/versions/node/v18.16.0/bin/github-copilot-cli gh-assist "$@" --shellout $TMPFILE; then
if [ -e "$TMPFILE" ]; then
FIXED_CMD=$(cat $TMPFILE);
print -s "$FIXED_CMD";
eval "$FIXED_CMD"
else
echo "Apologies! Extracting command failed"
fi
else
return 1
fi
};
alias 'gh?'='copilot_gh-assist';
alias 'wts'='copilot_what-the-shell';
#zprof
# Add libpq (without PSQL Server) installed via Brew
export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
# Set up fzf key bindings and fuzzy completion
eval "$(fzf --zsh)"
source ~/git/fzf-git.sh/fzf-git.sh
export BAT_THEME=Dracula
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/sbin:$PATH"
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"