-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.zshrc
More file actions
195 lines (173 loc) · 5.29 KB
/
.zshrc
File metadata and controls
195 lines (173 loc) · 5.29 KB
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
## Options
setopt correct
setopt extendedglob
setopt nocaseglob
setopt rcexpandparam
setopt nocheckjobs
setopt numericglobsort
setopt histignorealldups
setopt inc_append_history
setopt appendhistory
setopt autocd
unsetopt beep nomatch
## History
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.histfile
## Completion
FPATH=/opt/homebrew/share/zsh-completions:$FPATH
autoload -U compinit colors zcalc
compinit
colors
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' rehash true
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
zstyle ':completion:*' menu select
zmodload zsh/complist
_comp_options+=(globdots)
## Prompt
PS1="%B%{$fg[green]%}%n@%M:%{$fg[blue]%}%~%{$reset_color%}$%b "
## Environment
export XDG_CONFIG_HOME="$HOME/.config"
export EDITOR=/usr/local/bin/nvim
export PATH="$PATH:$HOME/.local/bin"
## Vi mode
bindkey -v
export KEYTIMEOUT=1
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -v '^?' backward-delete-char
# Change cursor shape for different vi modes
function zle-keymap-select {
if [[ ${KEYMAP} == vicmd ]] || [[ $1 = 'block' ]]; then
echo -ne '\e[1 q'
elif [[ ${KEYMAP} == main ]] || [[ ${KEYMAP} == viins ]] || [[ ${KEYMAP} = '' ]] || [[ $1 = 'beam' ]]; then
echo -ne '\e[5 q'
fi
}
zle -N zle-keymap-select
zle-line-init() {
zle -K viins
echo -ne "\e[5 q"
}
zle -N zle-line-init
echo -ne '\e[5 q'
preexec() { echo -ne '\e[5 q' ;}
# Edit line in vim with ctrl-e
autoload edit-command-line; zle -N edit-command-line
bindkey '^e' edit-command-line
## Man page colors
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'
## Terminal title (works with iTerm2/tmux)
function title {
emulate -L zsh
setopt prompt_subst
[[ "$EMACS" == *term* ]] && return
: ${2=$1}
case "$TERM" in
xterm*|putty*|rxvt*|konsole*|ansi|mlterm*|alacritty|st*)
print -Pn "\e]2;${2:q}\a"
print -Pn "\e]1;${1:q}\a"
;;
screen*|tmux*)
print -Pn "\ek${1:q}\e\\"
;;
esac
}
ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<"
ZSH_THEME_TERM_TITLE_IDLE="%n@%m:%~"
function mzc_termsupport_precmd {
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
}
function mzc_termsupport_preexec {
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
emulate -L zsh
local -a cmdargs
cmdargs=("${(z)2}")
if [[ "${cmdargs[1]}" = fg ]]; then
local job_id jobspec="${cmdargs[2]#%}"
case "$jobspec" in
<->) job_id=${jobspec} ;;
""|%|+) job_id=${(k)jobstates[(r)*:+:*]} ;;
-) job_id=${(k)jobstates[(r)*:-:*]} ;;
[?]*) job_id=${(k)jobtexts[(r)*${(Q)jobspec}*]} ;;
*) job_id=${(k)jobtexts[(r)${(Q)jobspec}*]} ;;
esac
if [[ -n "${jobtexts[$job_id]}" ]]; then
1="${jobtexts[$job_id]}"
2="${jobtexts[$job_id]}"
fi
fi
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'
}
autoload -U add-zsh-hook
add-zsh-hook precmd mzc_termsupport_precmd
add-zsh-hook preexec mzc_termsupport_preexec
## FZF
export FZF_CTRL_T_COMMAND='fd --hidden --exclude .git'
source <(fzf --zsh)
## Archive extraction
extract() {
if [ -f "$1" ]; then
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*.tar.xz) tar xf "$1" ;;
*.tar.zst) unzstd "$1" ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
## Load aliases if existent
[ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc"
## Plugins (Homebrew)
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh 2>/dev/null
bindkey '^ ' autosuggest-execute
source /opt/homebrew/opt/zsh-syntax-highlighting/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null
## Bloomberg dev environment
. "$HOME/.local/bin/env"
source ~/.lcldevrc
## VPN proxy toggle
vpn-on() {
touch "$HOME/.vpn-proxy-enabled"
export HTTP_PROXY="http://proxy.bloomberg.com:81"
export HTTPS_PROXY="http://proxy.bloomberg.com:81"
export http_proxy="http://proxy.bloomberg.com:81"
export https_proxy="http://proxy.bloomberg.com:81"
export SSL_CERT_FILE="$HOME/.ssl/corporate-certs.pem"
export REQUESTS_CA_BUNDLE="$HOME/.ssl/corporate-certs.pem"
git config --global http.proxy http://proxy.bloomberg.com:81
git config --global https.proxy http://proxy.bloomberg.com:81
echo "VPN proxy enabled"
}
vpn-off() {
rm -f "$HOME/.vpn-proxy-enabled"
unset HTTP_PROXY HTTPS_PROXY http_proxy https_proxy SSL_CERT_FILE REQUESTS_CA_BUNDLE
git config --global --unset http.proxy
git config --global --unset https.proxy
echo "VPN proxy disabled"
}