-
Notifications
You must be signed in to change notification settings - Fork 1
/
.zshrc
331 lines (278 loc) · 10.6 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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# the config installation on clean system (from my last attempt):
# git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
# git clone https://github.com/robbyrussell/oh-my-zsh ~/.oh-my-zsh
# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting
# chsh -s $(which zsh)
#
# optionally: to migrate bash_history use command below. The grep is to skip
# timestamps in bash format (the command below does not retain them for
# simplicity)
# cat ~/.bash_history | grep -v -E "^#" | sed 's/^/: 0:0;/' > ~/.zsh_history
# Path to your oh-my-zsh installation.
export ZSH=~/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
export ZSH_THEME="mira"
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
export DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
export ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
export COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
export HIST_STAMPS="%d.%m.%y %T"
export HISTSIZE=100000
export HISTFILESIZE=$HISTSIZE
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
export plugins=(git themes)
source $ZSH/oh-my-zsh.sh
# User configuration
autoload -U select-word-style
select-word-style bash
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=12'
export ZSH_AUTOSUGGEST_STRATEGY=(history completion) # first history, then what tab would suggest
export ZSH_AUTOSUGGEST_USE_ASYNC=t
zstyle ':completion:*' matcher-list '' \
'm:{a-z\-}={A-Z\_}' \
'r:[^[:alpha:]]||[[:alpha:]]=** r:|=* m:{a-z\-}={A-Z\_}' \
'r:|?=** m:{a-z\-}={A-Z\_}'
# Note: by default zsh *deletes whole* line with this key
bindkey "^U" backward-kill-line
bindkey "^[l" down-case-word
#useful aliases
alias grep1="grep --exclude-dir=\".*\" --exclude=tags --exclude=TAGS"
alias ack='ack "--ignore-dir=match:^\." --ignore-dir=build --ignore-file=is:tags --ignore-file=is:TAGS --color-lineno=red --color-filename=blue -H'
alias dmesg="dmesg --color=always"
alias gdb="gdb -q"
alias ll="ls -l"
alias ghc="stack ghc -- "
alias ghci="stack ghci -- "
alias ghci512="stack ghci --ghci-options '+RTS -M512m -RTS'"
alias ghciMath="stack ghci --ghci-options '-ghci-script /home/constantine/.ghciMath'"
# alias ghciMath512="stack ghci --ghci-options '+RTS -M512m -RTS -ghci-script /home/constantine/.ghciMath'"
alias git-head='git checkout $(git log --branches -1 --pretty=format:"%D" | sed "s/.*, //g")'
# colorizing "cat"
alias ccat='pygmentize -g'
# You may need to manually set your language environment
export LANG=en_US.UTF-8
export EDITOR='vim'
setopt HIST_IGNORE_ALL_DUPS
setopt hist_reduce_blanks
setopt INC_APPEND_HISTORY # append history during the session, but do not load the file
unsetopt sharehistory # it's set elsewhere (perhaps oh-my-zsh?), disable it.
# completion for ninja command
fpath=(~/.zsh/ninja-completion.zsh $fpath)
## path to `ack` varies between systems, so acquire it explicitly
ack_binary=$(whereis -b ack | awk '{print $2}')
# sed analog in perl, called like "sed_perl pattern_from pattern_to [filenames]"
function sed_perl() {
local from=$1
local to=$2
shift 2
$ack_binary -l --print0 "$from" "$@" | xargs -r0 perl -Mutf8 -i -CS -pe "s α${from}α${to}αg"
}
alias sp=sed_perl
# deletes lines, called like "del_lines pattern [filenames]"
function del_lines() {
local pattern=$1
shift 1
$ack_binary -l --print0 "$pattern" "$@" | xargs -r0 perl -i -ne 'BEGIN { $re = shift } print if not m/$re/' ${pattern}
}
# Logs while a command is running. Usage example `log_with 'journalctl -f > 1' 'ping localhost'`.
function log_with() (
local log_cmd=$1
local exec_cmd=$2
sh -c "$log_cmd" &
local log_pid=$!
trap 'kill "$log_pid"' EXIT
eval "$exec_cmd"
)
# adds reviwed-by to n commits
function git_rb() {
# export arguments, otherwise they're not visible to inline shell executions
export who=$1
export mail=$2
export n=$3
git rebase HEAD~$n -x 'git commit --amend -m"$(git log --format=%B -n1)$(echo -e \\nReviewed-by: ${who} \<${mail}\>.)"'
}
# rebase-at <action> <comit-ids-and-co>
function rebase-at() {
local action=$1
shift 1
GIT_SEQUENCE_EDITOR="sed -i -E \"1s/\w+/$action/\"" git rebase -i "$@"
}
function cs() {
if [[ $# == 0 ]]; then
git add -u && git commit -sv
elif [[ $# == 1 ]]; then
git add "$1" && git commit -sv
else
echo "Wrong params number!"
fi
}
function c() {
if [[ $# == 0 ]]; then
git add -u && git commit -v
elif [[ $# == 1 ]]; then
git add "$1" && git commit -v
else
echo "Wrong params number!"
fi
}
function co_prev() {
git checkout HEAD^ "$@" && git reset
}
function newbranch() {
if [[ $# == 1 ]]; then
git checkout --no-track -b $1 upstream/master
elif [[ $# == 2 ]]; then
git checkout --no-track -b $1 $2
else
echo "Wrong params number!"
fi
}
# Define autocompletion for newbranch
_newbranch_comp() {
_arguments \
'1: :->branch' \
'2: :->source'
case $state in
branch)
# nothing
;;
source)
compadd $(git branch -r | awk '{print $1}')
;;
esac
}
compdef _newbranch_comp newbranch
function p() {
if [ -z $(git rev-parse --abbrev-ref --symbolic-full-name @{u}) ]; then
echo "INFO: setting the branch to track origin"
git push -u origin HEAD "$@"
else
git push "$@"
fi
}
function ct() (
cd "$(git rev-parse --show-toplevel)"
local git_status=$(git status -u no)
if [ -f .git/CHERRY_PICK_HEAD ]; then
git add -u && GIT_EDITOR=true git cherry-pick --continue
elif [[ "$git_status" == *"rebase in progress"* ]]; then
git add -u && GIT_EDITOR=true git rebase --continue
elif [ -d .git/rebase-apply ]; then
git add -u && GIT_EDITOR=true git am --continue
else
echo "No operation in progress that is suitable for continue"
return 1
fi
)
function ab() (
cd "$(git rev-parse --show-toplevel)"
local git_status=$(git status -u no)
if [ -f .git/CHERRY_PICK_HEAD ]; then
git cherry-pick --abort
elif [[ "$git_status" == *"rebase in progress"* ]]; then
git rebase --abort
elif [ -d .git/rebase-apply ]; then
git am --abort
else
echo "Conflict due to an unknown operation"
return 1
fi
# aborts have no hook where we could fix submodule commit, so do that here
git submodule update
)
# show the commit whose application triggered the conflict
function conflicted_commit() (
cd "$(git rev-parse --show-toplevel)"
git log -1 -p --stat $(awk 'END{print $2}' .git/rebase-merge/done)
)
# git-infix: find file in the repo containing the word
function fnfx () {
# `last_arg` is the infix, so separate it from the rest of args
last_arg="${@: -1}"
remaining_args="${@:1:$(($# - 1))}"
git ls-files ${remaining_args} ":/*$last_arg*"
}
# run interactive git-rebase over the commits of the current branch
function ri () {
target_branch=$([ -z $1 ] && echo upstream/master || echo "$1")
git rebase -i HEAD~$(l ${target_branch}.. | wc -l)
}
# `sed_perl` but runs only over git-controlled files that matched.
function spg () (
set -u
old="$1"
new="$2"
shift 2
sp "$old" "$new" $(ggf -P "$old" "$@")
)
function um () {
if [ $# = 0 ]; then
git fetch upstream master && git rebase upstream/master
else
git fetch upstream ${1} && git rebase upstream/${1}
fi
}
# have emacsclient for quick edits instead of vim
alias ec="emacsclient -ct"
function sudoec () {
ec "/sudo::$1"
}
alias gd="git diff -p --stat"
alias rc="git add -u && GIT_EDITOR=true git rebase --continue"
alias ca="git add -u && git commit --amend -v"
alias cax="git add -u && git commit --amend -v --no-edit"
alias amend_date="git commit --amend --date=now --no-edit"
alias or="git pull origin HEAD --rebase"
alias ur="git pull upstream HEAD --rebase"
alias co="git checkout"
alias l="git l"
alias lp="git log -p --stat"
alias gg="git --no-pager grep -In"
alias ggf="git --no-pager grep -In --files-with-matches"
alias ip="ip -c"
# I often find useful being able to peek at command timestamps in the scrollback
PROMPT='%{$fg[yellow]%}[%D{%d.%m.%Y-%H:%M:%S}] '$PROMPT
# do not "eat" control sequences while a command being executed. This is useful when
# I have a command running, and I want to press, say, ^R to enable reverse-search,
# type something into it, and press RET to make it execute. What will happen is that
# when a command finishes, everything I typed will get executed. Usually, ^R isn't
# passed, only the usual text. This setting makes ^R to get passed as well.
stty rprnt ''
# Re-execute prev. command and insert its output at the caret. Mostly useful for when
# a command returned single line that you want to re-use, like cd into the directory
# and the like.
function _insert-last-command-output () {
local hist=$history[$((HISTCMD-1))] REPLY
autoload -U read-from-minibuffer
LBUFFER+=${(j: :)${(qf)"$(eval $hist 2> /dev/null)"}}
}
bindkey "^X^H" _insert-last-command-output
zle -N _insert-last-command-output
# NOTE: the pluging documentation states it should be sourced at the end of .zshrc
source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh