-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
215 lines (191 loc) · 7.34 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
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
# 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
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
fpath+=($(brew --prefix)/share/zsh/site-functions)
# Load homebrew shell variables
eval "$(/opt/homebrew/bin/brew shellenv)"
# plugin configs
source <(fzf --zsh)
eval "$(zoxide init zsh)"
eval "$(atuin init zsh --disable-up-arrow)"
[ -x "$(command -v bat)" ] && alias cat='bat'
[ -x "$(command -v bat)" ] && alias more='bat'
[ -x "$(command -v bat)" ] && alias less='bat'
[ -x "$(command -v eza)" ] && alias ls='eza --icons=always'
[ -x "$(command -v nvim)" ] && alias vim='nvim' vimdiff='nvim -d'
[ -x "$(command -v kubectl)" ] && alias k='kubectl'
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
### End of Zinit's installer chunk
# https://zdharma-continuum.github.io/zinit/wiki/Example-Minimal-Setup/
zinit ice depth=1; zinit light romkatv/powerlevel10k
zinit wait lucid light-mode for \
atinit"zicompinit; zicdreplay" \
zdharma-continuum/fast-syntax-highlighting \
atload"_zsh_autosuggest_start; \
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#61afef,standout' \
bindkey '^[[Z' autosuggest-accept" \
zsh-users/zsh-autosuggestions \
blockf atpull'zinit creinstall -q .' \
zsh-users/zsh-completions
# general
alias dots='/usr/bin/git --git-dir=$HOME/src/dots/ --work-tree=$HOME'
alias g='git'
alias ga='git add'
alias gaf='git ls-files -m -o --exclude-standard | fzf --print0 -m | xargs -0 -t -o git add'
alias gap='git add -AN && git add -p'
alias gau='git add -u'
alias gb='git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format="%(refname:short)"'
alias gcb='git checkout -b'
alias gcd='cd $(git rev-parse --show-toplevel)'
alias gcm='git commit -m'
gsw() {
git branch | grep -v '^[*+]' | awk '{print $1}' | fzf -0 --preview 'git show --color=always {-1}' --preview-window=down:80%:wrap | sed 's/remotes\/origin\///g' | xargs -r git checkout
}
alias gcp='git checkout -p'
alias gcv='git commit -v'
alias gd='git diff'
alias gdc='git diff --cached'
alias gdn='git diff --name-only'
alias gdom='git diff origin/main...'
alias gds='git diff --staged'
alias gdst='git diff --stat'
alias gdu='git diff @{upstream}'
alias gf='git fetch'
alias gfom='git fetch origin main'
alias gg='gau; git cane'
alias ggg='gau; git cane; gpfwl'
alias girl='git reflog -n30'
alias gj='git status'
alias gja='git status'
alias gjuno='git status -uno'
alias gl='git log --pretty=format:"%C(yellow)%h %Cred%ad %Cblue%<(20)%an%Cgreen%d %Creset%s" --date=format:"%Y-%m-%d %H:%M:%S" -n 15 --color=always'
alias gl='git log --pretty=format:"%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s" --date=format:"%Y-%m-%d %H:%M:%S" -n 15'
alias gll='git log --oneline --stat -n 5'
alias gly='git log --pretty=format:"%C(yellow)%h %Cred%ad %Cblue%<(20)%an%Cgreen%d %Creset%s" --date=format:"%Y-%m-%d %H:%M:%S" -n 15 | yank'
alias gma='git merge --abort'
alias gmc='git merge --continue'
alias gmom='git merge origin/main'
alias gp='git pull && clear'
alias gpfwl='git push --force-with-lease'
alias gpfwln='git push --force-with-lease --no-verify'
alias gpomr='function _gpomr() { git pull origin main --rebase="${1:-true}" -Xignore-whitespace; }; _gpomr'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias gret='git rebase --edit-todo'
alias gri='f() { git rebase -i HEAD~${1:-7}; }; f'
alias griom='git rebase -i origin/main'
alias gs-='git switch -'
alias gs='git switch'
alias gsc='git switch -c'
alias gsh='git show'
alias gsm='git switch main'
alias gto='git open'
alias mom='git fetch && git merge origin/main'
alias pp='gpomr && gpfwl'
alias rom='git fetch && git rebase -i origin/main'
alias targets='make -qp | awk -F'\'':'\'' '\''/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}'\'' | sort -u'
alias pacman='yay'
alias ta='tmux attach'
path+=$HOME/.bin:.
path+=/opt/homebrew/bin/
# history
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.zsh_history
setopt appendhistory
setopt histignoredups
setopt incappendhistory
setopt sharehistory
setopt interactive_comments
# color
autoload -U colors && colors
# basic auto/tab complete:
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' # case insensitive match
zstyle ':completion:*:make:*:targets' call-command true
zstyle ':completion:*:*:make:*' tag-order 'targets'
# plugins
zinit ice wait lucid
zinit light paulirish/git-open
zinit ice wait lucid
zinit light Aloxaf/fzf-tab
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza -1 --color=always $realpath'
zstyle ':fzf-tab:complete:z:*' fzf-preview 'eza -1 --color=always $realpath'
ulimit -n 99999999
# functions
# https://gist.github.com/cschindlbeck/db0ac894a46aac42861e96437d8ed763#file-fzffuns-L13
kil() {
local selection
selection=$(ps -e -o pid,comm | fzf)
local pid=$(echo "$selection" | awk '{print $1}')
local pname=$(echo "$selection" | awk '{print $2}')
if [ "$pid" != "" ]; then
kill -9 "$pid" > /dev/null 2>&1 && echo "Process $pname (PID $pid) has been successfully killed."
fi
}
cd() {
if [ $# -eq 0 ]; then
# no arguments
z
elif [ $# -eq 1 ]; then
if [ -f "$1" ]; then
# argument is a file
z "$(dirname $1)"
else
# argument is not a file, assume it's a directory or handle as needed
z "$1"
fi
else
# zoxide best match
z "$@"
fi
}
# https://news.ycombinator.com/item?id=9869613
function up {
if [[ "$#" < 1 ]] ; then
cd ..
else
CDSTR=""
for i in {1..$1} ; do
CDSTR="../$CDSTR"
done
cd $CDSTR
fi
}
# zle
# https://nuclearsquid.com/writings/edit-long-commands/
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# copy current command
cmd_to_clip () { echo $BUFFER | tr -d '\n' | pbcopy }
zle -N cmd_to_clip
bindkey '^y' cmd_to_clip
# variables
export BAT_THEME="Catppuccin Macchiato"
export FZF_DEFAULT_OPTS="--layout=reverse"
export EDITOR='nvim -u ~/.config/nvim/init.lua'
export VISUAL='nvim -u ~/.config/nvim/init.lua'
export HOMEBREW_AUTO_UPDATE_SECS="86400"
export HOMEBREW_BIN=/opt/homebrew/bin
export HOMEBREW_CASK_OPTS=--require-sha
export HOMEBREW_DIR=/opt/homebrew
export HOMEBREW_NO_INSECURE_REDIRECT=1
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#61afef,standout'