summaryrefslogtreecommitdiff
path: root/.config/shell/.zshrc
blob: 542c6df6a1c0e6e796de2d924d2b7b7d64cd10c2 (plain)
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
# =============================================================================
# Filip's config for the zoomer shell
# =============================================================================

# ─── 1) Fundamental environment ──────────────────────────────────────────────
export PATH="$HOME/.local/bin:$PATH"
[ -f "$ALIASRC"  ] && source "$ALIASRC"

# ─── 2) Shell behaviour ──────────────────────────────────────────────────────
autoload -U colors && colors
setopt auto_pushd
setopt no_check_jobs
setopt pushd_ignore_dups
setopt pushd_silent
setopt autocd
setopt interactive_comments
stty stop undef
unsetopt beep

zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zsh/zcompcache"
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' use-cache on

# ─── 3) Prompt ───────────────────────────────────────────────────────────────
blue=$(tput setaf 34)
green=$(tput setaf 40)
cyan=$(tput setaf 46)
lime=$(tput setaf 154)
reset=$(tput sgr0)

# Precomputed colors avoid running commands in PS1
PS1="%{$blue%}%n%{$green%}@%{$cyan%}%m %{$lime%}%1~ %{$reset%}$ "

# ─── 4) History ──────────────────────────────────────────────────────────────
HISTSIZE=10000000
SAVEHIST=10000000
if [[ ! -d "${XDG_CACHE_HOME:-$HOME/.cache}/shell" ]]; then
  mkdir -p "${XDG_CACHE_HOME:-$HOME/.cache}/shell"
fi
HISTFILE="${XDG_CACHE_HOME:-$HOME/.cache}/shell/history"

setopt inc_append_history
setopt hist_ignore_all_dups
setopt hist_find_no_dups
setopt hist_save_no_dups

# ─── 5) Vi mode & ZVM variables ──────────────────────────────────────────────
export KEYTIMEOUT=1
ZVM_LINE_INIT_MODE=$ZVM_MODE_INSERT
ZVM_SYSTEM_CLIPBOARD_ENABLED=true
ZVM_CLIPBOARD_COPY_CMD='xclip -selection clipboard'
ZVM_CLIPBOARD_PASTE_CMD='xclip -selection clipboard -o'
ZVM_LAZY_KEYBINDINGS=false

# ─── 6) Zinit & plugins ──────────────────────────────────────────────────────
[[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]] && {
    print -P "%F{33} Installing %F{220}Zinit…%f"
    mkdir -p "$HOME/.local/share/zinit"
    git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git"
}

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# Core annexes
zinit light-mode for \
    zdharma-continuum/zinit-annex-as-monitor \
    zdharma-continuum/zinit-annex-bin-gem-node \
    zdharma-continuum/zinit-annex-patch-dl \
    zdharma-continuum/zinit-annex-rust

# Plugins: **vi-mode first, then autosuggestions, then others**
zinit ice depth=1
zinit light-mode for \
    jeffreytse/zsh-vi-mode \
    zsh-users/zsh-autosuggestions \
    zsh-users/zsh-completions \
    zsh-users/zsh-history-substring-search \
    zsh-users/zsh-syntax-highlighting

# Autosuggestions config
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#999999,bg=default,underline"
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=100

# ─── 7) Completion ───────────────────────────────────────────────────────────
# Run compinit **after all plugins** to avoid wiping widgets
autoload -Uz compinit
for dump in "${ZDOTDIR:-$HOME}/.zcompdump"(N.m1); do
    compinit
    break
done
compinit -C
zstyle ':completion:*' menu select
zmodload zsh/complist
fpath=(/usr/share/zsh/site-functions $fpath)
_comp_options+=(globdots)        # hidden files

# ─── 8) Keybindings ──────────────────────────────────────────────────────────
# Better backspace in vi mode
bindkey -v '^?' backward-delete-char

# Menu navigation with vim keys
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char

# history substring search (up/down)
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey -M vicmd 'k' history-substring-search-up
bindkey -M vicmd 'j' history-substring-search-down

# accept autosuggest
bindkey '^f' autosuggest-accept

# ─── 9) Custom functions & widgets ───────────────────────────────────────────
lfcd() {
    local tmp="$(mktemp -uq)"
    trap 'rm -f $tmp >/dev/null 2>&1' EXIT
    lf -last-dir-path="$tmp" "$@"
    [ -f "$tmp" ] && {
        local dir="$(cat "$tmp")"
        [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
    }
}

lfcd_widget()  { zle -I; BUFFER="lfcd";  zle accept-line; }
gitui_widget() { zle -I; BUFFER="gitui"; zle accept-line; }
htop_widget()  { zle -I; BUFFER="htop";  zle accept-line; }

zle -N lfcd_widget
zle -N gitui_widget
zle -N htop_widget

bindkey -M viins '^o' lfcd_widget
bindkey -M vicmd '^o' lfcd_widget
bindkey -M viins '^g' gitui_widget
bindkey -M vicmd '^g' gitui_widget
bindkey -M viins '^t' htop_widget
bindkey -M vicmd '^t' htop_widget

# ─── 10) Tool initializations ─────────────────────────────────────────────────
eval "$(zoxide init zsh)"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
# __conda_setup="$('/home/filipek/.local/opt/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
# if [ $? -eq 0 ]; then
#     eval "$__conda_setup"
# else
#     if [ -f "/home/filipek/.local/opt/miniconda3/etc/profile.d/conda.sh" ]; then
#         . "/home/filipek/.local/opt/miniconda3/etc/profile.d/conda.sh"
#     else
#         export PATH="/home/filipek/.local/opt/miniconda3/bin:$PATH"
#     fi
# fi
# unset __conda_setup
# <<< conda initialize <<<

# ─── 11) Local overrides (create this file if needed) ─────────────────────────
[ -f ~/.zshrc.local ] && source ~/.zshrc.local