-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzshrc
More file actions
157 lines (135 loc) · 5.31 KB
/
zshrc
File metadata and controls
157 lines (135 loc) · 5.31 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
# Used for setting user's interactive shell configuration and executing
# commands. Will be read when starting as an interactive shell.
#
# Completion
zmodload zsh/complist
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' rehash true
zstyle ':completion:*:default' list-prompt '%S%M matches%s' # Scroll long matches
zstyle ':completion:*' completer _complete _match _approximate # Order of completers to try
zstyle ':completion:*:match:*' original only # No wildcard matching
# allow one error for every three characters typed in approximate completer
zstyle -e ':completion:*:approximate:*' max-errors 'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )'
#
# Prompt
autoload -Uz promptinit
promptinit
# Prepare version control prompt
setopt prompt_subst
setopt transient_rprompt
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
parse_git_stash () {
[[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo -e '\U1F95E '
}
# vcs prompt
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' unstagedstr ' *'
zstyle ':vcs_info:*' stagedstr ' +'
zstyle ':vcs_info:*' formats '%F{magenta}[%F{green}%b%F{red}%u%c%F{magenta}]%f '
zstyle ':vcs_info:*' actionformats '%F{magenta}[%F{green}%b%F{yellow}|%F{red}%a%u%c%F{magenta}]%f '
precmd () { vcs_info }
PROMPT='%n@%m %F{yellow}%c ${vcs_info_msg_0_}$(parse_git_stash)%f%% '
RPROMPT='%(?..[%B%F{red}%?%f%b])'
#
# Environment, aliases, and functions
bindkey -e # Use Emacs key bindings in terminal, C-e, C-a, etc
# Enable 'ctrl-x-e' to edit command line; same as typing 'fc'
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^x^e' edit-command-line
export EDITOR="nvim"
export SUDO_EDITOR="nvim"
export CSCOPE_EDITOR="nvim"
export TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S'
alias dh='dirs -v'
alias gpg=gpg2
alias grep='egrep --color --ignore-case'
alias ll='ls --all --human-readable --group-directories-first -l'
alias ls='ls --color=auto'
open() {
command xdg-open $1
}
# Colored man pages
man() {
LESS_TERMCAP_mb=$'\e[1;31m' \
LESS_TERMCAP_md=$'\e[1;38;5;74m' \
LESS_TERMCAP_me=$'\e[0m' \
LESS_TERMCAP_se=$'\e[0m' \
LESS_TERMCAP_so=$'\e[38;5;246m' \
LESS_TERMCAP_ue=$'\e[0m' \
LESS_TERMCAP_us=$'\e[4;38;5;146m' \
GROFF_NO_SGR=yes \
command man "$@"
}
#
# Options
setopt auto_cd # Change directory by typing a directory name on its own
setopt correct # Automatically correct command names
setopt no_hup # Don't kill background jobs when exiting
setopt no_beep # I said no beeping
setopt no_clobber # Prevents redirected output from overwriting existing files
setopt clobber_empty # ... but do allow overwriting empty files
setopt no_hash_dirs # When a command is hashed do not hash the directory containing it
#
# History
HISTSIZE=1000
SAVEHIST=$HISTSIZE
HISTFILE="$HOME"/.history
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt histverify # Turn on verbose history substitution
setopt share_history # Prevents race conditions saving to history file
# Map arrow keys to history
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-beginning-search
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-beginning-search
#
# Directory stacks
DIRSTACKSIZE='20'
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushd_minus
setopt pushd_silent
setopt pushd_to_home
#
# ZLE
typeset -g -A key
key[Home]="${terminfo[khome]}"
key[End]="${terminfo[kend]}"
key[Insert]="${terminfo[kich1]}"
key[Backspace]="${terminfo[kbs]}"
key[Delete]="${terminfo[kdch1]}"
key[Up]="${terminfo[kcuu1]}"
key[Down]="${terminfo[kcud1]}"
key[Left]="${terminfo[kcub1]}"
key[Right]="${terminfo[kcuf1]}"
key[PageUp]="${terminfo[kpp]}"
key[PageDown]="${terminfo[knp]}"
key[Shift-Tab]="${terminfo[kcbt]}"
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode
[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char
[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history
[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history
[[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char
[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history
[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history
[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete
# Finally, make sure the terminal is in application mode, when zle is
# active. Only then are the values from $terminfo valid.
if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then
autoload -Uz add-zle-hook-widget
function zle_application_mode_start { echoti smkx }
function zle_application_mode_stop { echoti rmkx }
add-zle-hook-widget -Uz zle-line-init zle_application_mode_start
add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop
fi