-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions
186 lines (160 loc) Β· 4.73 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
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
#!/bin/bash
mkd () {
mkdir -p "$@" && cd "$@" || exit
}
# Overwrite when we need secure delete
secure_delete() {
shred -f -n 4 "$1"
}
# Docker prompt
function prompt_docker() {
# shellcheck disable=SC1090
source ~/repos/kube-ps1/kube-ps1.sh
# if [ -f /.dockerenv ]; then
orange=$(tput setaf 166);
white=$(tput setaf 15)
yellow=$(tput setaf 136)
reset_color=$(tput sgr0)
PS1="\[${orange}\]\u" # username
PS1+='\[${white}\]@' # @
PS1+='\[${yellow}\]\h' # hostname
# Unicode Moby
PS1+=' π³ '
PS1+='\[${white}\]:'
PS1+='\[${green}\]\W'
PS1+='\[${white}\]:'
PS1+='$(kube_ps1)' # kube-ps1 prompt
PS1+='\[${reset_color}\]'
PS1+='$ '
export PS1
# fi
}
function prompt_issue_27() {
KUBE_PS1_SYMBOL_USE_IMG=true
KUBE_PS1_SYMBOL_ENABLE=true
KUBE_PS1_SEPARATOR=' '
KUBE_PS1_PREFIX=''
KUBE_PS1_SUFFIX=''
KUBE_PS1_NS_ENABLE=false
source ~/repos/kube-ps1/kube-ps1.sh
source ~/.zsh/prompt/agnoster.zsh
PROMPT='$(kube_ps1) ' $PROMPT
}
function prompt_issue_65() {
export KUBE_PS1_SYMBOL_DEFAULT='lll'
}
# Restore default prompt
function prompt_default () {
# shellcheck disable=SC1090
source ~/.zsh/prompt/steeef.zsh-theme
}
# kubectl context
function prompt_k8s () {
# shellcheck disable=SC1090
source ~/repos/kube-ps1/kube-ps1.sh
# shellcheck disable=SC2125
PROMPT=$'
%F{166}%n${PR_RST} $fg[white]%}at${PR_RST} %{$orange%}%m${PR_RST} $fg[white]%}in${PR_RST} %{$limegreen%}%~ ${PR_RST}$(virtualenv_info)${PR_RST}$(kube_ps1)${PR_RST}
$ '
}
# kubectl context
function prompt_k8s_omz () {
# shellcheck disable=SC1090
source ~/repos/oh-my-zsh/plugins/kube-ps1/kube-ps1.zsh
# shellcheck disable=SC2125
PROMPT=$'
%F{166}%n${PR_RST} $fg[white]%}at${PR_RST} %{$orange%}%m${PR_RST} $fg[white]%}in${PR_RST} %{$limegreen%}%~${PR_RST} $(git_super_status)$(virtualenv_info)$(kube_ps1)
$ '
}
# Switch to a simple prompt to aid in pasting
function prompt_paste () {
export PROMPT='$ '
}
function prompt_simple () {
# Robby Russel prompt to use for minimal prompt
ret_status="%(?:%F{166%}β${PR_RST} :%{$fg_no_bold[red]%}β${PR_RST} )"
# shellcheck disable=SC2016
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%}${PR_RST} '
}
function prompt_simple_k8s () {
#KUBE_PS1_SYMBOL_USE_IMG=true
#KUBE_PS1_SYMBOL_ENABLE=true
#KUBE_PS1_SEPARATOR=' '
#KUBE_PS1_PREFIX=''
#KUBE_PS1_SUFFIX=''
#KUBE_PS1_NS_ENABLE=false
# shellcheck disable=SC1090
# KUBE_PS1_DEFAULT_LABEL_IMG=false
source ~/repos/kube-ps1/kube-ps1-devel/kube-ps1.sh
# ret_status="%(?:%F{166}β :%{$fg_no_bold[red]%}β )"
local ret_status="%(?:%{$fg_bold[green]%}β :%{$fg_bold[red]%}β )"
# shellcheck disable=SC2016
# PROMPT='${ret_status} %{%F{cyan}%}%c%{$reset_color%}${PR_RST}$(kube_ps1) '
PROMPT='%{${ret_status}%} %{$fg[cyan]%}%c%{$reset_color%} $(kube_ps1) '
}
function prompt_simple_k8s_img () {
# shellcheck disable=SC1090
# KUBE_PS1_DEFAULT_LABEL_IMG=true
KUBE_PS1_LABEL_USE_IMG=true
source ~/repos/kube-ps1/kube-ps1.sh
ret_status="%(?:%F{166}β :%{$fg_no_bold[red]%}β )"
# shellcheck disable=SC2016
PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%}%f$(git_super_status)%f$(kube_ps1) '
}
function prompt_k8s_eval () {
# shellcheck disable=SC1090
source ~/repos/kube-ps1/kube-ps1.sh
# shellcheck disable=SC2034
ret_status="%(?:%F{166}β :%{$fg_no_bold[red]%}β )"
while :; do
ts=$(date +%s%N) ; kube_ps1 ; tt=$((($(date +%s%N) - $ts)/1000000)) ; echo "Time taken: $tt milliseconds"
done
}
function prompt_bash_k8s () {
orange=$(tput setaf 166);
green=$(tput setaf 64);
# shellcheck disable=SC1090
bash -l
source ~/repos/kube-ps1/kube-ps1.sh
PS1='\u@\h:\w\ $(kube_ps1) $ '
export PS1
}
# Flush DNS cache
# sometimes after being on VPN, DNS gets a little strange
function flush_dns() {
sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache
}
# Extract yaml from a running deployment
function k8s_yaml_extract() {
if [[ $# -ne 1 ]]; then
echo "Usage: $0 output.yaml"
exit 1
fi
kubectl get deployment "$1" -o yaml --export "$2"
}
# Get the latest Linux Kernel version
function kver() {
curl -s https://www.kernel.org/releases.json | jq '.latest_stable.version' -r
}
function kcdebug() {
kubectl run -i --rm --tty debug --image=debian:stable-slim --restart=Never -- bash
}
function dnsutil() {
docker run -it gcr.io/kubernetes-e2e-test-images/dnsutils:1.3 /bin/sh
}
function gitsync() {
git fetch upstream
git checkout master
git rebase upstream/master
}
function oc_rename() {
oc config rename-context $(oc config current-context) "${1}"
}
function pasta() {
xclip -sel clip < "${1}"
}
add_to_path_front() {
if [[ "$PATH" != *"$1"* ]]; then
export PATH=$1:$PATH
fi
}