-
Notifications
You must be signed in to change notification settings - Fork 0
/
.aliases
324 lines (265 loc) · 10.1 KB
/
.aliases
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
316
317
318
319
320
321
322
323
324
# Quickly change to dev directory
# alias dev="cd ~/Dropbox/dev"
DEV=$HOME/dev
# Stopwatch
alias timer='echo "Timer started. Stop with Ctrl-D." && date && time cat && date'
# Weather
alias weather='curl wttr.in'
# Get OS X Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
alias update='sudo softwareupdate -i -a; brew update; brew upgrade; brew cleanup; npm install npm -g; npm update -g; sudo gem update --system; sudo gem update'
# IP addresses
alias exip="curl myipv4.millnert.se"
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 }'"
# View HTTP traffic
alias sniff="sudo ngrep -d 'wlp4s0' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""
# Enable/Disable Spotlight
alias spotoff="sudo mdutil -a -i off"
alias spoton="sudo mdutil -a -i on"
# Lock the screen (when going AFK)
alias afk="gnome-screensaver-command -l"
# alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"
# Speed Test
alias speedtest='echo "scale=2; `curl --progress-bar -w "%{speed_download}" http://speedtest.wdc01.softlayer.com/downloads/test10.zip -o /dev/null` / 131072" | bc | xargs -I {} echo {} mbps'
alias pypiup='python setup.py sdist upload'
alias tmux='TERM=xterm-256color tmux'
workin () { cd "$DEV/$@"; }
compdef "_files -W $DEV" workin
workgo () { cd "$DEV/go/src/$@"; }
lsdev () { echo "$(ls $DEV)"; }
mkdev () { mkdir "$DEV/$@"; workdev "$@"; }
mkw () { mkdev $@; workdev $@ }
ndev () {
mkdev $@
git init $DEV/$@
workdev $@
}
gic () {
echo "Making dev directory: $2";
mkdev $2;
git init;
git remote add origin $1;
git fetch;
git checkout -t origin/master || git checkout -t origin/main
}
ssh-remote-add () { cat ~/.ssh/id_ed25519.pub | ssh "$@" 'cat > .tmp.pubkey; mkdir -p ~/.ssh; touch ~/.ssh/authorized_keys; cat .tmp.pubkey >> ~/.ssh/authorized_keys; rm .tmp.pubkey' }
alias catmd="pandoc -f markdown -t plain"
workdev () {
if [ -z "$@" ]; then
echo "Include a dev directory"
return
else
dir="$DEV/$1";
tmux new-session -d -s "$(echo $1 | rev | cut -d'/' -f 1 | rev | sed 's/\.//g')" -c "$dir"
fi
tmux rename-window "Dev"
tmux new-window -n "Test" -c "$dir"
tmux split-window -v -c "$dir"
tmux select-window -n
tmux -2 attach-session -d
}
obsi () {
workdev ~/Library/Mobile\ Documents/iCloud\~md\~obsidian/Documents/Main
}
compdef "_files -W $DEV" workdev
attachdev () {
dir="$(echo $1 | rev | cut -d'/' -f 1 | rev | sed 's/\.//g')";
tmux attach -t "$dir"
}
compdef "_files -W $DEV" attachdev
alias vi=nvim
venv () {
SDIR=`pwd`
while true; do
if [ -d venv ]; then
echo "Sourcing env from $PWD/.venv"
source "venv/bin/activate"
break
fi
if [ -d .venv ]; then
echo "Sourcing env from $PWD/.venv"
source ".venv/bin/activate"
break
fi
if [ -d virtualenv ]; then
echo "Sourcing env from $PWD/virtualenv"
source "virtualenv/bin/activate"
break
fi
cd ../
if [[ "$PWD" == "/" ]]; then
echo "No virtual environments found."
break
fi
done
cd $SDIR
unset SDIR
}
synk () {
# I built this and then found out about vagrant rsync. I leave it here so
# you can admire my understanding of regex and sed.
#
#
# VAGRANT_SSH_CONFIG=$(vagrant ssh-config)
# VAGRANT_IP=$(echo $VAGRANT_SSH_CONFIG | sed -rn 's/\s*HostName\s*([0-9.a-Z]+)/\1/p')
# VAGRANT_PORT=$(echo $VAGRANT_SSH_CONFIG | sed -rn 's/\s*Port\s*([0-9]+)/\1/p')
# FOLDERS=$(cat Vagrantfile | grep synced_folder | grep -v -e "#" | sed -r 's/\s*config.vm.synced_folder\s*"([~/a-Z0-9_-.]*)",\s*"([!/a-Z0-9_-.]*)".*/\1 \2/g')
# while read -A entry; do
# echo "rsync -rvh ${entry[1]} vagrant@$VAGRANT_IP:${entry[2]} --delete --links --port=$VAGRANT_PORT"
# rsync -rvh ${entry[1]} vagrant@$VAGRANT_IP:${entry[2]} --delete --links -e "ssh -p $VAGRANT_PORT"
# done <<< $FOLDERS
vagrant rsync
}
alias t='$DEV/todo.txt-cli/todo.sh'
genpw () {
if [ -z $1 ]; then
len=32;
else
len=$1
fi
date +%s | sha256sum | base64 | head -c $len; echo
}
today () {
echo "\
___________________________ _______ _______
\\__ __/\\__ __/\\__ __/( ___ )( ____ \\
) ( ) ( ) ( | ( ) || ( \\/
| | | | | | | | | || (__
| | | | | | | | | || __)
| | | | | | | | | || (
___) (___ | | ___) (___| (___) || )
\\_______/ )_( \\_______/(_______)|/
\
"
dig +short txt istheinternetonfire.com
echo ""
echo ""
echo ""
echo "\
_______ _______ _________ _______ _______
|\\ /|( ____ \\( ___ )\\__ __/|\\ /|( ____ \\( ____ )
| ) ( || ( \\/| ( ) | ) ( | ) ( || ( \\/| ( )|
| | _ | || (__ | (___) | | | | (___) || (__ | (____)|
| |( )| || __) | ___ | | | | ___ || __) | __)
| || || || ( | ( ) | | | | ( ) || ( | (\\ (
| () () || (____/\\| ) ( | | | | ) ( || (____/\\| ) \\ \\__
(_______)(_______/|/ \\| )_( |/ \\|(_______/|/ \\__/
\
"
weather
}
function ag {
echo "Tom was right. You were wrong. RG is faster. Better. In every way."
}
function opto_jpeg {
find ./src -regextype sed -regex ".*\.jpg" | xargs -I [] convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% [] []
}
function aws-rotate-key {
# Requires GAWK, aws-cli, RipGrep, and jq
USER_NAME=${1:-matthew_stone}
PROFILE=${2:-default}
CURRENT_KEY=`cat ~/.aws/credentials | rg "\[$PROFILE\]" -A 2 | rg "aws_access_key_id\s+=\s+(.*)" -r '$1'`
echo "Rotating from key $CURRENT_KEY. Press any key to continue..."; read -k1 -s
NEW_KEY=`aws --profile $PROFILE iam create-access-key --user-name $USER_NAME`
NEW_ACCESS_KEY_ID=`echo "$NEW_KEY" | jq '.AccessKey.AccessKeyId'| sed 's/\"//g'`
NEW_SECRET_ACCESS_KEY=`echo "$NEW_KEY" | jq '.AccessKey.SecretAccessKey' | sed 's/\"//g'`
AWK=`cat << EOF
BEGIN {s="no"; f="no"}
(s=="yes" && /^\[/) {f="yes"}
/^\[$PROFILE\]/ {s="yes"}
(s=="yes" && f=="no") {
if (\\$0 ~ /aws_access_key_id*/) {
print "aws_access_key_id = $NEW_ACCESS_KEY_ID"
} else if (\\$0 ~ /aws_secret_access_key*/) {
print "aws_secret_access_key = $NEW_SECRET_ACCESS_KEY"
} else {
print \\$0
}
}
((s=="no" && f=="no") || (s=="yes" && f=="yes")){
print \\$0
}
EOF`
gawk -i inplace "$AWK" ~/.aws/credentials
echo "Acquired new key and written to credentials file. Ready to deactivate old key? Press any key to continue..."; read -k1 -s
aws --profile $PROFILE sts get-session-token
echo "aws --profile $PROFILE iam update-access-key --access-key-id $CURRENT_KEY --status Inactive --user-name $USER_NAME"
aws --profile $PROFILE iam update-access-key --access-key-id $CURRENT_KEY --status Inactive --user-name $USER_NAME
echo "Done..."
}
function aws-delete-inactive {
USER_NAME=${1:-matthew_stone}
PROFILE=${2:-default}
KEYS=`aws --profile $PROFILE iam list-access-keys --user-name $USER_NAME | jq -rc '.AccessKeyMetadata | .[] | select(.Status=="Inactive") | .AccessKeyId'`
for KEY in $KEYS
do
echo "Really delete $KEY?"; read -k1 -s
aws --profile $PROFILE iam delete-access-key --user-name $USER_NAME --access-key-id $KEY
done
}
function aws-rotate-all-keys {
aws-delete-inactive red5 personal
aws-rotate-key red5 personal
aws-delete-inactive mstone bigstripe
aws-rotate-key mstone bigstripe
}
function git_report {
# Usage: git_report 2023-01-01 2023-12-31
echo "Date,User,Commits,Lines of Code"
git log --pretty="%an|%ad" --shortstat --date=short --since="$1" --until="$2" | \
awk '
/^ / {
added+=$4;
deleted+=$6;
loc=added+deleted
}
!/^ / && NF == 2 {
if (user && date) print date "," user "," commits "," loc;
split($0, parts, "|")
user=parts[1];
date=parts[2];
commits=0;
loc=0;
added=0;
deleted=0;
}
/^ / { commits++ }
END { if (user && date) print date "," user "," commits "," loc }
'
}
function append-creation-date {
local force=0
# Check if the '-f' option is provided
if [[ "$1" == "-f" ]]; then
force=1
shift # Remove the first argument, processing the rest as filenames
fi
local dir="$1" # The directory to process files in
# Navigate to the directory
cd "$dir" || return
# Iterate over each file in the directory
for file in *; do
# Check if the file is a regular file
if [ -f "$file" ]; then
# Get the file's creation date on macOS, adjust for Linux if necessary
local creationDate=$(stat -f "%SB" -t "%y-%m-%d" "$file")
# Check if the filename already starts with a date in the format YY-MM-DD
if ! [[ $file =~ ^[0-9]{2}-[0-9]{2}-[0-9]{2} ]]; then
local newFileName="${creationDate} $file"
if [ $force -eq 0 ]; then
# Prompt the user for confirmation if not in force mode
echo "Renaming $file to $newFileName, proceed? y/N"
read response
if [[ $response =~ ^[Yy]$ ]]; then
mv "$file" "$newFileName"
fi
else
# Rename the file without prompting
mv "$file" "$newFileName"
fi
fi
fi
done
}
alias docker="lima nerdctl"