-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_functions.sh
96 lines (82 loc) · 2.04 KB
/
dot_functions.sh
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
# .functions.sh
cheatsh() {
curl -s "cheat.sh/$1?style=rrt"
}
ipinfo() {
ip -4 -o a | awk 'BEGIN { OFS=":\t " } { print $2, $4 }'
}
mkdirf() {
mkdir -p "$1" && cd "$1"
}
# Create paste from stdin or file
pb() {
curl -sF "file=@${1:--}" 'https://0x0.st'
}
# Generate QR code from stdin or file
qrencode() {
curl -F "-=${1:-<-}" "https://qrenco.de"
}
wttr() {
curl -s "https://wttr.in/${1}?m"
}
gi() {
curl -sLw '\n' "https://www.toptal.com/developers/gitignore/api/$*"
}
b64() {
echo -n "$1" | base64
}
httping() {
while :; do
curl --write-out "%{url_effective} - %{response_code} - %{time_total} - $(date +%T)\n" --silent --output /dev/null -L "$1"
[[ -n $2 ]] && sleep "$2"
done
}
tls-pin-sha256() {
openssl s_client -connect "$1:443" </dev/null 2>/dev/null |
openssl x509 -noout -pubkey |
openssl pkey -pubin -outform der |
openssl dgst -sha256 -binary |
openssl enc -base64
}
awsudo() {
if [[ $1 == "unset" ]]; then
unset AWS_PROFILE
else
AWS_PROFILE=$(sed -n "s/\[profile \(.*\)\]/\1/gp" ~/.aws/config | fzf --query="$1")
export AWS_PROFILE
fi
}
ec2-id-from-name() {
aws ec2 describe-instances \
--filter "Name=tag:Name,Values=$1" \
--query "Reservations[].Instances[].InstanceId[]" \
--output text
# --query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" \
}
ssm-connect() {
if [[ $1 == i-* ]]; then
local -r id=$1
else
local -r id=$(ec2-id-from-name "$1")
fi
if [[ ${2:-false} == "ssh" ]]; then
echo "Connecting to instance $id via ssh"
ssh "$id"
else
echo "Connecting to instance $id"
aws ssm start-session --target "$id"
fi
}
ssm-port-forward() {
if [[ $1 == i-* ]]; then
local -r id=$1
else
local -r id=$(ec2-id-from-name "$1")
fi
local remote=$2
local local=${3:-$remote}
echo "Forwarding port $remote from instance $id to port $local"
aws ssm start-session --target "$id" \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["'"$remote"'"],"localPortNumber":["'"$local"'"]}'
}