-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
171 lines (135 loc) · 3.83 KB
/
.zshrc
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
zstyle :omz:plugins:ssh-agent identities ~/.ssh/id_ed25519 ~/.ssh/keys/{github_personal,bitbucket_mpk}
export ZSH=$HOME/.oh-my-zsh
HISTORY_IGNORE="(jwt-decode*|systemctl poweroff)"
ZSH_THEME="sunaku-zapling"
plugins=(git ssh-agent)
source $ZSH/oh-my-zsh.sh
eval "$(direnv hook zsh)"
# Soft disable 'exit' on dropdown terminals
protectDropdownTerminal () {
ID=$(ps -p $$ -o ppid= | tr -d '[:space:]')
PARAM=$(ps -p $ID o args=)
if [[ $PARAM =~ "dropdown" ]];
then
# Prevent CTRL-D on dropdown terminals
setopt IGNORE_EOF
function exit() {
if [[ "$1" == "-f" ]]; then
builtin exit
fi
echo "You should not exit a dropdown terminal!"
echo "Use restart-dropdown-terminals to restart terminals"
printf "Use \\\exit to force exit\n"
return 1
}
fi
}
protectDropdownTerminal
# Source private stuff
[ -e ~/.private ] && source ~/.private
# Dialog before doing stupid stuff
function git() {
confirm=0
# confirm before doing hard resets
if [[ "$1" == "reset" ]] && [[ "$2" == "--hard" ]]; then
confirm=1
fi
if [[ "$1" == "push" ]] && [[ "$2" == "-f" ]]; then
confirm=1
fi
if [[ "$1" == "clean" ]] && [[ "$2" == "-fd" ]]; then
confirm=1
fi
if [[ $confirm -eq 1 ]]; then
echo "Are you being retarded? Press any key to continue..."
read -sk1
echo ""
fi
command git $@
}
function git-checkout-date () {
default_branch=$(git branch --show-current)
if [[ "$default_branch" == "" ]]; then
default_branch="main"
fi
date_input=$1
time_input=${2:-00:00}
branch_input=${3:-$default_branch}
git checkout `git rev-list -n 1 --first-parent --before="$date_input $time_input" $branch_input`
}
function docker() {
if [[ "$1" == "kill-all" || "$1" == "stop-all" ]]; then
containers=($(docker ps -q))
if [[ "$containers" == "" ]]; then
echo "Nothing to stop"
return 1
fi
command docker kill $containers
return
fi
if [[ "$1" == "rm-all" ]]; then
command docker ps --filter status=exited -q | xargs docker rm
return
fi
command docker $@
}
# Start a temp docker container with the given entrypoint
function drun() {
image=$1
entrypoint=${2:-sh}
if [[ "$image" == "" ]]; then
echo "drun [IMAGE] [ENTRYPOINT]"
return 1
fi
command docker run -it --rm --entrypoint $entrypoint $image
}
# Attach to a running docker container with the given entrypoint
function dattach() {
container=$1
entrypoint=${2:-sh}
if [[ "$container" == "" ]]; then
echo "dattach [CONTAINER] [ENTRYPOINT]"
return 1
fi
command docker exec -it $container $entrypoint
}
# Attach to a running k8s pod with the given entrypoint
function kattach() {
namespace=$1
pod=$2
if [[ "$namespace" == "" ]] || [[ "$pod" == "" ]]; then
echo "kattach [NAMESPACE] [POD] [ENTRYPOINT]"
return 1
fi
entrypoint=${3:-sh}
kubectl exec --stdin --tty -n $namespace $pod -- $entrypoint
}
function frm() {
CUR=$(pwd)
FILENAME=$(uuidgen)
cd ~/P/frame && go build -o /tmp/$FILENAME frame.go
EXIT_CODE=$?
cd $CUR
if [[ $EXIT_CODE -gt 0 ]]; then
return $EXIT_CODE
fi
/tmp/./$FILENAME $@
}
function make() {
if [[ -f "./Earthfile" ]]; then
print "\033[1;33mEarthfile detected, switching to earthly\033[0m\n"
~/.local/bin/earthly-linux-amd64 $@
return
fi
command make $@
}
alias vi="nvim --clean"
alias vim="nvim"
alias gom="go mod tidy && go mod vendor"
alias task="go-task"
alias k="kubectl"
alias kx="kubectx"
alias fsize="du -a 2>/dev/null | sort -n"
# Work
alias ert="~/R/ertia/ertia/ertia"
alias earthly="~/.local/bin/earthly-linux-amd64"