-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
155 lines (140 loc) · 5.67 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
# Setup inspiration: https://www.youtube.com/watch?v=ud7YxC33Z3w
# ------------------------------------------------------------------------------
# Basic settings
# ------------------------------------------------------------------------------
bindkey -v
setopt IGNOREEOF # accidentally pressing Ctrl + d keeps closing the zsh session
if [ -d ".ssh" ]; then
ssh-add -l > /dev/null || ssh-add ~/.ssh/id_ed25519 # add ssh key to agent
fi
eval "$($(which brew) shellenv)" # set up homebrew
# ------------------------------------------------------------------------------
# Exports
# ------------------------------------------------------------------------------
export EDITOR="nvim"
export GPG_TTY=$(tty)
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
# Go
export GOPATH="$HOME/go"
export PATH="$PATH:$GOPATH/bin"
# Ruby
export PATH="$HOMEBREW_PREFIX/opt/ruby/bin:$PATH"
export LDFLAGS="-L$HOMEBREW_PREFIX/opt/ruby/lib"
export CPPFLAGS="-I$HOMEBREW_PREFIX/opt/ruby/include"
# Rust
export PATH="$HOME/.cargo/bin:$PATH"
# ------------------------------------------------------------------------------
# P10k settings (prompt)
# ------------------------------------------------------------------------------
# NOTE: (Auto-generated)
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# ------------------------------------------------------------------------------
# Better history
# ------------------------------------------------------------------------------
bindkey -M vicmd 'k' history-search-backward
bindkey -M vicmd 'j' history-search-forward
HISTSIZE=5000 # size of the history
HISTFILE=~/.zsh_history # path where history will be stored
SAVEHIST=$HISTSIZE # needs to be the same as HISTSIZE
HISTDUP=erase # erase any dupes inside the HISTFILE
setopt appendhistory # append any commands to the HISTFILE, rather than overwriting it
setopt sharehistory # share history across all zsh sessions
setopt hist_ignore_space # if there's a space prefix, don't save to history
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups
# ------------------------------------------------------------------------------
# Aliases
# ------------------------------------------------------------------------------
alias ls="ls --color" #! must come before any other ls commands
alias ".."="cd .."
alias "..."="cd ../.."
alias "...."="cd ../../.."
alias "....."="cd ../../../.."
alias "gp!"="git push --force-with-lease"
alias c="clear"
alias cg="cargo"
alias cgr="cargo run"
alias gac="git add --all && git commit"
alias gdhh="git diff HEAD^ HEAD"
alias glgo="git log --oneline"
alias got="go test ./..."
alias gor="go run ."
alias l="ls -alh"
alias ng="nvim ~/.gitconfig"
alias ni="nvim ~/.zshrc"
alias nv="nvim"
alias nz="nvim ~/.zshrc"
alias pn="pnpm"
alias sd="cd ~/dotfiles && stow --adopt --restow . && cd -"
alias sz="source ~/.zshrc"
alias t1="~/dotfiles/scripts/term1"
alias t2="~/dotfiles/scripts/term2"
alias t3="~/dotfiles/scripts/term3"
alias t4="~/dotfiles/scripts/term4"
alias tkser="tmux kill-server"
alias tmat="tmux a -t"
# ------------------------------------------------------------------------------
# Utility functions
# ------------------------------------------------------------------------------
# Automatically input "ls -al" after each "cd"
cd() {
builtin cd "$@" && ls -alh
}
# ------------------------------------------------------------------------------
# Plugins
# ------------------------------------------------------------------------------
set_up_plugin_manager() {
# Set the directory we want to store zinit and plugins
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
# Create the zinit home directory, if it's not there yet
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
# Download zinit, if it's not there yet
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
# Load zinit
source "${ZINIT_HOME}/zinit.zsh"
}
install_plugins() {
zinit snippet OMZP::git # Oh My Zsh git plugin
zinit snippet OMZP::autojump # Oh My Zsh autojump plugin
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light olets/zsh-abbr # auto expand abbreviations
zinit ice depth=1; zinit light romkatv/powerlevel10k
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
zinit light Aloxaf/fzf-tab # replace zsh's completion selection menu with fzf
}
set_up_completion() {
# Disable sort when completing `git checkout`
zstyle ':completion:*:git-checkout:*' sort false
# Set descriptions format to enable group support
# NOTE: don't use escape sequences here, fzf-tab will ignore them
zstyle ':completion:*:descriptions' format '[%d]'
# Set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# Force zsh not to show completion menu, which allows fzf-tab to capture the unambiguous prefix
zstyle ':completion:*' menu no
# Preview directory's content with eza when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
# Switch group using `<` and `>`
zstyle ':fzf-tab:*' switch-group '<' '>'
# Shell integrations
eval "$(fzf --zsh)"
# Load completions
autoload -U compinit && compinit
zinit cdreplay -q
}
set_up_plugins() {
set_up_plugin_manager
install_plugins
set_up_completion
}
set_up_plugins