-
Notifications
You must be signed in to change notification settings - Fork 1
/
.functions.sh
144 lines (120 loc) · 3.55 KB
/
.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
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
awsp () {
if [ -z "$1" ]; then
echo $AWS_PROFILE
else
export AWS_PROFILE=${1}
fi
}
baseurl() { # Get base url from full url. scheme://domain
scheme=${1%%://*}
without_scheme=${1##"$scheme"://}
echo "$scheme://${without_scheme%%/*}"
}
colordump () { # Dump primary term colors.
for c in {0..15}; do
printf "\033[48;5;%sm%3d\033[0m " "$c" "$c"
if (( c == 15 )) || (( c > 15 )) && (( (c-15) % 6 == 0 )); then
printf "\n";
fi
done
}
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z e $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
gfixtags () {
for t in $(gvtags); do gtr $t ${t#v}; done
for t in $(gvtags); do git tag -d $t; done
}
gitp() { # Switch to git project directory from .projects. See alias repocache.
REPO="$(cat "$HOME"/.projects | sed s:"$HOME":~: | fzf --reverse)"
[ "$REPO" = "" ] || cd "${REPO/\~/$HOME}" || return
}
gtr () {
SOURCE_TAG=${1} NEW_TAG=${2}; deref() { git for-each-ref "refs/tags/$SOURCE_TAG" --format="%($1)" ; }; GIT_COMMITTER_NAME="$(deref taggername)" GIT_COMMITTER_EMAIL="$(deref taggeremail)" GIT_COMMITTER_DATE="$(deref taggerdate)" git tag "$NEW_TAG" "$(deref "*objectname")" -a -sm "$(deref contents:subject)"
# If any of the tags have bodies, this will add the contents.
# SOURCE_TAG=${1} NEW_TAG=${2}; deref() { git for-each-ref "refs/tags/$SOURCE_TAG" --format="%($1)" ; }; GIT_COMMITTER_NAME="$(deref taggername)" GIT_COMMITTER_EMAIL="$(deref taggeremail)" GIT_COMMITTER_DATE="$(deref taggerdate)" git tag "$NEW_TAG" "$(deref "*objectname")" -a -sm "$(deref contents:subject)\n\n$(deref contents:body)"
}
gvtags () {
for t in $(git tag); do
if [[ $t =~ ^v ]]; then
echo $t
fi;
done
}
jsonesc () {
python -c 'import json,sys; print(json.dumps('$1'))'
}
prettyjson () {
cat $1 | python -mjson.tool > $2
}
pwa () { # add password to keyring
security add-generic-password -s $1 -a $2 -w
}
pwdel () { # delete password in keyring
security delete-generic-password -s $1 -a $2
}
pwf () { # find password in keyring
security find-generic-password -w -s $1 -a $2
}
rgh () { # search history
history | rg $1
}
sc() {
if [ ! -n "$NEXUS_USER" ]; then
export NEXUS_USER="unset"
fi
if [ ! -n "$NEXUS_PWD" ]; then
export NEXUS_PWD="unset"
fi
cmd="sceptre ${@#config/}"
echo $cmd
eval $cmd
}
ssmp() { # get ssm parameter value
aws ssm get-parameter --name $1 | jq -r .Parameter.Value
}
ssmpd() { # get ssm parameter value with decryption
aws ssm get-parameter --with-decryption --name $1 | jq -r .Parameter.Value
}
t() { # tree with depth
eza -T -L $1
}
util-connect() {
aws ssm start-session --target $1
}
util-start() {
aws ec2 start-instances --instance-ids $1
}
util-stop() {
aws ec2 stop-instances --instance-ids $1
}
venv2 () {
virtualenv -p /usr/bin/python2 .venv
venvact .venv
pip install ipython
}
venv3 () {
python3 -m venv .venv
venvact .venv
pip install ipython
}
venvact () {
source .venv/bin/activate
}