/
.sh_functions
174 lines (150 loc) · 5.49 KB
/
.sh_functions
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
#!/usr/bin/env bash
mkcd() {
mkdir -pv $1 && cd $1
}
fdNvimRtp() {
local search_term="${1:-.}"
nvim -e -s -c "set runtimepath?" \
| sed s/runtimepath=// | tr "," $IFS | awk '{$1=$1};1' \
| xargs fd $search_term --max-depth=1 2>/dev/null
}
# TODO: rewrite in dash-compatible way
nvmuse() {
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
nvm use $@
SetWebCerts
}
SdkManInit() {
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"
}
RBInit() {
eval "$(rbenv init - zsh)"
}
SetWebCerts() {
export NODE_EXTRA_CA_CERTS="/tmp/mega.pem"
if [ ! -f $NODE_EXTRA_CA_CERTS ]; then
security find-certificate -a -p /Library/Keychains/System.keychain > $NODE_EXTRA_CA_CERTS
fi
}
#tea-magic() {
# [[ -d "$HOME/.tea" ]] && source <("$HOME/.tea/tea.xyz/v*/bin/tea" --magic)
#}
source ~/dotfiles/bin/clone
function is-walmart-mac() {
[[ -f "/Users/Shared/Start Here - Mac At Walmart.pdf" ]]
}
function vpn-up() {
# STEPS TO MAKE THIS WORK
# 1. Install [2fa](https://github.com/rsc/2fa)
# a. Make a [new TOTP](https://linotp.wal-mart.com/selfservice/login) token
# 2. Set up your VPN account in the Mac Keychain, inserting your user id and password
# a. `security add-generic-password -s 'wmt-sso' -a $USER -w`
# b. credit: @a0c01gr
# 3. run this function!
# 4. profit???
#local VPN_HOST=sslvpngwgec.wal-mart.com/Walmart_Associate_MAC_Yubi # blocks Spotify
#local VPN_HOST=http://sslvpngwwec.wal-mart.com/Walmart_Associate_Yubi # blocks Spotify
#local VPN_HOST=http://sslvpngw.wal-mart.com/Walmart_Associate_Yubi # seamlessly switches on Zoom calls; blocks Spotify; makes Slack go offline when switching
local VPN_HOST=sslvpngwwec.wal-mart.com/Walmart_Associate_Yubi # blocks Spotify, i like this one
if is-walmart-mac; then
local VPN_USER=$USER
else
local VPN_USER=${VPN_USER:-m0c0j7y}
fi
echo "Starting the vpn ..."
if [[ ! -x "$(command -v 2fa)" ]] ; then
printf "requires [2fa](https://github.com/rsc/2fa)\n"
return 1
fi
local mfa_code="$(2fa walmart)"
if [[ -x "$(command -v security)" ]]; then
local vpn_password=$(security find-generic-password -w -s 'wmt-sso' -a $VPN_USER || cat ~/.vpn_password)
else
local vpn_password=$(cat ~/.vpn_password)
fi
if [[ -f /opt/cisco/anyconnect/bin/vpn ]]; then
printf "\n${vpn_password}\n${mfa_code}\ny" | /opt/cisco/anyconnect/bin/vpn -s connect $VPN_HOST $@
else
# for some reason this is the only one I've found that works with openconnect
local VPN_HOST=sslvpngwgec.wal-mart.com/Walmart_Associate_MAC_Yubi
echo "${vpn_password}\n${mfa_code}\n" | sudo openconnect --passwd-on-stdin --background -u $VPN_USER $VPN_HOST $@
fi
}
function vpn-down() {
if [[ -f /opt/cisco/anyconnect/bin/vpn ]]; then
/opt/cisco/anyconnect/bin/vpn disconnect
else
sudo kill -2 `pgrep openconnect`
fi
}
function vpn-status() {
local vpn=/opt/cisco/anyconnect/bin/vpn
if [[ ! -x $vpn ]]; then
echo "N/A"
return 1
fi
/opt/cisco/anyconnect/bin/vpn state\
| sed -r 's/^.*state: (Connected|Disconnected)$/\1/g'\
| grep -E --color=never 'Connected|Disconnected'\
| head -n1
}
function wmt_sudome() {
set -x
sudo jamf policy -id 854
set +x
}
function wmt_fixmynetwork() {
set -x
# Fix My Network
sudo jamf policy -id 906
if [[ $1 == "eagle" ]]; then
# Fix My Eagle Configuration
sudo jamf policy -id 809
fi
set +x
}
function afk() {
echo "set i to 0
repeat while i < 20
tell application \"System Events\" to key code 80
set i to i + 1
delay 180
end repeat" | osascript
}
function vo() {
vim $(fd | fzf)
}
function keepkillwd() {
## Microsoft antivirus runs every time we write to the filesystem. This makes
# write-heavy processes a lot slower. This function keeps the antivirus
# software contained to speed up disk writes
#
# While running this function, I've measured `git switch` to be 2x faster and
# web production builds to be 20% faster
#
# Run this function in a separate terminal window like
# `sudo zsh -c "source $HOME/.sh_functions; keepkillwd"`
# to prevent being prompted when waking the machine from sleep
local nextSleep=1;
# use sudo here so that we're not prompted in the loop
sudo echo "started successfully"
while true; do
sudo killall -9 wdavdaemon wdavdaemon_unprivileged wdavdaemon_enterprise 2>/dev/null && nextSleep=1 || nextSleep=$(($nextSleep + 1))
sleep $nextSleep
done
}
kubeparallel() {
local clusters=(scus-prod-a29 eus2-prod-a18 uswest-prod-az-002)
local clusters_separated_by_newlines_extra_newline=$(printf "\n%s" "${clusters[@]}") # \nscus-prod-a29\neus2-prod-a18\nuswest-prod-az-002
local clusters_separated_by_newlines=${clusters_separated_by_newlines_extra_newline:1} # scus-prod-a29\neus2-prod-a18\nuswest-prod-az-002
printf "$clusters_separated_by_newlines" | parallel -j3 "printf '\e[34m\e[40m{}\e[0m\n'; kubectl $@ --context={} ; printf '\n'"
}
kubesequential() {
local clusters=("scus-prod-a29" "eus2-prod-a18" "uswest-prod-az-002")
local clusters_separated_by_newlines_extra_newline=$(printf "\n%s" "${clusters[@]}") # \nscus-prod-a29\neus2-prod-a18\nuswest-prod-az-002
local clusters_separated_by_newlines=${clusters_separated_by_newlines_extra_newline:1} # scus-prod-a29\neus2-prod-a18\nuswest-prod-az-002
printf "$clusters_separated_by_newlines" | xargs -r -I{} zsh -c "echo '\e[34m\e[40m{}\e[0m' ; kubectl $* --context={} ; printf '\n'"
}