-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
120 lines (97 loc) · 3.12 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
# Source environment variables
[ -f "$HOME/.config/exportrc" ] && source "$HOME/.config/exportrc"
# Colors and prompt
autoload -U colors && colors
[ -n "$SSH_CLIENT" ] && PS1_HOSTNAME="@$(hostname)"
PS1="%F{blue}λ %1~$PS1_HOSTNAME %f"
# History
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=~/.cache/zsh_history
# Share history between terminal sessions
setopt inc_append_history
setopt share_history
# Don't add lines starting with space to history
setopt histignorespace
# Autocompletion
autoload -U compinit
zstyle ':completion:*' menu select
zmodload zsh/complist
compinit -d "${XDG_CACHE_HOME:-$HOME/.cache}/zcompdump"
_comp_options+=(globdots)
# Quote pasted URLs automatically
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
# Make lowercase letters match both lowercase and uppercase letters, but only if no exact matches are found.
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}'
# vi mode
bindkey -v
export KEYTIMEOUT=1
# Fix common keys
bindkey "^?" backward-delete-char # Otherwise backspace only deletes up to where insert mode was last entered
bindkey "^[[1~" beginning-of-line
bindkey "^[[3~" delete-char
bindkey "^[[4~" end-of-line
# Search history using Up and Down keys
autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[[A" history-beginning-search-backward-end
bindkey "^[[B" history-beginning-search-forward-end
# Use vim keys in tab complete menu:
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
# Change cursor shape for different vi modes.
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() {
echo -ne "\e[5 q"
}
zle -N zle-line-init
# Load the zmv function
autoload -Uz zmv
alias mmv='noglob zmv -W'
# p shortcut
accept-line() {
if [[ $BUFFER = p\ * ]]; then
python3 ~/.local/lib/p_wrapper.py "${BUFFER#p }"
fi
zle .accept-line
}
zle -N accept-line
alias p='#'
# Edit line in vim with ctrl-e:
autoload edit-command-line; zle -N edit-command-line
bindkey '^e' edit-command-line
# Clear the screen using C-x
bindkey '^x' clear-screen
# Swap last two characters using C-t
bindkey '^t' gosmacs-transpose-chars
# Allow C-q and C-s keys
# C-q is bound to vi-quoted-insert by default
stty -ixon
# Comment/uncomment using C-s
bindkey '^s' vi-pound-insert
# Keep trailing slashes on commands
setopt no_auto_remove_slash
# Allow comments in repl
setopt interactive_comments
# Load other configuration files
[ -f "$HOME/.config/aliasrc" ] && source "$HOME/.config/aliasrc"
[ -f "$HOME/.config/machinerc" ] && source "$HOME/.config/machinerc"
# Load fasd shortcuts
command -v fasd > /dev/null && eval "$(fasd --init auto)"