summary refs log tree commit diff
path: root/dot_config/zsh/dot_zshrc
blob: ab059fd89f6bf01a28c104971654d93ceb3b67e8 (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
#!/usr/bin/env zsh

# Set up nice and lengthy history
export HISTFILE="${ZDOTDIR:-$HOME}/.zsh_history"
export HISTSIZE=1000000
export SAVEHIST=1000000

# Simple prompt
PROMPT="%F{15}%K{4}%n@%M:%~%f%k "
RPROMPT="%(?.%F{10}%?.%F{9}%?)%f %T"

autoload -U compaudit compinit zrecompile giti
autoload -U colors && colors


export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:${PATH}"

# zinit
declare -A ZINIT
ZINIT[HOME_DIR]="${XDG_CONFIG_HOME}/zinit"
ZINIT[ZCOMPDUMP_PATH]="${XDG_CACHE_HOME}/zcompdump-${HOSTNAME}-${ZSH_VERSION}"
source "${XDG_DATA_HOME}/zinit/zinit.git/zinit.zsh"

# bashcompinit after zinit sets up compdump path
autoload -U +X bashcompinit && bashcompinit

# Powerlevel10k instant prompt. Any input prompts above, other stuff below
if [[ -r "${XDG_CACHE_HOME}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
    source "${XDG_CACHE_HOME}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# Speed up autosuggestions by requiring manual rebind if ever lost
ZSH_AUTOSUGGEST_MANUAL_REBIND=1

ZSH_CUSTOM="${XDG_DATA_HOME:-${HOME}/.local/share}/zsh"

zinit load "${ZSH_CUSTOM}/brew/"
zinit load "${ZSH_CUSTOM}/fzf/"
zinit load "${ZSH_CUSTOM}/completion/"
zinit load "${ZSH_CUSTOM}/clipboard/"
zinit load "${ZSH_CUSTOM}/git/"
zinit load "${ZSH_CUSTOM}/powerlevel10k/"
zinit load "${ZSH_CUSTOM}/coloured-man/"
zinit load "${ZSH_CUSTOM}/zsh-autosuggestions/"
zinit load "${ZSH_CUSTOM}/fast-syntax-highlighting/"
zinit load "${ZSH_CUSTOM}/auto-activate-venv/"
zinit load "${ZSH_CUSTOM}/fzf-z/"
zinit load "${ZSH_CUSTOM}/bindings/"
# zinit load "${ZSH_CUSTOM}/zsh-autocomplete/"

# zinit has issues, use zsh-defer
# zinit load "${ZSH_CUSTOM}/zsh-edit/"
source "${ZSH_CUSTOM}/zsh-defer/zsh-defer.plugin.zsh"
zsh-defer source "${ZSH_CUSTOM}/zsh-edit/zsh-edit.plugin.zsh"
zsh-defer bindkey '^W' backward-kill-subword
zsh-defer bindkey '^H' backward-kill-shell-word

zsh-defer source "${ZDOTDIR}/alias.zsh"

zinit ice as"completion"
zinit snippet "${ZSH_CUSTOM}/completion/_pass"

zinit ice as"completion"
zinit snippet https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker

zinit ice as"completion"
zinit snippet https://github.com/zsh-users/zsh-completions/blob/master/src/_nano

# get git-extras + git-extras completions
alias pip='noglob python -m pip'

# zinit load ${ZSH}/plugins/fasd/
# steal: j/z but use fzf?

# zinit load ${ZSH}/plugins/fzf/
# steal: fzf-completion
# steal: fzf-cd-widget
# steal: fzf-history-widget

zicompinit
zicdreplay

# echo ${INSTALLED_COMPS}

# Set editor to micro/nano
if which micro &>/dev/null; then
    export EDITOR='micro'
    function micro() {
        emulate -L zsh
        autoload is-at-least
        if is-at-least 2.0.0 $(command env micro -version | cut -d' ' -f2); then
            unset -f micro
            command env micro "$@"
        else
            local log_exists
            if [[ -f log.txt ]]; then
                log_exists=1
            fi
            command env micro "$@"
            if [[ -f log.txt ]] && [[ ${log_exists} != 1 ]]; then
                rm log.txt
            fi
        fi
    }
else
    export EDITOR='nano'
fi


# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
if [[ -f "${ZDOTDIR}/.p10k.zsh" ]]; then
    source "${ZDOTDIR}/.p10k.zsh"
elif [[ -f "/etc/zsh/p10k.zsh" ]]; then
    source "/etc/zsh/p10k.zsh"
fi

# WSL tricks
if [[ "$(uname -r)" == *microsoft-standard* ]]; then
     if [[ $(service ssh status) == *"is not running"* ]]; then
           sudo service ssh --full-restart > /dev/null
     fi
fi

# iTerm2 integration
if [[ -e "${HOME}/.local/share/iterm2/integration/shell_integration/zsh" ]] && which hostname &>/dev/null; then
    source "${HOME}/.local/share/iterm2/integration/shell_integration/zsh"
    iterm2_print_user_vars() {
        it2git
    }
fi

# macOS wifi utility
if [[ -f "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport" ]]; then
    alias airport="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
fi

# JetBrains Toolbox
if [[ -d "${HOME}/Library/Application Support/JetBrains/Toolbox/scripts" ]]; then
    export PATH="${PATH}:${HOME}/Library/Application Support/JetBrains/Toolbox/scripts"
fi

export FZFZ_RECENT_DIRS_TOOL="fasd"