-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc
More file actions
502 lines (443 loc) · 16.2 KB
/
.zshrc
File metadata and controls
502 lines (443 loc) · 16.2 KB
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# If you come from bash you might have to change your $PATH.
export PATH="$HOME/bin:$PATH"
export PATH="$HOME/.local/bin/:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/bin:$PATH"
# XDG Base Directory specification
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
# Cargo path
export PATH="$HOME/.cargo/bin:$PATH"
# Ruby path
export PATH="$HOME/.local/share/gem/ruby/3.3.0/bin:$PATH"
# Go path
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
# Emacs path
export PATH="$HOME/.config/emacs/bin:$PATH"
# Flatpak exports path
export PATH="/var/lib/flatpak/exports/share:$PATH"
# GitArbor TUI
export PATH="$HOME/.gitarbor/bin:$PATH"
# Source api keys (has to be sourced before zsh-ai gemini provider)
source $HOME/projects/dotfiles/api.env
# ZSH AI integration with local AI models
export ZSH_AI_PROVIDER="gemini" # (anthropic (default), ollama (local), gemini, opennai)
export ZSH_AI_OLLAMA_MODEL="llama3.2"
export ZSH_AI_GEMINI_MODEL="gemini-3-flash-preview"
export ZSH_AI_PROMPT_EXTEND="Always prefer modern CLI tools like ripgrep, fd, and bat."
# Set pop to use outlook SMTP server (for sending emails from CLI)
# export POP_SMTP_HOST=smtp-mail.outlook.com
# export POP_SMTP_PORT=587
# export POP_SMTP_USERNAME=daxisunder@hotmail.com
# export POP_SMTP_PASSWORD=
export POP_FROM=onboarding@resend.dev
export POP_SIGNATURE="Sent with [Pop](https://github.com/charmbracelet/pop)!"
# XDG runtime dir (onedrive)
export XDG_RUNTIME_DIR="/run/user/$UID"
export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"
# Set ydotool socket path
export YDOTOOL_SOCKET="$HOME/.ydotool_socket"
# Add scripts to PATH
export SCRIPTS_DIR="$HOME/projects/dotfiles/scripts"
export PATH="$SCRIPTS_DIR:$PATH"
# Make all scripts executable
if [ -d "$SCRIPTS_DIR" ]; then
find "$SCRIPTS_DIR" -type f -exec chmod +x {} \;
fi
# Set prompt
ZSH_THEME="powerlevel10k/powerlevel10k"
# To customize prompt, run `p10k configure` or edit ~/projects/dotfiles/.p10k.zsh.
[[ ! -f ~/projects/dotfiles/.p10k.zsh ]] || source ~/projects/dotfiles/.p10k.zsh
# Set editor
export EDITOR="nvim"
export SUDO_EDITOR="${EDITOR}"
export VISUAL="${EDITOR}"
# Set bat as manpager
export BAT_THEME="base16-256"
export BAT_STYLE="full"
#export MANPAGER="sh -c 'col -bx | bat -l man -p'"
# Set neovim as manpager
export MANPAGER="nvim +Man!"
# Use QEMU/KVM without sudo permissions
export LIBVIRT_DEFAULT_URI="qemu:///system"
# Compilation flags
export ARCHFLAGS="-arch $(uname -m)"
# Limit make, cmake and cargo to 8 threads (webkit2gtk compilation was causing system to freeze otherwise)
export MAKEFLAGS="-j8"
export CMAKE_BUILD_PARALLEL_LEVEL=8
export CARGO_BUILD_JOBS=8
# Kitty default terminal
export TERM="xterm-kitty"
# History
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=1000000
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
# Set some cool ZSH options ('set -o' to see all options)
setopt no_case_glob # Case insensitive autocompletions
setopt no_case_match # Case insensitive autocompletions
setopt globdots # Include dotfiles in globbing
setopt globcomplete # Enable globbing in completion
setopt extended_glob # Advanced globbing patterns
setopt auto_menu # Automatically highlight first element of completion menu
setopt menu_complete # Use menu completion
setopt list_packed # The completion menu takes less space
setopt auto_list # Automatically list choices on ambiguous completion
setopt complete_in_word # Complete from both ends of a word
setopt correct # Auto-corrections
setopt autocd # Change directory just by typing its name
setopt prompt_subst # Enable command substitution in prompt
setopt interactive_comments # Allow comments in interactive shell
setopt chaselinks # Follow symbolic links when changing directories
# Set comment color (zsh-syntax-highlighting)
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[comment]="fg=#565f89"
# Set auto-suggestions color (default fg=8 is too dark with kitty color8=#1a1b26)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#565f89'
# Load completion engine
autoload -Uz compinit
for dump in ~/.config/zsh/zcompdump(N.mh+24); do
compinit -d ~/.config/zsh/zcompdump
done
compinit -C -d ~/.config/zsh/zcompdump
autoload -Uz add-zsh-hook
autoload -Uz vcs_info
precmd () { vcs_info }
_comp_options+=(globdots)
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} 'ma=0\;33'
zstyle ':completion:*' matcher-list \
'm:{a-zA-Z}={A-Za-z}' \
'+r:|[._-]=* r:|=*' \
'+l:|=*'
zstyle ':completion:*:warnings' format "%B%F{red}No matches for:%f %F{magenta}%d%b"
zstyle ':completion:*:descriptions' format '%F{yellow}[-- %d --]%f'
zstyle ':vcs_info:*' formats ' %B%s-[%F{magenta}%f %F{yellow}%b%f]-'
# Set waiting dots
expand-or-complete-with-dots() {
echo -n "\e[31m…\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
# Set command not found handler (fetch pacman files database first with pacman -Fy)
function command_not_found_handler {
local purple=$'\e[1;35m' bright=$'\e[0;1m' green=$'\e[1;32m' reset=$'\e[0m'
printf 'zsh: Command not found!: %s\n' "$1"
local entries=(
${(f)"$(pacman -F --machinereadable -- "/usr/bin/$1")"}
)
if (( ${#entries[@]} )); then
printf "${bright}%s${reset} may be found in the following packages:\n" "$1"
local pkg=""
for entry in "${entries[@]}"; do
local fields=(${(0)entry})
if [[ "$pkg" != "${fields[2]}" ]]; then
printf "${purple}%s/${bright}%s ${green}%s${reset}\n" \
"${fields[1]}" "${fields[2]}" "${fields[3]}"
printf ' /%s\n' "${fields[4]}"
printf ' → Install with: %s\n' "${green}sudo pacman -S ${fields[2]}${reset}"
printf ' → Install with: %s\n' "${green}yay -S ${fields[2]}${reset}"
pkg="${fields[2]}"
fi
done
else
printf "${bright}No package provides '/usr/bin/$1'.${reset}\n"
printf "You may want to search the AUR manually:\n"
printf " → %syay -Ss $1%s\n" "$green" "$reset"
fi
return 127
}
# Edit command with $EDITOR
autoload -z edit-command-line
zle -N edit-command-line
bindkey '^X' edit-command-line
# Clear backbuffer/screen with CTRL L
function clear-screen-and-scrollback() {
printf '\x1Bc'
zle clear-screen
}
zle -N clear-screen-and-scrollback
bindkey '^L' clear-screen-and-scrollback
# zsh-vi-man
ZVM_MAN_PAGER='nvim'
# Archive extraction (usage: ex <file>)
# Github: https://github.com/xvoland/Extract/blob/master/extract.sh
function ex {
if [ $# -eq 0 ]; then
# display usage if no parameters given
echo "Usage: ex <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz|.zlib|.cso|.zst>"
echo " ex <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
fi
for n in "$@"; do
if [ ! -f "$n" ]; then
echo "'$n' - file doesn't exist"
return 1
fi
case "${n%,}" in
*.cbt|*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar --auto-compress -xvf "$n" ;;
*.lzma) unlzma "$n" ;;
*.lz4) lz4 -d "$n" ;;
*.appimage) ./"$n" --appimage-extract ;;
*.tar.lz4) tar --use-compress-program=lz4 -xvf "$n" ;;
*.tar.br) tar --use-compress-program=pbzip2 -xvf "$n" ;;
*.bz2) bunzip2 "$n" ;;
*.cbr|*.rar) unrar x -ad "$n" ;;
*.gz) gunzip "$n" ;;
*.cbz|*.epub|*.zip) unzip "$n" ;;
*.z) uncompress "$n" ;;
*.7z|*.apk|*.arj|*.cab|*.cb7|*.chm|*.deb|*.iso|*.lzh|*.msi|*.pkg|*.rpm|*.udf|*.wim|*.xar|*.vhd)
7z x "$n" ;;
*.xz) unxz "$n" ;;
*.exe) cabextract "$n" ;;
*.cpio) cpio -id < "$n" ;;
*.cba|*.ace) unace x "$n" ;;
*.zpaq) zpaq x "$n" ;;
*.arc) arc e "$n" ;;
*.cso) ciso 0 "$n" "$n.iso" && extract "$n.iso" && rm -f "$n" ;;
*.zlib) zlib-flate -uncompress < "$n" > "${n%.*zlib}" && rm -f "$n" ;;
*.dmg)
mnt_dir=$(mktemp -d)
hdiutil mount "$n" -mountpoint "$mnt_dir"
echo "Mounted at: $mnt_dir" ;;
*.tar.zst) tar -I zstd -xvf "$n" ;;
*.zst) zstd -d "$n" ;;
*)
echo "ex: '$n' - unknown archive method"
return 1
;;
esac
done
}
# Check plugin commands here: https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/<plugin-name>
plugins=(
auto-notify
colored-man-pages
fancy-ctrl-z
# git
safe-paste
# shellfirm
sudo
vi-mode
you-should-use
zoxide
zsh-ai
zsh-autopair
zsh-autosuggestions
# zsh-expand
zsh-syntax-highlighting
zsh-system-clipboard
zsh-vi-man
)
# OMZ path
export ZSH="$HOME/.oh-my-zsh"
# Source Oh My Zsh
source $ZSH/oh-my-zsh.sh
# Some useful aliases
alias ls='eza -a --icons'
alias lal='eza -al --icons'
alias la='eza -a --tree --level=1 --icons'
alias l.='eza -a | egrep "^\."' # Show only hidden files
alias q='exit'
alias z='cd'
alias .1='cd ..'
alias .2='cd ../..'
alias .3='cd ../../..'
alias .4='cd ../../../..'
alias .5='cd ../../../../..'
alias cpv='cp -vi' # Confirm before overwriting something (verbose)
alias mvv='mv -vi' # Confirm before overwriting something (verbose)
alias rmv='rm -vi' # Confirm before removing something (verbose)
alias mkdir='mkdir -p' # Create parent directories on the fly
alias ping='ping -c 5'
alias df='df -h'
alias du='du -h'
alias ysua='yay -Sua' # Update only AUR packages
alias yd='yay --devel && sudo flatpak update' # Update AUR/development packages + flatpaks
alias yrsn='yay -Rsn'
alias yrsu='yay -Rsu'
alias yrsnu='yay -Rsnu'
alias ys='yay -S'
alias yss='yay -Ss'
alias yqdtq='yay -Qdtq'
alias yqet='yay -Qet'
alias yqi='yay -Qi'
alias ysi='yay -Si'
alias ysii='yay -Sii' # List reverse dependencies
alias yrq='yay -Rsn $(yay -Qdtq)' # List & remove all unneeded dependencies
alias ysc='yay -Sc' # Clean cached packages
alias yi="yay -Slq|fzf -m --preview-window=right:75% --preview 'bat -p <(yay -Qi {1}|grep -e \"Install Reason\";echo \"\") <(yay -Sii {1}) <(yay -Fl {1}|awk \"{print \$2}\")'|xargs -ro yay -S"
alias yu="yay -Qq|fzf -m --preview-window=right:75% --preview 'bat -p <(yay -Qi {1}|grep -e \"Install Reason\";echo \"\") <(yay`` -Sii {1}) <(yay -Ql {1}|awk \"{print \$2}\")'|xargs -ro yay -Rsn"
alias psyu='sudo pacman -Syu && sudo flatpak update' # Update standard packages + flatpaks
alias psyyu='sudo pacman -Syyu' # Update only standard packages and force refresh databases (useful when mirrors are out of sync)
alias prsn='sudo pacman -Rsn'
alias prsu='sudo pacman -Rsu'
alias prsnu='sudo pacman -Rsnu'
alias pacs='sudo pacman -S'
alias pss='pacman -Ss'
alias pqdtq='pacman -Qdtq'
alias pqet='pacman -Qet'
alias pqi='pacman -Qi'
alias psi='pacman -Si'
alias psii='pacman -Sii' # List reverse dependencies
alias prq='sudo pacman -Rsn $(pacman -Qdtq)' # List & remove all unneeded dependencies
alias psc='sudo pacman -Sc' # Clean cached packages
alias unlock='sudo rm -f /var/lib/pacman/db.lck' # Unlock pacman
alias src='source $HOME/.zshrc'
alias ttc='tty-clock -C6 -c'
alias expacs="expac -S '%r/%n: %D'" # List dependencies w/o additional info
alias n='nvim'
alias v='vim'
alias e='emacs -nw'
alias dv='dirs -v'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias psmem='ps auxf | sort -nr -k 4 | head -10' # Show top 10 memory-consuming processes
alias pscpu='ps auxf | sort -nr -k 3 | head -10' # Show top 10 CPU-consuming processes
alias ssn='sudo shutdown now'
alias sr='sudo reboot'
alias jctl='journalctl -p 3' # Show logs with priority 3 and above (errors)
alias fz="fzf --preview-window=right:75% --preview 'bat -n --color=always {}'"
alias wcp='wl-color-picker'
alias wcpc='wl-color-picker clipboard'
alias gstat='$HOME/projects/dotfiles/scripts/Show-GitStatusBash.sh'
alias zsh='nvim .zshrc'
alias nls='nuls -lag'
alias rww='rm /tmp/wttrbar-*.json && wttrbar --location banjaluka >/dev/null 2>&1 && ~/.config/hypr/scripts/Refresh.sh >/dev/null 2>&1' # Refresh wttrbar weather widget and waybar
# Colorize --help output with bat
help() {
"$@" --help 2>&1 | bat -plhelp
}
# Colorize manpages with bat (pager = less)
mann() {
man $1 | col -bx | bat -plman
}
# FZF integration + key bindings (CTRL R for fuzzy history finder)
source <(fzf --zsh)
# FZF theme
export FZF_DEFAULT_OPTS=" \
--style=full \
--highlight-line \
--info=inline-right \
--ansi \
--color=bg+:#1a1b26 \
--color=border:#1a1b26 \
--color=fg:#c0caf5 \
--color=gutter:#16161e \
--color=header:#ff9e64 \
--color=hl+:#2ac3de \
--color=hl:#2ac3de \
--color=info:#545c7e \
--color=marker:#ff007c \
--color=pointer:#ff007c \
--color=prompt:#2ac3de \
--color=query:#c0caf5:regular \
--color=scrollbar:#1a1b26 \
--color=separator:#ff9e64 \
--color=spinner:#ff007c \
"
# FZF previews
# Preview file content using bat (https://github.com/sharkdp/bat)
export FZF_CTRL_T_OPTS="
--walker-skip .git,node_modules,target
--preview 'bat -n --color=always {}'
--bind 'ctrl-/:change-preview-window(down|hidden|)'"
# Print tree structure in the preview window
export FZF_ALT_C_OPTS="
--walker-skip .git,node_modules,target
--preview 'eza --tree --color=always {}'"
# CTRL-Y to copy the command into clipboard using pbcopy
export FZF_CTRL_R_OPTS="
--bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'
--color header:italic
--header 'Press CTRL-Y to copy command into clipboard'"
# Zellij integration
# eval "$(zellij setup --generate-auto-start zsh)"
# Atuin integration (pretty history)
. "$HOME/.atuin/bin/env"
eval "$(atuin init zsh)"
# Wikiman integration
source /usr/share/wikiman/widgets/widget.zsh
# Pay-respects (better command-not-found) integration
eval "$(pay-respects zsh)"
# Yazi integration
function y() {
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd
yazi "$@" --cwd-file="$tmp"
IFS= read -r -d '' cwd < "$tmp"
[ -n "$cwd" ] && [ "$cwd" != "$PWD" ] && builtin cd -- "$cwd"
rm -f -- "$tmp"
}
# Yazi file picker integration (bind to ALT-Y)
yazi_pick_path() {
local file=$(yazi --chooser-file=>(cat))
[[ -z "$file" ]] && zle redisplay && return
LBUFFER+="\"$file\""
zle redisplay
}
zle -N yazi_pick_path
bindkey '\ey' yazi_pick_path
# SuperFile cd-on-quit
spf() {
os=$(uname -s)
if [[ "$os" == "Linux" ]]; then
export SPF_LAST_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/superfile/lastdir"
fi
command spf "$@"
[ ! -f "$SPF_LAST_DIR" ] || {
. "$SPF_LAST_DIR"
rm -f -- "$SPF_LAST_DIR" > /dev/null
}
}
# Fancy-ctrl-z integration (doesn't work if set before sourcing OMZ)
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line -w
else
zle push-input -w
zle clear-screen -w
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
# Carapace integration (argument completion)
export CARAPACE_BRIDGES='zsh,fish,bash,inshellisense' # optional
zstyle ':completion:*' format $'\e[2;37mCompleting %d\e[m'
source <(carapace _carapace)
# Broot integration
source /home/daxis/.config/broot/launcher/bash/br
# Television integration
eval "$(tv init zsh)"
# FZF-navigator
source ~/.config/fzf-navigator.sh >> ~/.${SHELL##*/}rc
export FZF_NAVIGATOR_HIDE_HELP=1
export FZF_NAVIGATOR_SHOW_HIDDEN=1
export FZF_NAVIGATOR_BINDINGS="
ctrl-h:toggle_hidden_files, \
ctrl-d:toggle_file_details, \
alt-b:go_back, alt-f:go_forward, \
~:go_home, \
alt-p:go_to_parent"
# Display Pokemon-colorscripts
# Project page: https://gitlab.com/phoneybadger/pokemon-colorscripts#on-other-distros-and-macos
#pokemon-colorscripts --no-title -s -r
# Display colorscripts
#colorscript -r
# Auto-start "zombie-zfetch"
source $HOME/.config/zfetch/zfetchrc