-
Notifications
You must be signed in to change notification settings - Fork 10
/
.zshrc
287 lines (239 loc) · 7.37 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#------------------------------
# History stuff
#------------------------------
HISTFILE=~/.histfile
HISTSIZE=200000
SAVEHIST=50000
#------------------------------
# Variables
#------------------------------
# SLRN
export NNTPSERVER='news.gmane.org'
export EDITOR=nvim
export DE=gnome
export LANG=en_GB.UTF-8
export PATH=$PATH:/home/jelle/bin/
# Browser
export BROWSER=firefox
# I'm a cool kid now
alias vim=nvim
# my completions
fpath=("$HOME/.zcompletions" "$fpath[@]")
#------------------------------
# Keybindings
#------------------------------
bindkey -v
typeset -g -A key
bindkey '^[[3~' delete-char
# Up/Down line history arrow up/down
bindkey '^[[B' down-line-or-history
bindkey '^[[A' up-line-or-search
# Beginning of line also ctrl+e/a ctrl+up/down
bindkey "^E" end-of-line
bindkey "^A" beginning-of-line
bindkey "^[^?" backward-kill-word
# Ctrl+r history search
bindkey "^R" history-incremental-search-backward
# History search (usually up/down key)
bindkey '^P' up-line-or-search
bindkey '^N' down-line-or-search
bindkey "^[[1;5D" emacs-backward-word
bindkey "^[[1;5C" emacs-forward-word
#------------------------------
# History
#------------------------------
setopt extended_history
setopt inc_append_history
setopt share_history
setopt hist_ignore_dups
setopt hist_ignore_all_dups
setopt hist_expire_dups_first
setopt hist_save_no_dups
setopt hist_ignore_space
setopt hist_verify
#------------------------------
# Alias stuff
#------------------------------
alias cat="bat"
alias ls="ls --color -F"
alias grep="grep --color=always"
# cockpit
alias cpf='PYTHONPATH=src python3 -m cockpit.misc.print'
alias cpy='PYTHONPATH=src python3 -m cockpit.bridge'
# pacman
alias pacup='sudo pacman -Syu '
alias pacs='pacman -Ss'
alias pacins='sudo pacman -S'
alias pacr='sudo pacman -Rs'
alias pacq='pacman -Q'
alias pacu='sudo pacman -U'
# vim wiki
alias notes='cd ~/Notes && nvim -c VimwikiIndex'
alias diary='cd ~/Notes/diary/ && nvim -c VimwikiIndex -c VimwikiDiaryIndex'
alias vimwikis='vim -c VimwikiUISelect'
# moving in dirs
alias ..="cd .."
#-----------------------------
# Dircolors
#-----------------------------
eval $(dircolors -b $HOME/.dircolors)
#------------------------------
# Comp stuff
#------------------------------
zmodload zsh/complist
autoload -Uz compinit
compinit
zstyle :compinstall filename '${HOME}/.zshrc'
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:*:killall:*' menu yes select
zstyle ':completion:*:killall:*' force-list always
autoload -U incremental-complete-word predict-on
zle -N incremental-complete-word
zle -N predict-on
zle -N predict-off
bindkey '^X1' predict-on
bindkey '^X2' predict-off
#------------------------------
# Functions
#------------------------------
sprunge() {
if [ -z "$1" ]
then
curl -s -F 'sprunge=<-' http://sprunge.us
else
if [ -z "$2" ]
then
echo -n "$1:"
cat "$1" | "$0"
else
for i in "$@"
do
"$0" "$i"
done
fi
fi
}
# svn diff
svndiff() {
svn diff "${@}" | colordiff | less -R
}
_fetchpr() {
origin=${3:-origin}
ref=$1
branch=$2
program=${funcstack#_fetchpr};
if (( $# != 2 && $# != 3 )) then
echo usage:$program id branchname \[remote\];
return 1
fi
if git rev-parse --git-dir &> /dev/null; then
git fetch $origin $ref && git checkout $branch
else
echo 'error: not in git repo'
fi
}
# Checkout Github PR function
gitpr() {
github="pull/$1/head:$2"
_fetchpr $github $2 $3
}
# Checkout Bitbucket PR function
bitpr() {
bitbucket="refs/pull-requests/$1/from:$2"
_fetchpr $bitbucket $2 $3
}
# Checkout Gitlab MR function
gitmr() {
gitlab="merge-requests/$1/head:$2"
_fetchpr $gitlab $2 $3
}
cockpit-queue-status() {
curl -s http://webhook-cockpit.apps.ocp.cloud.ci.centos.org/inspect-queue
}
#------------------------------
# Window title
#------------------------------
case $TERM in
*xterm*|rxvt|rxvt-unicode|rxvt-256color|(dt|k|E)term)
precmd () { print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~]\a" }
preexec () { print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a" }
;;
screen)
precmd () {
[[ $a = zsh ]] && print -Pn "\ek$2\e\\" # show the path if no program is running
[[ $a != zsh ]] && print -Pn "\ek$a\e\\" # if a program is running show that
# Terminal title
if [[ -n $STY ]] ; then
[[ $a = zsh ]] && print -Pn "\e]2;$SHORTHOST:S\[$WINDOW\]:$2\a"
[[ $a != zsh ]] && print -Pn "\e]2;$SHORTHOST:S\[$WINDOW\]:${a//\%/\%\%}\a"
elif [[ -n $TMUX ]] ; then
# We're running in tmux, not screen
[[ $a = zsh ]] && print -Pn "\e]2;$SHORTHOST:$2\a"
[[ $a != zsh ]] && print -Pn "\e]2;$SHORTHOST:${a//\%/\%\%}\a"
fi
}
preexec () {
# print -Pn "\e]83;title \"$1\"\a"
# print -Pn "\e]0;$TERM - (%L) [%n@%M]%# [%~] ($1)\a"
}
;;
esac
#------------------------------
# Prompt
#------------------------------
setprompt () {
# load some modules
autoload -U zsh/terminfo # Used in the colour alias below
# Use colorized output, necessary for prompts and completions.
autoload -U colors && colors
setopt prompt_subst
# make some aliases for the colours: (coud use normal escap.seq's too)
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
eval PR_$color='%{$fg[${(L)color}]%}'
done
PR_NO_COLOR="%{$terminfo[sgr0]%}"
# Check the UID
if [[ $UID -ge 1000 ]]; then # normal user
eval PR_USER='${PR_GREEN}%n${PR_NO_COLOR}'
eval PR_USER_OP='${PR_GREEN}%#${PR_NO_COLOR}'
elif [[ $UID -eq 0 ]]; then # root
eval PR_USER='${PR_RED}%n${PR_NO_COLOR}'
eval PR_USER_OP='${PR_RED}%#${PR_NO_COLOR}'
fi
# Check if we are on SSH or not --{FIXME}-- always goes to |no SSH|
if [[ -f /run/.toolboxenv && -f /run/.containerenv ]]; then
local TOOLBOX_HOSTNAME=$(grep name /run/.containerenv | cut -d'"' -f 2)
eval PR_HOST='${PR_ORANGE}⬢\ ${TOOLBOX_HOSTNAME}${PR_NO_COLOR}'
elif [[ -z "$SSH_CLIENT" || -z "$SSH2_CLIENT" ]]; then
eval PR_HOST='${PR_GREEN}%M${PR_NO_COLOR}' # no SSH
else
eval PR_HOST='${PR_YELLOW}%M${PR_NO_COLOR}' #SSH
fi
# set the prompt
PS1=$'${PR_CYAN}[${PR_USER}${PR_CYAN}@${PR_HOST}${PR_CYAN}][${PR_BLUE}%~${PR_CYAN}]${PR_USER_OP}'
PS2=$'%_>'
}
setprompt
#------------------------------
# gpg-agent
#------------------------------
# Start the gpg-agent if not already running
if ! pgrep -x -u "${USER}" gpg-agent >/dev/null 2>&1; then
gpg-connect-agent /bye >/dev/null 2>&1
fi
# Set SSH to use gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="/run/user/$UID/gnupg/S.gpg-agent.ssh"
fi
# Set GPG TTY
GPG_TTY=$(tty)
export GPG_TTY
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null
# setup zoxide
if command -v zoxide > /dev/null; then
eval "$(zoxide init --cmd j zsh)"
fi