-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
224 lines (194 loc) · 6.72 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
216
217
218
219
220
221
222
223
export VISUAL=/usr/bin/nvim
export EDITOR="$VISUAL"
export PATH="${HOME}/.local/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
export PATH="${HOME}/bin:$PATH"
export PATH="$(yarn global bin):$PATH"
export PATH="$HOME/gems/bin:$PATH"
export GEM_HOME="$HOME/gems"
source ~/.zshrc_private
if [ -f ~/.aliases ]; then
. ~/.aliases
fi
bindkey -v # vi mode
# Prompt
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWSTASHSTATE=1
export GIT_PS1_SHOWUPSTREAM="auto"
setopt PROMPT_SUBST
export PS1='%F{2}%n@%M%f:%F{141}%~%f$(__git_ps1 " (%s)")\$ '
# Case-insensitive completion
autoload -U compinit && compinit
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
# Enable searching through history
bindkey '^R' history-incremental-pattern-search-backward
setopt AUTOCD # Allow changing directories without `cd`
# History
HISTFILE=~/.zsh_history
HISTSIZE=100000
SAVEHIST=100000
setopt APPEND_HISTORY # Do not overwrite history
setopt EXTENDED_HISTORY # Also record time and duration of commands
setopt SHARE_HISTORY # Share history between multiple shells
setopt HIST_EXPIRE_DUPS_FIRST # Clear duplicates when trimming internal hist
setopt HIST_FIND_NO_DUPS # Do not display duplicates during searches
setopt HIST_IGNORE_DUPS # Ignore consecutive duplicates
setopt HIST_IGNORE_ALL_DUPS # Remember only one unique copy of the command
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks
setopt HIST_SAVE_NO_DUPS # Omit older commands in favor of newer ones
setopt HIST_IGNORE_SPACE # Prevent commands with leading space from history
# View colored man pages
export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'
# curl wttr.in
w () {
(IFS=+; curl wttr.in/"$*";);
}
# scrot
scr () {
scrot -d 5 '%Y-%m-%d-%H%M%S_$wx$h_scrot.png' -e 'mv $f ~/Downloads'
}
# Countdown (Usage: cdown 30)
cdown () {
n=$1
while [[ $((--n)) > 0 ]]
do
echo "$n" && sleep 1
done
}
command_not_found_handler() {
cowsay "lol, $1"
}
# <C-x><C-e> to fix a command in a text editor
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^x^e' edit-command-line
# https://github.com/zsh-users/zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
# nnn
export NNN_BMS='p:~/main/src/;d:~/main/docs/;D:~/Downloads/'
export NNN_TRASH=2
export NNN_COLORS="2136"
# fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Setting fd as the default source for fzf
export FZF_DEFAULT_COMMAND='fd -t f -L -H -E .git'
# To apply the command to CTRL-T as well
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
# Dracula color scheme
export FZF_DEFAULT_OPTS=$FZF_DEFAULT_OPTS'
--color=dark
--color=fg:-1,bg:-1,hl:#5fff87,fg+:-1,bg+:-1,hl+:#ffaf5f
--color=info:#af87ff,prompt:#5fff87,pointer:#ff87d7,marker:#ff87d7,spinner:#ff87d7
'
export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'"
export FZF_ALT_C_COMMAND="fd -t d"
export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'"
# export FZF_TMUX=1
# nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Automatically call nvm use (https://github.com/nvm-sh/nvm#automatically-call-nvm-use)
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
# Extract compressed files
extract() {
setopt localoptions noautopushd
if (( $# == 0 )); then
cat >&2 <<'EOF'
Usage: extract [-option] [file ...]
Options:
-r, --remove Remove archive after unpacking.
EOF
fi
local remove_archive=1
if [[ "$1" == "-r" ]] || [[ "$1" == "--remove" ]]; then
remove_archive=0
shift
fi
local pwd="$PWD"
while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then
echo "extract: '$1' is not a valid file" >&2
shift
continue
fi
local success=0
local extract_dir="${1:t:r}"
local file="$1" full_path="${1:A}"
case "${file:l}" in
(*.tar.gz|*.tgz) (( $+commands[pigz] )) && { pigz -dc "$file" | tar xv } || tar zxvf "$file" ;;
(*.tar.bz2|*.tbz|*.tbz2) tar xvjf "$file" ;;
(*.tar.xz|*.txz)
tar --xz --help &> /dev/null \
&& tar --xz -xvf "$file" \
|| xzcat "$file" | tar xvf - ;;
(*.tar.zma|*.tlz)
tar --lzma --help &> /dev/null \
&& tar --lzma -xvf "$file" \
|| lzcat "$file" | tar xvf - ;;
(*.tar.zst|*.tzst)
tar --zstd --help &> /dev/null \
&& tar --zstd -xvf "$file" \
|| zstdcat "$file" | tar xvf - ;;
(*.tar) tar xvf "$file" ;;
(*.tar.lz) (( $+commands[lzip] )) && tar xvf "$file" ;;
(*.tar.lz4) lz4 -c -d "$file" | tar xvf - ;;
(*.tar.lrz) (( $+commands[lrzuntar] )) && lrzuntar "$file" ;;
(*.gz) (( $+commands[pigz] )) && pigz -dk "$file" || gunzip -k "$file" ;;
(*.bz2) bunzip2 "$file" ;;
(*.xz) unxz "$file" ;;
(*.lrz) (( $+commands[lrunzip] )) && lrunzip "$file" ;;
(*.lz4) lz4 -d "$file" ;;
(*.lzma) unlzma "$file" ;;
(*.z) uncompress "$file" ;;
(*.zip|*.war|*.jar|*.ear|*.sublime-package|*.ipa|*.ipsw|*.xpi|*.apk|*.aar|*.whl) unzip "$file" -d "$extract_dir" ;;
(*.rar) unrar x -ad "$file" ;;
(*.rpm)
command mkdir -p "$extract_dir" && builtin cd -q "$extract_dir" \
&& rpm2cpio "$full_path" | cpio --quiet -id ;;
(*.7z) 7za x "$file" ;;
(*.deb)
command mkdir -p "$extract_dir/control" "$extract_dir/data"
builtin cd -q "$extract_dir"; ar vx "$full_path" > /dev/null
builtin cd -q control; extract ../control.tar.*
builtin cd -q ../data; extract ../data.tar.*
builtin cd -q ..; command rm *.tar.* debian-binary ;;
(*.zst) unzstd "$file" ;;
(*.cab) cabextract -d "$extract_dir" "$file" ;;
(*.cpio) cpio -idmvF "$file" ;;
(*)
echo "extract: '$file' cannot be extracted" >&2
success=1 ;;
esac
(( success = success > 0 ? success : $? ))
(( success == 0 && remove_archive == 0 )) && rm "$full_path"
shift
# Go back to original working directory in case we ran cd previously
builtin cd -q "$pwd"
done
}