-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
166 lines (142 loc) · 3.89 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
if [[ -f "/opt/homebrew/bin/brew" ]]; then
# If you're using macOS, you'll want this enabled
eval "$(/opt/homebrew/bin/brew shellenv)"
export SSL_CERT_FILE="/etc/ssl/cert.pem"
fi
# Set the directory we want to store zinit and plugins
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
# Function to check if a command can be executed
function command_exists() {
if command -v "$1" &> /dev/null; then
return 0
else
return 1
fi
}
# set proxy
function proxy () {
export {https,http}_proxy="http://127.0.0.1:7897"
export all_proxy="socks5://127.0.0.1:7897"
if command_exists "npm"; then
npm config set proxy http://127.0.0.1:7897
fi
export no_proxy="127.0.0.1,localhost,apple.com"
}
# init proxy
proxy
# Download Zinit, if it's not there yet
if [ ! -d "$ZINIT_HOME" ]; then
mkdir -p "$(dirname "$ZINIT_HOME")"
git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
# Source/Load zinit
source "${ZINIT_HOME}/zinit.zsh"
# Add in zsh plugins
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light trystan2k/zsh-tab-title
zinit light Aloxaf/fzf-tab
# Add in snippets
zinit snippet OMZP::git
zinit snippet OMZP::sudo
zinit snippet OMZP::archlinux
zinit snippet OMZP::aws
zinit snippet OMZP::kubectl
zinit snippet OMZP::kubectx
zinit snippet OMZP::command-not-found
# Load completions
autoload -Uz compinit && compinit
zinit cdreplay -q
# Keybindings
bindkey -e
bindkey '^p' history-search-backward
bindkey '^n' history-search-forward
bindkey '^[w' kill-region
# History
HISTSIZE=5000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
HISTDUP=erase
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
# Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'ls --color $realpath'
# env variable
export ZSH_TAB_TITLE_PREFIX=" "
export GOPATH="$HOME/go"
export CARGO_HOME="$HOME/.cargo"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share",
export PATH="$PATH:$GOPATH/bin"
export PATH="$PATH:$CARGO_HOME/bin"
if [[ "$(uname)" == "Linux" ]]; then
export PATH="$PATH:$HOME/.local/bin"
export PKG_CONFIG_PATH="/usr/lib64/pkgconfig"
export OPENSSL_DIR="/usr"
fi
export EDITOR="$(which nvim)"
export SHELL="$(which zsh)"
export OLLAMA_API_BASE="http://127.0.0.1:11434"
export NODE_OPTIONS="--no-warnings=ExperimentalWarning"
# Shell integrations
source <(starship init zsh)
source <(zoxide init zsh)
eval "$(fnm env)"
if command_exists "fzf"; then
source <(fzf --zsh)
fi
# Aliases
alias ls="ls --color"
alias vim="nvim"
alias vi="nvim"
alias c="clear"
alias e="nvim"
alias el="NVIM_APPNAME=nvim-lazy nvim"
alias gc-="git checkout -"
alias ys="yarn start"
alias python="python3"
alias pip="python3 -m pip"
alias xcopy="xclip -selection clipboard"
alias cat="bat"
alias find="fd"
function create_worktree() {
local target_dir=$1
local branch_name=$2
if [[ ! -d "$target_dir" ]]; then
mkdir -p "$target_dir"
fi
if ! git rev-parse --verify --quiet "refs/heads/$branch_name" >/dev/null 2>&1; then
git branch "$branch_name"
fi
git worktree add "$target_dir" "$branch_name"
}
# unset proxy
function unproxy() {
unset {https,http,all,no}_proxy
npm config delete proxy --global
}
function removeDuplicatedAppIcon () {
if [[ "$(uname)" != "Darwin" ]]; then
return
fi
defaults write com.apple.dock ResetLaunchPad -bool true;
killall Dock
}
function switch_ctrl_caps_lock() {
if [[ "$(uname)" != "Linux" ]]; then
return
fi
if [[ -f "$HOME/.xmodmap" ]] && command_exists "xmodmap"; then
xmodmap ~/.xmodmap
fi
}