-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zshrc
264 lines (224 loc) · 8.09 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
#===============================================================================
#
# ~/.zshrc
# Written by Minoru ([email protected])
#
# zsh 4.3.17 (x86_64-unknown-linux-gnu)
#
#===============================================================================
#-------------------------------------------------------------------------------
#
# HISTORY
#
# History file
HISTFILE=~/.zhistory
# The number of lines the shell will keep within one session
HISTSIZE=10240
# The number of lines of history will be saved
SAVEHIST=8192
# All running zsh sessions will have exactly the same history
# Don't worry - '!' command and so will work only with current session's history
setopt SHARE_HISTORY
# Remove all duplicates of current command from history, add current to end
setopt HIST_IGNORE_ALL_DUPS
# Don't save any commands beginning with space
setopt HIST_IGNORE_SPACE
# Don't save 'history' and 'fc' commands
setopt HIST_NO_STORE
# Enable extended globs to interpret things like rm ^(file|file2)
setopt EXTENDED_GLOB
# split parameters into words after substitution
# E.g.:
# D="one two three"
# With this option on (bash and dash behave like that):
# ./x $D # argv == ["x", "one", "two", "three"]
# Without this option (the default):
# ./x $D # argv == ["x", "one two three"]
# See https://bnw.im/p/EEIAKW (Russian!) for details on this
setopt SH_WORD_SPLIT
#-------------------------------------------------------------------------------
#
# PROMPT
#
# Load and initialize colors - we will use it soon
autoload colors && colors
# Prompt on the left is % if regular user or # if root
PROMPT="%{$fg[green]%}%# %{$reset_color%}"
# if connected via ssh, make prompt red
[[ -n ${SSH_CONNECTION} ]] && PROMPT="%{$fg[red]%}$HOST%# %{$reset_color%}"
# Prompt on the right is current directory (green font)
RPROMPT="%{$fg[green]%}%~%{$reset_color%}"
#-------------------------------------------------------------------------------
#
# ALIASES
#
# NOTE: if you don't want an alias to be used (for example, you went just 'du',
# but alias is 'du -h') you have three options:
# - use full path to binaries (continuing example above, it will look like
# '/bin/du')
# - use 'noglob' before command name (e.g., 'noglob du')
# - use backslash before command name (e.g., '\du')
# Regular aliases
alias ls="ls -F --color"
alias l="ls"
alias ll="ls -l"
alias la="ls -a"
alias sl="ls"
alias e="vim"
alias ta="tmux attach -t"
alias ncal="ncal -M" # weeks start at Monday
alias free="free -m"
alias grep="grep --colour"
alias bzip2='bzip2 -vv --best'
alias bunzip2='bunzip2 -vv'
alias gzip='gzip --best -v'
alias gunzip='gunzip -v'
alias less='less --RAW-CONTROL-CHARS --quit-if-one-screen --no-init'
alias netstat='netstat --numeric --program'
alias pqiv='pqiv -f -i -n'
alias mutt='PATH="/usr/lib/mutt:$PATH" mutt'
# Some nocorrect aliases (needed only if CORRECT is set)
alias df='nocorrect df -h'
alias du='nocorrect du -sh'
alias mv='nocorrect mv -i'
alias cp='nocorrect cp -i'
alias rm='nocorrect rm -i'
alias vim='nocorrect vim'
alias mc='nocorrect mc'
alias mkdir='nocorrect mkdir -p'
alias ip='nocorrect ip -h'
# You need run-help module to be loaded to have 'run-help' command
# See MISCELLANEOUS section below
alias help="run-help"
# Some more complicated but still useful aliases
alias rtorrent='tmux a -t "=rtorrent" || tmux new -s rtorrent "echo \"\033]0;rtorrent\a\" && rtorrent" \; set status off'
# monitor-activity is unset in order to work around a bug in Tmux 2.2:
# https://github.com/tmux/tmux/issues/403
alias mcabber='tmux a -t "=mcabber" || tmux new -s mcabber "echo \"\033]0;mcabber\a\" && mcabber" \; set status off \; set monitor-activity off'
alias irssi='tmux a -t "=irssi" || tmux new -s irssi "stty start \"\" stop \"\" && echo \"\033]0;irssi\a\" && irssi" \; set status off \; set monitor-activity off'
alias ocaml='rlwrap ocaml'
alias news='tmux a -t "=news" || tmux new -s news "echo \"\033]0;news\a\" && newsboat 2>/dev/null" \; set status off'
alias find_original='git annex find | xargs -I "{}" -- find -L ~/torrents/downloads -samefile {}'
alias ip='ip -color=auto'
if [ "$TERM" = "linux" ]; then
alias mplayer='mplayer -vo fbdev2'
alias startx='rm -f ~/.xsession-errors; setsid startx; while [ "`jobs | wc -l`" -ne "0" ]; do fg ; done; exit'
fi
# Suffix aliases for easier files processing
# PDF
alias -s pdf=zathura
# FB 2.1
alias -s fb2=fbless
alias -s fb2.bz2=fbless
# DejaVu
alias -s djvu=zathura
alias -s djv=zathura
# Global aliases
alias -g L="| less"
alias -g H="| head"
alias -g T="| tail"
alias -g G="| grep"
#-------------------------------------------------------------------------------
#
# FUNCTIONS
#
# This code will change terminal emulator's title
# As far as this action makes sense only in X terminal (and screen, but I don't
# use it), case used for checking are we in X terminal or where
# NOTE: if we're in the tty, $TERM will be "linux"
[[ -n "${SSH_CONNECTION}" ]] && titleHost="[$HOST] "
case $TERM in
xterm* | rxvt* | screen*)
# Precmd is called just before the prompt is printed
precmd() {
title="${titleHost}"
if [ -n "$TMUX" ]; then
title="${title}(`tmux display-message -p '#S'`) "
fi
title="${title}zsh"
print -Pn "\033]0;${title}\a"
}
# Preexec is called just before any command line is executed
# $1 is the command being executad
# sed used to cut off parameters of command
preexec() {
title="${titleHost}"
if [ -n "$TMUX" ]; then
title="${title}(`tmux display-message -p '#S'`) "
fi
title="${title}`echo $1 | head -n1 | sed -r 's/^((sudo |torify )?[^[:space:]]+).*/\1/'`"
print -Pn "\033]0;${title}\a"
}
# There are postexec too, but I don't need it as far as I configured precmd
;;
esac
function mcd() {
# Create directory and cd to it
mkdir -p "$1" && cd "$1"
}
function lcd() {
# cd to directory and do ls
cd "$1" && ls
}
function t() {
task $* && (clear; task)
}
#-------------------------------------------------------------------------------
#
# MISCELLANEOUS
#
# Don't beep even if zsh don't like something
setopt NO_BEEP
# Change directory even if user forgot to put 'cd' command in front, but entered
# path is valid
setopt AUTO_CD
# If possible, correct commands
setopt CORRECT
# Use colors in auto-completion
eval `dircolors`
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# Making things like "{1-3}" and "{a-d}" working (it expands to "1 2 3" and "a b
# c d")
setopt BRACECCL
# Send CONT signal automatically when disowning jobs
setopt AUTO_CONTINUE
# All files created by zsh (it happens when you use redirection of command's
# output to non-existent file) will have ug+rwX,o-rwx (or 750 for directories
# and 640 for files) perrmissions
umask 0027
# Load help system, which can show parts of man pages where specified command
# described. Also, add help="run-help" alias (see above in ALIASES section)
autoload run-help
# key bindings
# exporting EDITOR=vim makes ZSH switch into Vi mode; I don't like that
bindkey -e
# needed when connected by ssh, don't hurt if you're connected locally
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
bindkey "\e[3~" delete-char
#bindkey "\e[2~" quoted-insert
bindkey "\e[5C" forward-word
bindkey "\e[5D" backward-word
bindkey "\e\e[C" forward-word
# for urxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
#-------------------------------------------------------------------------------
#
# COMPLETION
#
# case-insensitive,partial-word and then substring completion
# http://hintsforums.macworld.com/archive/index.php/t-6493.html
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' #'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
# Sets autocompletion
autoload -Uz compinit && compinit
#-------------------------------------------------------------------------------
#
# LOCAL SETTINGS
#
if [ -n "$HOST" -a -f "$HOME/.zshrc.$HOST" ]; then
source "$HOME/.zshrc.$HOST"
fi
[ -f "/home/minoru/.ghcup/env" ] && source "/home/minoru/.ghcup/env" # ghcup-env