-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
executable file
·85 lines (74 loc) · 2.55 KB
/
.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
#!/usr/bin/env bash
# print all the 256 colors supported by terminal
allthecolors() {
x=$(tput op) y=$(printf %$((${COLUMNS}-6))s);for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} $(tput setaf $i;tput setab $i)${y// /=}$x;done;
}
# Decode \x{ABCD}-style Unicode escape sequences
unidecode() {
perl -e "binmode(STDOUT, ':utf8'); print \"$@\""
# print a newline unless we’re piping the output to another program
if [ -t 1 ]; then
echo # newline
fi
}
retry() {
let backoff=5
false
while [[ $? -ne 0 && $? -ne 130 ]]; do
"$@" || (sleep $((backoff*=2));false)
done
}
# privnote cli
privnote() {
echo "input semi secret"
read -r input
local message="$input"
# a password is required, so randomly generate one in a format privote accepts
local password="$(perl -pe 'binmode(STDIN, ":bytes"); tr/A-Za-z0-9//dc;' < /dev/urandom | head -c 9; echo)"
local data=$(echo "$message" | openssl enc -e -aes-256-cbc -k "$password" -a -md md5)s
local note_link=$(curl -s 'https://privnote.com/' \
-H 'X-Requested-With: XMLHttpRequest' \
--data-urlencode "data=$data" \
--data "has_manual_pass=false&duration_hours=0&dont_ask=false&data_type=T¬ify_email=¬ify_ref=" \
| jq -r --arg arg "$password" '.note_link + "#" + $arg')
echo "$note_link" | pbcopy
echo "note URL is $note_link"
}
dot-edit () {
pushd "$HOME" > /dev/null
if [ -e ".gitignore" ]; then
cat .gitignore | grep -F . | tr -d ! | xargs -I {} subl {}
else
echo "dotfile .gitignore not found"
fi
if [ -e ".bashrc.local" ]; then
subl .bashrc.local
else
echo "local .bashrc not found"
fi
popd > /dev/null
}
# kubectlgetall -n stage -l app=gifs
kubectlgetall() {
for i in $(kubectl api-resources --verbs=list --namespaced -o name | grep -v "events.events.k8s.io" | grep -v "events" | sort | uniq); do
printf "\n Resource:" $i
kubectl "${@}" get --ignore-not-found ${i}
done
}
# tail -f console.log | highlight ERROR
highlight () {
perl -pe "s/$1/\e[1;31;43m$&\e[0m/g"
}
# hammer an endpoint from within the cluster
# namespace, sleep interval, endpoint
kubepodstress() {
kubectl -n $1 run -i --tty load-generator-$RANDOM --rm --image=busybox --restart=Never -n $1 -- /bin/sh -c "while sleep $2; do wget -q -O- $3; done"
}
multikill () {
ps -ef | grep -m 1 "$1" | awk '{ print $2 }' | xargs kill -9
}
aws-shell () {
saml2aws login -a "$1"
# subscript required to isolate env var and silence declarations
saml2aws exec -a "$1" -- bash "${HOME}/.aws_shell.sh" "$1"
}