-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
165 lines (140 loc) · 4.44 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
ZSH_HOME="${ZDOTDIR:-$HOME}"
fpath=( "$ZSH_HOME/.zsh" "$ZSH_HOME/.zsh/zsh-completions/src" $fpath )
autoload -U compaudit compinit
compinit -d "${XDG_CONFIG_HOME:-$HOME/.config}/zcompdump"
## aliases
autoload -Uz run-help
unalias run-help &> /dev/null
alias help=run-help
alias ls='ls --color=auto'
alias lsa='ls -lah'
alias history='fc -l 1'
alias xclip="xclip -selection c"
alias open="xdg-open"
alias wee='WEECHAT_PASSPHRASE="$(pass personal/weechat)" weechat'
alias which-command='whence'
alias ta='exec tmux new -A -s 1'
# https://unix.stackexchange.com/questions/250690/how-to-configure-ctrlw-as-delete-word-in-zsh
WORDCHARS=''
## zsh options
setopt extended_glob
setopt long_list_jobs # TODO:?
setopt interactivecomments
bindkey -e
bindkey '^r' history-incremental-search-backward
bindkey ' ' magic-space # expand !! and alike
# this still doesn't catch some attacks, see:
# https://thejh.net/misc/website-terminal-copy-paste
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
## history
HISTFILE="$ZSH_HOME/.zsh_history"
HISTSIZE=10000
SAVEHIST=100000000
setopt extended_history
setopt hist_ignore_dups
setopt inc_append_history
setopt share_history
## completion
zmodload zsh/complist
bindkey -M menuselect '^o' accept-and-infer-next-history # TODO:
bindkey -M menuselect '^[[Z' reverse-menu-complete
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path "${XDG_CONFIG_HOME:-$HOME/.config}/zsh"
setopt complete_aliases
unsetopt menu_complete
zmodload zsh/terminfo
# Make sure that the terminal is in application mode when zle is active, since
# only then values from $terminfo are valid
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-line-init() {
echoti smkx
}
function zle-line-finish() {
echoti rmkx
}
zle -N zle-line-init
zle -N zle-line-finish
fi
autoload -U up-line-or-beginning-search
zle -N up-line-or-beginning-search
bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "${terminfo[kcud1]}" down-line-or-beginning-search
setopt PROMPT_SUBST
autoload -Uz promptinit
promptinit
prompt 'custom'
unset ZSH_HOME
## functions
function 256color_test {
( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;
for i in {0..256};
do
o=00$i;
echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;
done )
}
function title {
case "$TERM" in
cygwin|xterm*|putty*|rxvt*|ansi)
print -Pn "\e]1;$1:q\a"
;;
screen*)
print -Pn "\ek$1:q\e\\"
;;
*)
if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
echoti tsl
print -Pn "$1"
echoti fsl
fi
;;
esac
}
function refresh_tmux {
if [ -n "$TMUX" ]; then
eval $(tmux showenv -s SSH_CONNECTION)
eval $(tmux showenv -s SSH_CLIENT)
eval $(tmux showenv -s SSH_TTY)
eval $(tmux showenv -s SSH_AUTH_SOCK)
eval $(tmux showenv -s DISPLAY)
fi
}
function set_title_precmd {
title "%15<..<%~%<<" $ZSH_THEME_TERM_TITLE_IDLE
}
function set_title_preexec {
setopt extended_glob
# cmd name only, or if this is sudo or ssh, the next cmd
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
local LINE="${2:gs/%/%%}"
title '$CMD' '%100>...>$LINE%<<'
}
function refresh_preexec {
refresh_tmux
}
precmd_functions+=(set_title_precmd)
preexec_functions+=(set_title_preexec refresh_preexec)
# zshenv may not be attached to a tty, so we set this here instead
export GPG_TTY="$(tty)"
# if $SSH_AUTH_SOCK is not set or not pointing to a socket, use gpg-agent
if [ ! -S "$SSH_AUTH_SOCK" ] && type "gpgconf" > /dev/null; then
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
fi
fi
# Refresh gpg-agent tty in case user switches into an X session
gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1
## startup
update_dotfiles
if (( $+commands[archey3] )) ; then
archey3
fi