-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.zsh.inc
190 lines (145 loc) · 4.98 KB
/
helpers.zsh.inc
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
# -*- shell-script -*-
################################################################################
# Hooks
function local_zsh() {
if [ -r $OLDPWD/.zsh_config ]; then
source $OLDPWD/.zsh_config
on_exit
fi
if [ -r $PWD/.zsh_config ]; then
source $PWD/.zsh_config
on_entry
fi
}
chpwd_functions+=local_zsh
################################################################################
# gpg
function sign-and-send {
gpg --sign-key "${1}" && gpg --send-keys "${1}"
}
################################################################################
# git
function git-task-types {
echo "fix - bug patching"
echo "feat - introducing a new feature"
echo "test - adding tests"
echo "perf - improving performance"
echo "wip - placeholder tag signifying ongoing work"
echo "deps - updating related to project dependencies"
echo "docs - updating related to project documentation"
echo "refactor - changing structure; functionality remains unchanged"
echo "build - updating anything related to building and deploying"
}
function git-files() {
commit="${1:-HEAD}"
git show --pretty="" --name-only "${commit}" | cat
}
function cd-git-head() {
cd "$(git rev-parse --show-toplevel)"
}
function git-branch-delete-pattern() {
git branch -D `git branch | grep -E ${1}`
}
function git-branch-checkout-pattern() {
git checkout `git branch | grep -E ${1} | sed -n 1p`
}
function git-force-pull() {
commit="${1:-$(git symbolic-ref --short HEAD)}"
git fetch && git reset --hard origin/"${commit}"
}
################################################################################
# Python aliases
function grid-create-revision() {
nix-shell --run "alembic revision -m '${1}'"
}
################################################################################
# nix
function nix-store-references() {
nix-store -q --references `which "${1}"`
}
function nix-store-referrers() {
nix-store -q --referrers `which "${1}"`
}
function nix-store-deps() {
nix-store -qR `which "${1}"`
}
function nix-store-deps-tree() {
nix-store -q --tree `which "${1}"`
}
function nix-store-path() {
readlink -f `which "${1}"`
}
function nix-query () {
local CACHE="$HOME/.cache/nq-cache"
if ! ( [ -e $CACHE ] && [ $(stat -c %Y $CACHE) -gt $(( $(date +%s) - 3600 )) ] ); then
echo "update cache" && NIXPKGS_ALLOW_UNFREE=1 nix-env -qa --json > "$CACHE"
fi
jq -r 'to_entries | .[] | .key + "|" + .value.meta.description' < "$CACHE" |
{
if [ $# -gt 0 ]; then
# double grep because coloring breaks column's char count
# $* so that we include spaces (could do .* instead?)
grep -i "$*" | column -t -s "|" | grep --color=always -i "$*"
else
column -t -s "|"
fi
}
}
# shells
function uuid-gen-n() {
nix-shell --argstr "$1" ~/.shells/uuid.nix --run "echo \"$UUID_GEN_N\""
}
################################################################################
# docker
function docker-compose-restart-and-log() {
docker-compose restart "$1" && docker-compose logs -f "$1"
}
function docker-compose-hard-restart() {
docker-compose stop "$1" && yes | docker-compose rm "$1" && docker-compose up -d "$1"
}
function docker-compose-hard-restart-and-log() {
docker-compose stop "$1" && yes | docker-compose rm "$1" && docker-compose up -d "$1" && docker-compose logs -f "$1"
}
################################################################################
# kubernetes
function kpods-by-app() {
kubectl get pods --selector="app=${1}"
}
function kube-get-secret() {
kubectl get secret "$1" -o json | jq -r "$2" | base64 -D | cat
}
################################################################################
# Stackdriver
function google-logs() {
gcloud logging read "labels.\"compute.googleapis.com/resource_name\"=$1 $2" --limit 10 --format json
}
################################################################################
# dev servers
alias sshml="ssh cameron@${ML_1_IP_ADDR}"
alias sshmll="ssh cameron@${ML_2_IP_ADDR}"
alias sshvpn="ssh cameron@${VPN_IP_ADDR}"
alias sshadmin="ssh cameron@${ADMIN_IP_ADDR}"
################################################################################
# shell
function take-dir() {
mkdir -p "$1" && cd "$1"
}
################################################################################
# 1Pass retrieval
function op-retrieve() {
op get item "${1}" | jq '.details.password' | tr -d \" | tr -d '\n' | xclip -selection clipboard
}
function op-retrieve-vpn() {
op get item VPN | jq '.details.fields[0].value' | tr -d \" | tr -d '\n' | xclip -selection clipboard
}
function op-list() {
op list "${1}" | jq -c 'map(.overview.title) | sort'
}
function op-retrieve-tripwire() {
op get item "Tripwire Local Passphrase" | jq '.details.password' | tr -d \" | tr -d '\n' | xclip -selection clipboard
}
################################################################################
# Productivity
function timer() {
$(sleep "$1" && notify-send "$2" && espeak "$2" 2>/dev/null) &
}