-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_zshrc
227 lines (194 loc) · 6.57 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env zsh
# Force switch to zsh if not already running in it
if [ -z "${ZSH_VERSION:-}" ]; then
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Switching to zsh..."
export SHELL=$(command -v zsh)
exec zsh -l "$0" "$@"
fi
echo "[$(date +'%Y-%m-%d %H:%M:%S')] Running in zsh version: $ZSH_VERSION"
export ZSH="${HOME}/.oh-my-zsh"
export ZSH_THEME='miloshadzic'
# Consolidated plugin list to avoid duplication
function get_plugins() {
local common_plugins=(
git tmux python sudo docker rust docker-compose gitfast kubectl
mvn rust tmuxinator zsh-completions zsh-autosuggestions
zsh-syntax-highlighting zsh-history-substring-search
)
if [ "$(uname)" = "Darwin" ]; then
echo "${common_plugins[@]} brew macos"
else
echo "${common_plugins[@]}"
fi
}
function init() {
local zsh_plugins=(zsh-completions zsh-autosuggestions zsh-syntax-highlighting zsh-history-substring-search)
for plugin in "${zsh_plugins[@]}"; do
local plugin_dir="${ZSH}/plugins/${plugin}"
if [ ! -d "${plugin_dir}" ]; then
(cd "${ZSH}/plugins" && git clone "https://github.com/zsh-users/${plugin}.git")
fi
done
}
function plugins() {
plugins=($(get_plugins))
source "${ZSH}/oh-my-zsh.sh"
}
function define_path() {
local base_path="/usr/local/sbin:/usr/local/bin:/bin:/usr/sbin:/sbin:/usr/bin"
export PATH="${base_path}"
if [ "$(uname)" = "Darwin" ]; then
export PATH="${PATH}:/opt/homebrew/bin:/Applications/Xcode.app/Contents/Developer/usr/bin"
[ -f "${HOME}/src/z.lua/z.lua" ] && eval "$(lua ${HOME}/src/z.lua/z.lua --init zsh enhanced)"
[ -d "/usr/local/opt/python@3.8/" ] && export PATH="/usr/local/opt/python@3.8/bin:${PATH}"
elif [ "$(uname)" = "Linux" ]; then
[ -f "/usr/bin/lua" ] && eval "$(lua ${HOME}/src/z.lua/z.lua --init zsh enhanced)"
fi
[ -d "${GOPATH}" ] && export PATH="${PATH}:${GOPATH}/bin"
}
function custom_exports() {
define_path
# Core exports
export EDITOR="vim"
export REPO_PATH="${HOME}/src/"
export PYTHONPATH="${HOME}/src/caliber"
export PIP_DOWNLOAD_CACHE="${HOME}/.pip/cache"
export PYTHONSTARTUP="${HOME}/.pythonrc.py"
export GOROOT="${HOME}/go"
export GOPATH="${HOME}/go/pkg"
export PATH="${PATH}:${GOROOT}/bin"
# Development related
export PEXPECT_START_TIMEOUT=180
export CALIBER_DEBUG=1
export TF_CPP_MIN_LOG_LEVEL=2
export COMPOSE_API_VERSION=auto
export SNYK_DISABLE_ANALYTICS=1
export COLORLOG=1
export SHELL=/bin/zsh
export LUNA_DEBUG=1
export BUILDKIT_COLORS="run=123,20,245:error=yellow:cancel=blue:warning=white"
# Java setup
if [ "$(uname)" = "Darwin" ]; then
export JAVA_HOME=$(/usr/libexec/java_home)
else
export JAVA_HOME="/usr/lib/jvm/java-1.11.0-openjdk-amd64"
fi
export JDK_HOME="${JAVA_HOME}"
# Source additional config files if they exist
local config_files=(
"${HOME}/google-cloud-sdk/path.zsh.inc"
"${HOME}/google-cloud-sdk/completion.zsh.inc"
"${HOME}/.cargo/env"
"${HOME}/.ssh/kub_detection_db.properties"
"${HOME}/env/export.properties"
"${HOME}/.poetry/env"
"${HOME}/.ssh/secrets.env"
)
for file in "${config_files[@]}"; do
[ -f "${file}" ] && source "${file}"
done
}
function custom_aliases() {
. "${HOME}/src/dotfiles/aliases.zsh"
# Modern CLI alternatives
alias ping='prettyping --nolegend'
alias cat='bat'
alias top='glances'
alias du="ncdu --color dark -rr -x --exclude .git --exclude node_modules"
alias l='eza --long --git -g -a -s modified'
alias k='kubecolor'
alias kubectl="kubecolor"
# Navigation aliases
alias zc='z -c' # restrict matches to subdirs of $PWD
alias zz='z -i' # cd with interactive selection
alias zf='z -I' # use to select in multiple matches
alias zb='z -b' # quickly cd to the parent directory
# Configuration aliases
alias zconf="vim ${HOME}/.zshrc"
alias reload=". ${HOME}/.zshrc"
# Bulk update aliases
alias gall="for i in \$(find ${HOME}/src -type d -execdir test -d {}/.git \; -prune -print); do (echo \"==== Updating \$i ====\"; cd \$i; git stash && g p && gfa && git stash pop; cd -); done"
alias pipall="for i in \$(pip list -o --format columns|awk '{print \$1}') ; do pip install -U \$i; done"
alias dall="docker images --format \"{{.Repository}}:{{.Tag}}\" | grep ':latest' | xargs -L1 docker pull"
}
function enable_node() {
if [ -f "${HOME}/.nvm/nvm.sh" ]; then
export NVM_DIR="${HOME}/.nvm" && . "${HOME}/.nvm/nvm.sh"
fi
}
function jlog() {
less +F -r $@ |jq . -r
}
function sleep-in() {
local minutes=$1
local datetime=`date -v+${minutes}M +"%m/%d/%y %H:%M:%S"`
sudo pmset schedule sleep "$datetime"
}
function ssh_agent() {
if [ -f "${HOME}/.ssh/bakhru_me_id_rsa" ]; then
ssh-add --apple-use-keychain ~/.ssh/bakhru_me_id_rsa
fi
if [ -f "${HOME}/.ssh/id_ed25519" ]; then
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
fi
if [ "${SSH_AUTH_SOCK}" != "${HOME}/.ssh/ssh_auth_sock" ]; then
ln -sf "${SSH_AUTH_SOCK}" ~/.ssh/ssh_auth_sock
fi
ls -larth ~/.ssh/ssh_auth_sock
}
function setup_ssh_agent() {
if ssh-add -l; then
echo "Your SSH Agent is already working."
return 0
fi
for sock in $(ls /tmp/ssh-*/agent.*); do
export SSH_AUTH_SOCK=$sock
if ssh-add -l; then
echo "Your SSH Agent is fixed. New socket=$sock."
return 0
fi
done
echo "Could not find any working SSH Agent sockets."
return 1
}
function ueba_env() {
export CLUSTER_NAME=$@
export AWS_PROFILE=kognos
export KUBECONFIG=~/.kube/$@-eks.yaml
export NAMESPACE=luna
export LUNA_CONFIG=${PWD}/luna/config.json
eval $(aws-sso-creds export -p da)
}
# Initialize everything
custom_exports
plugins
enable_node
custom_aliases
# Platform specific setup
if [ "$(uname)" = "Darwin" ]; then
ssh_agent
else
setup_ssh_agent
fi
# Theme loading
if [ -n "${ZSH_THEME}" ]; then
for theme_path in "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme" \
"$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme" \
"$ZSH/themes/$ZSH_THEME.zsh-theme"; do
[ -f "${theme_path}" ] && source "${theme_path}" && break
done
fi
# Final PATH adjustments and completions
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
export PATH="$HOME/.poetry/bin:$PATH"
export GROOVY_HOME=/opt/homebrew/opt/groovy/libexec
# ZSH completion setup
# autoload -Uz compinit
# zstyle ':completion:*' menu select
# fpath+=~/.zfunc
# Load additional environments if they exist
[ -d "$HOME/.rye" ] && source "$HOME/.rye/env"
[ -s "${HOME}/.bun/_bun" ] && source "${HOME}/.bun/_bun"
# [ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion"
# Initialize starship prompt
eval "$(starship init zsh)"