-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc
335 lines (282 loc) · 9.2 KB
/
dot_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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME=""
plugins=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)
source $ZSH/oh-my-zsh.sh
#Star Ship
eval "$(starship init zsh)"
# Brew
if type brew &>/dev/null
then
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
autoload -Uz compinit
compinit
fi
eval "$(thefuck --alias)"
# Generated for envman. Do not edit.
[ -s "$HOME/.config/envman/load.sh" ] && source "$HOME/.config/envman/load.sh"
export EDITOR='emacs'
export VISUAL="$EDITOR"
# # Exa aliases
alias ls='eza --icons --group-directories-first'
alias la='eza -a --icons --group-directories-first'
alias lsa='eza -a --icons --group-directories-first'
alias ll='eza -lah --icons --group-directories-first'
alias l='eza -lh --icons --group-directories-first'
alias tree='eza --tree --icons --group-directories-first'
alias v='nvim' # Neovim shortcut
alias o='open' # macOS open shortcut
alias owd='open ./' # Open current dir in Finder (macOS)
alias doit='dooit'
alias c='clear'
alias ne='neofetch'
alias v="nvim"
# shorten cd ../../../
alias .1='cd ..'
alias .2='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
# pdfrenamer alias
alias rename='pdfrenamer ./ -f "{T}_{Aall}" -case snake'
#Colors
# export FZF_DEFAULT_OPTS=" --ansi --preview-window 'right:60%' --preview 'bat --color=always --style=header,grid --line-range :300 {}' \
# --color=marker:#f2d5cf,fg+:#c6d0f5,prompt:#ca9ee6,hl+:#e78284"
export FZF_DEFAULT_OPTS="\
--ansi \
--height 75% --multi --reverse --margin=0,1
--cycle \
--preview '([[ -f {} ]] && (bat --style=numbers --color=always --style=header,grid --line-range :300 {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
--preview-window='right:70%' \
--bind='?:toggle-preview' \
--bind='tab:down' \
--color=marker:#f2d5cf,fg+:#c6d0f5,prompt:#ca9ee6,hl+:#e78284\
"
# --preview='(highlight -O ansi -l {} 2> /dev/null || bat --color=alwyas --style=header,grid --line-range :300 {} || tree -L 2 -C {}) 2> /dev/null | head -200' \
# --height='75%' \
# --layout='reverse' \
export FZF_DEFAULT_COMMAND_OPTS="
--hidden \
--follow \
--type='f' \
--exclude='.git' \
"
export FZF_CTRL_R_OPTS="
--sort \
--exact \
--preview-window='down:3:hidden:wrap' \
"
export FZF_CTRL_T_OPTS="
--select-1 \
--exit-0 \
--preview 'bat --color=always --style=header,grid --line-range :100 {}'\
"
export FZF_ALT_C_OPTS="
--select-1 \
--exit-0 \
--preview 'tree -C {} | head -100'\
"
export FZF_DEFAULT_COMMAND="fd ${FZF_DEFAULT_COMMAND_OPTS}"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# More fuzzy searches
eval "$(zoxide init zsh)"
eval "$(thefuck --alias)"
bindkey '^f' mcfly-history-widget
eval "$(mcfly init zsh)"
export MCFLY_KEY_SCHEME=vim
export MCFLY_FUZZY=2
export MCFLY_RESULTS=20
export MCFLY_PROMPT="❯"
# lfcd
f() {
tmp="$(mktemp)"
# `command` is needed in case `lfcd` is aliased to `lf`
command lf -last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
fi
fi
}
# nnn
n() {
# See nnn Project's misc/quitcd
if [ -n $NNNLVL ] && [ "${NNNLVL:-0}" -ge 1 ]; then
echo "nnn is already running"
return
fi
export NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
nnn -e -Pp -Tt "$@"
if [ -f "$NNN_TMPFILE" ]; then
. "$NNN_TMPFILE"
rm -f "$NNN_TMPFILE" > /dev/null
fi
}
# rga + fzf
rga() {
RG_PREFIX="rga --files-with-matches --column --line-number --no-heading --color=always --smart-case"
local file
file="$(
FZF_DEFAULT_COMMAND="$RG_PREFIX '$1'" \
fzf --sort --preview="[[ ! -z {} ]] && rga --pretty --context 5 {q} {}" \
--phony -q "$1" \
--bind "change:reload:$RG_PREFIX {q}" \
--preview-window="70%:wrap" \
# --preview 'bat --color=always --style=header,grid --line-range :300 {}' \
# --color=bg+:#3c3836,bg:#32302f,spinner:#fb4934,hl:#928374,fg:#ebdbb2,header:#928374,info:#8ec07c,pointer:#fb4934,marker:#fb4934,fg+:#ebdbb2,prompt:#fb4934,hl+:#fb4934
)" &&
echo "opening $file" &&
open "$file"
}
p() {fuzzy-pdf -c 10 . 'open'}
# usage: ex <file>
ex () {
if [ -f "$1" ] ; then
case $file in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1;;
*.7z) 7z x $1 ;;
*.deb) ar x $1 ;;
*.tar.xz) tar xf $1 ;;
*.tar.zst) unzstd $1 ;;
*) echo "'$1' cannot be extracted via ex()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#connect to vpn
vc() {
~/vpn.exp
}
jc() {
# ~/vpn.exp
# SSH to the cluster and submit the Jupyter sbatch job.
# Capture the job ID for further use.
JOB_ID=$(ssh [email protected] "/opt/slurm/bin/sbatch jupyter_sbatch.sh" | grep -oP '\d+')
if [[ -n "$JOB_ID" ]]; then
echo "Job submitted with ID: $JOB_ID"
echo $JOB_ID > ~/job_id.txt
else
echo "Failed to submit job or retrieve job ID."
fi
# Give it a few seconds for the job to initialize.
sleep 5
# Check if the job is running.
# Modify the loop count or sleep duration if necessary.
COUNTER=10
while [[ $COUNTER -gt 0 ]]; do
STATUS=$(ssh [email protected] "/opt/slurm/bin/squeue -j $JOB_ID" | tail -n +2 | awk '{print $5}')
if [[ $STATUS == "R" ]]; then
break
fi
sleep 5
let COUNTER-=1
done
# Set up port forwarding.
if [[ $STATUS == "R" ]]; then
ssh -N -f -L localhost:8888:ielsc-99:8888 [email protected]
else
echo "Jupyter job did not start successfully."
fi
}
jcn() {
# ~/vpn.exp
# SSH to the cluster and submit the Jupyter sbatch job.
# Capture the job ID for further use.
JOB_ID=$(cat ~/job_id.txt)
if [[ -n "$JOB_ID" ]]; then
# Cancel the Slurm job
echo "Existing job ID found."
else
echo "Starting new job."
JOB_ID=$(ssh [email protected] "/opt/slurm/bin/sbatch jupyter_sbatch.sh" | grep -oP '\d+')
echo "Job submitted with ID: $JOB_ID"
echo $JOB_ID > ~/job_id.txt
fi
# Give it a few seconds for the job to initialize.
sleep 5
# Check if the job is running.
# Modify the loop count or sleep duration if necessary.
COUNTER=10
while [[ $COUNTER -gt 0 ]]; do
STATUS=$(ssh [email protected] "/opt/slurm/bin/squeue -j $JOB_ID" | tail -n +2 | awk '{print $5}')
if [[ $STATUS == "R" ]]; then
break
fi
sleep 5
let COUNTER-=1
done
# Set up port forwarding.
if [[ $STATUS == "R" ]]; then
ssh -N -f -L localhost:8888:ielsc-99:8888 [email protected]
else
echo "Jupyter job did not start successfully."
fi
}
jd() {
# Assuming the job ID is stored in a file named "job_id.txt"
JOB_ID=$(cat ~/job_id.txt)
if [[ -n "$JOB_ID" ]]; then
# Cancel the Slurm job
ssh [email protected] "/opt/slurm/bin/scancel $JOB_ID"
echo "Cancelled job with ID: $JOB_ID."
rm ~/job_id.txt
else
echo "No job ID found."
fi
# Find the process ID (PID) of the process running on port 8888
pid=$(lsof -ti :8888)
# Check if a process is running on port 8888
if [[ -n $pid ]]; then
# Kill the process
kill $pid
echo "Process on port 8888 has been killed"
else
echo "No process found on port 8888"
fi
}
#disconnect to vpn
vd() {
/opt/cisco/anyconnect/bin/vpn disconnect
}
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
eval "$(rbenv init -)"
# eval "$(github-copilot-cli alias -- "$0")"
# export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export PATH="$PATH:$HOME/.local/bin"
export PATH=$PATH:/Users/nisch/.spicetify
export PATH=$HOME/.emacs.d/bin:$PATH
export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home"
export PATH="/opt/homebrew/opt/grep/libexec/gnubin:$PATH"
alias te="~/.emacs.d/emacs-client-server.sh"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion