-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zsh_functions.tmpl
140 lines (127 loc) · 3.84 KB
/
dot_zsh_functions.tmpl
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
## zsh functions
# ===============================================================
function edit-command-line-inplace() {
if [[ $CONTEXT != start ]]; then
if (( ! ${+widgets[edit-command-line]} )); then
autoload -Uz edit-command-line
zle -N edit-command-line
fi
zle edit-command-line
return
fi
() {
emulate -L zsh -o nomultibyte
local editor=("${(@Q)${(z)${VISUAL:-${EDITOR:-vi}}}}")
case $editor in
(*vim*)
"${(@)editor}" -c "normal! $(($#LBUFFER + 1))go" -- $1
;;
(*emacs*)
local lines=("${(@f)LBUFFER}")
"${(@)editor}" +${#lines}:$((${#lines[-1]} + 1)) $1
;;
(*)
"${(@)editor}" $1
;;
esac
BUFFER=$(<$1)
CURSOR=$#BUFFER
} =(<<<"$BUFFER") </dev/tty
}
function fix-zsh-history() {
mv ~/.zsh_history ~/.zsh_history_bad
strings ~/.zsh_history_bad > ~/.zsh_history
fc -R ~/.zsh_history
rm ~/.zsh_history_bad
}
{{- if .islastpasspresent }}
## enterprise proxy functions
## ==============================================================
function add-proxy(){
export SHELLPROXY_URL="{{ (index (lastpassRaw "proxy value") 0).note }}"
}
{{- end }}
## p10k functions
## ==============================================================
function toggle-kubecontext-segment() {
(( ${+functions[p10k]} )) || return
p10k display '*/kubecontext'=show,hide;
}
function toggle-time-segment() {
(( ${+functions[p10k]} )) || return
p10k display '*/time'=hide,show;
}
function toggle-wifi-segment() {
(( ${+functions[p10k]} )) || return
p10k display '*/wifi'=hide,show;
}
function toggle-lastpass-segment() {
(( ${+functions[p10k]} )) || return
p10k display '*/my_lpass'=hide,show;
}
function toggle-transient-prompt() {
if [[ $POWERLEVEL9K_TRANSIENT_PROMPT != off ]]; then
POWERLEVEL9K_TRANSIENT_PROMPT=off
else
POWERLEVEL9K_TRANSIENT_PROMPT=always
fi
p10k reload
}
zle -N toggle-lastpass-segment
bindkey '^P' toggle-lastpass-segment
zle -N toggle-time-segment
bindkey '^T' toggle-time-segment
zle -N toggle-wifi-segment
bindkey '^N' toggle-wifi-segment
zle -N toggle-kubecontext-segment
bindkey '^K' toggle-kubecontext-segment
## Node functions
## ==============================================================
function configureNvm(){
export NVM_DIR="$HOME/.nvm"
. "/opt/homebrew/opt/nvm/nvm.sh"
}
## asdf functions
## ==============================================================
function updAsdfTools() {
for t in "${(@f)"$(<~/.tool-versions)"}"; do
pkg="$(echo "${t}" | cut -d ' ' -f1)"
if [[ "${t}" == *"system"* || ${pkg} == "kubectl" ]]; then
echo "${pkg} is set as system package or pinned (nothing to do)"
else
asdf install ${pkg} latest && asdf global ${pkg} latest
fi
done
}
## aws functions
## ==============================================================
function aws-ecr-repo-empty-list () {
for repo in $(aws ecr describe-repositories | jq -cr '.repositories | .[].repositoryName' | sed 's/\r//g'); do
IMAGES=$(aws ecr list-images --repository-name ${repo} | grep imageDigest)
#echo $i -- $repo
if [[ "$?" -eq "1" ]]; then
echo "${repo}: empty"
if [[ "$1" == "-d" ]]; then
aws ecr delete-repository --repository-name ${repo}
fi
fi
done
}
{{- if .islastpasspresent }}
function aws-start-inf1 () {
inst-id="$(aws ec2 describe-instances --filters "Name=tag:Name,Values={{ (index (lastpassRaw "inf1_tag_name") 0).note }}" --query 'Reservations[].Instances[].InstanceId' --output text)"
aws ec2 start-instances --instance-ids $inst-id
}
{{- end }}
## brew functions
## ==============================================================
function brew_find_pkg {
file_to_search="$@"
for package in $(brew list); do
brew ls $package | grep -E -q "/${file_to_search}$"
if [ $? -eq 0 ]; then
echo $package
break
fi
done
}