-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path.zshrc
346 lines (297 loc) · 11.5 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#
# ~/.zshrc
# Author: Dustin Tran <dustintran.com>
#
# General Settings
# -----------------------------------------------------------------------------
setopt auto_name_dirs
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
setopt multios
setopt cdablevarS
setopt autocd
setopt extendedglob
setopt interactivecomments
setopt nobeep
setopt nocheckjobs
setopt correct
CACHEDIR="$HOME/.cache/zsh-cache"
################################################################################
# History
################################################################################
HISTSIZE=1000
SAVEHIST=${HISTSIZE}
HISTFILE=~/.zshinfo
setopt histignoredups
setopt share_history
setopt append_history
setopt extended_history
setopt hist_expire_dups_first
setopt hist_ignore_space
setopt hist_verify
setopt inc_append_history
# Completion
# -----------------------------------------------------------------------------
# Use (advanced) completion functionality
# TODO: just switch to a theme like zsh pure
#autoload -U compinit
#compinit -d $CACHEDIR/zcompdump 2>/dev/null
# Use cache to speed completion up and set cache folder path
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path $CACHEDIR
# Auto-insert first suggestion
setopt menu_complete
# If the <tab> key is pressed with multiple possible options, print the
# options. If the options are printed, begin cycling through them
zstyle ':completion:*' menu select
# Set format for warnings
zstyle ':completion:*:warnings' format 'Sorry, no matches for: %d%b'
# Use colors when outputting file names for completion options
zstyle ':completion:*' list-colors ''
# Do not prompt to cd into current directory
# For example, cd ../<tab> should not prompt current directory
zstyle ':completion:*:cd:*' ignore-parents parent pwd
# Completion for kill
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,cputime,cmd'
# Show completion for hidden files also
zstyle ':completion:*' file-patterns '*(D)'
# Red dots!
expand-or-complete-with-dots() {
echo -n "\e[31m......\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
# Prompt Style
# -----------------------------------------------------------------------------
autoload -U colors && colors
PS1=$'%(!.%S-ROOT-%s.%n) %~ '
#zle-keymap-select () {
# if [ $KEYMAP = vicmd ]; then
# PS1=$'%{\e[0m%}%{\e[48;5;240m%}%{\e[38;5;235m%} %(!.%S-ROOT-%s.%n) \e[38;5;240m%}\e[48;5;249m%}⮀%{\e[38;5;235m%}%{\e[48;5;249m%} %~ %{\e[48;5;0m%}%{\e[38;5;249m%}⮀ %{\e[0m%}'
# () { return $__prompt_status }
# zle reset-prompt
# else
# PS1=$'%{\e[0m%}%{\e[48;5;255m%}%{\e[38;5;235m%} %(!.%S-ROOT-%s.%n) \e[38;5;255m%}\e[48;5;249m%}⮀%{\e[38;5;235m%}%{\e[48;5;249m%} %~ %{\e[48;5;0m%}%{\e[38;5;249m%}⮀ %{\e[0m%}'
# () { return $__prompt_status }
# zle reset-prompt
# fi
#}
#zle -N zle-keymap-select
#zle-line-init () {
# zle -K viins
# PS1=$'%{\e[0m%}%{\e[48;5;255m%}%{\e[38;5;235m%} %(!.%S-ROOT-%s.%n) \e[38;5;255m%}\e[48;5;249m%}⮀%{\e[38;5;235m%}%{\e[48;5;249m%} %~ %{\e[48;5;0m%}%{\e[38;5;249m%}⮀ %{\e[0m%}'
# () { return $__prompt_status }
# zle reset-prompt
#}
#zle -N zle-line-init
# zle widgets
# -----------------------------------------------------------------------------
# Delete all characters between a pair of characters. Mimics Vim's "di" text
# object functionality
# TODO: get this working..
delete-in() {
# Create locally-scoped variables we'll need
local CHAR LCHAR RCHAR LSEARCH RSEARCH COUNT
# Read the character to indicate which text object we're deleting
read -k CHAR
if [ "$CHAR" = "w" ]
then # diw, delete the word
# find the beginning of the word under the cursor
zle vi-backward-word
# set the left side of the delete region at this point
LSEARCH=$CURSOR
# find the end of the word under the cursor
zle vi-forward-word
# set the right side of the delete region at this point
RSEARCH=$CURSOR
# Set the BUFFER to everything except the word we are removing
RBUFFER="$BUFFER[$RSEARCH+1,${#BUFFER}]"
LBUFFER="$LBUFFER[1,$LSEARCH]"
return
# diw was unique. For everything else, we just have to define the
# characters to the left and right of the cursor to be removed
elif [ "$CHAR" = "(" ] || [ "$CHAR" = ")" ] || [ "$CHAR" = "b" ]
then # di), delete inside of a pair of parenthesis
LCHAR="("
RCHAR=")"
elif [ "$CHAR" = "[" ] || [ "$CHAR" = "]" ]
then # di], delete inside of a pair of square brackets
LCHAR="["
RCHAR="]"
elif [ $CHAR = "{" ] || [ $CHAR = "}" ] || [ "$CHAR" = "B" ]
then # di], delete inside of a pair of braces
LCHAR="{"
RCHAR="}"
else
# The character entered does not have a special definition
# Simply find the first instance to the left and right of the
# cursor
LCHAR="$CHAR"
RCHAR="$CHAR"
fi
# Find the first instance of LCHAR to the left of the cursor and the
# first instance of RCHAR to the right of the cursor, and remove
# everything in between
# Begin the search for the left-sided character directly the left of the cursor
LSEARCH=${#LBUFFER}
# Keep going left until we find the character or hit the beginning of the buffer
while [ "$LSEARCH" -gt 0 ] && [ "$LBUFFER[$LSEARCH]" != "$LCHAR" ]
do
LSEARCH=$(expr $LSEARCH - 1)
done
# If we hit the beginning of the command line without finding the character, abort
if [ "$LBUFFER[$LSEARCH]" != "$LCHAR" ]
then
return
fi
# start the search directly to the right of the cursor
RSEARCH=0
# Keep going right until we find the character or hit the end of the buffer
while [ "$RSEARCH" -lt $(expr ${#RBUFFER} + 1 ) ] && [ "$RBUFFER[$RSEARCH]" != "$RCHAR" ]
do
RSEARCH=$(expr $RSEARCH + 1)
done
# If we hit the end of the command line without finding the character, abort
if [ "$RBUFFER[$RSEARCH]" != "$RCHAR" ]
then
return
fi
# Set the BUFFER to everything except the text we are removing
RBUFFER="$RBUFFER[$RSEARCH,${#RBUFFER}]"
LBUFFER="$LBUFFER[1,$LSEARCH]"
}
zle -N delete-in
# Delete all characters between a pair of characters and then go to insert mode
# Mimics Vim's "ci" text object functionality
change-in() {
zle delete-in
zle vi-insert
}
zle -N change-in
# Delete all characters between a pair of characters as well as the surrounding
# characters themselves. Mimics Vim's "da" text object functionality
delete-around() {
zle delete-in
zle vi-backward-char
zle vi-delete-char
zle vi-delete-char
}
zle -N delete-around
# Delete all characters between a pair of characters as well as the surrounding
# characters themselves and then go into insert mode Mimics Vim's "ca" text
# object functionality
change-around() {
zle delete-in
zle vi-backward-char
zle vi-delete-char
zle vi-delete-char
zle vi-insert
}
zle -N change-around
# Zsh's vi-up/down-line-or-history does what I want but leaves the cursor at the
# beginning rather than front. Perplexing!
vim-up-line-or-history() {
zle vi-up-line-or-history
zle vi-end-of-line
}
zle -N vim-up-line-or-history
vim-down-line-or-history() {
zle vi-down-line-or-history
zle vi-end-of-line
}
zle -N vim-down-line-or-history
zle -N yank-x-selection
autoload edit-command-line
zle -N edit-command-line
# The Vim setup
# -----------------------------------------------------------------------------
bindkey -v
# Disable flow control. Specifically, ensure that ctrl-s does not stop
# terminal flow so that it can be used in other programs (such as Vim)
setopt noflowcontrol
stty -ixon
# Disable use of ^D
stty eof undef
# 1 sec <Esc> time delay? zsh pls
# Set to 10ms for key sequences. (Note "bindkey -rp '^['" removes the
# availability of any '^[...' mappings, so use this instead.)
KEYTIMEOUT=1
################################################################################
# Insert mode
################################################################################
# Vim defaults
bindkey -M viins "^?" backward-delete-char # i_Backspace
bindkey -M viins '^[[3~' delete-char # i_Delete
bindkey -M viins '^[[Z' reverse-menu-complete # i_SHIFT-Tab
# Non-Vim default mappings I use everywhere
bindkey -M viins "^N" vim-down-line-or-history # i_CTRL-N
bindkey -M viins "^E" vim-up-line-or-history # i_CTRL-E
# Edit current line in veritable Vim
bindkey -M viins "^H" edit-command-line # i_CTRL-I
################################################################################
# Normal mode
################################################################################
# Vim defaults
#bindkey -M vicmd "ca" change-around # ca
#bindkey -M vicmd "ci" change-in # ci
bindkey -M vicmd "cc" vi-change-whole-line # cc
#bindkey -M vicmd "da" delete-around # da
#bindkey -M vicmd "di" delete-in # di
bindkey -M vicmd "dd" kill-whole-line # dd
bindkey -M vicmd "^R" redo # CTRL-R
# Non-Vim default mappings I use everywhere
bindkey -M vicmd "s" backward-char # i_s
bindkey -M vicmd "t" forward-char # i_t
bindkey -M vicmd "z" vi-substitute # z
# Alias & Functions
# -----------------------------------------------------------------------------
################################################################################
# Alias
################################################################################
# Default flags
alias df="df -h"
alias du="du -h -c"
alias grep="grep --color"
alias ls="gls -a --color"
alias youtube-dl="youtube-dl -cik"
alias ranger='ranger --choosedir=/tmp/rangerdir; LASTDIR=`cat /tmp/rangerdir`; cd "$LASTDIR"; unset LASTDIR'
# Use `diskutil list` to list connected devices, osxfuse as the mounting software.
alias mount2-ntfs="sudo ntfs-3g -o uid=501,gid=20 /dev/disk2s1 /mnt/disk2s1"
alias mount3-ntfs="sudo ntfs-3g -o uid=501,gid=20 /dev/disk3s1 /mnt/disk3s1"
alias mount2-ext="sudo mount -t fuse-ext2 /dev/disk2s1 /mnt/disk2s1"
alias mount3-ext="sudo mount -t fuse-ext2 /dev/disk3s1 /mnt/disk3s1"
#sudo ext4fuse /dev/disk2s1 /mnt/disk2s1 -o allow_other
#sudo umount /mnt/disk2s1
alias umount2="sudo umount /mnt/disk2s1"
alias umount3="sudo umount /mnt/disk3s1"
# Make backup files ~/doc/package-list, ~/system/groups, ~/system/systemctl
# TODO: write equivalent for os x as external shell script
alias backup="(groups > ~/system/groups) && (systemctl --all > ~/system/systemctl) &&\
(echo 'This lists any installed packages that are not in the base or base-devel group, and hence are likely \
installed manually by\n me. See ~/.zshrc for the command.\n' > ~/doc/package-list\
&& (comm -23 <(pacman -Qeq|sort) <(pacman -Qgq base base-devel|sort)\
&& echo 'matlab r-2012b (\"make install\")') | sort >> ~/doc/package-list)"
################################################################################
# Functions
################################################################################
# The best zip! Don't include parent folders, don't nest zip function, zip
# recursively, and auto-take zip's second argument as first
zip() {
name="$(basename -- "$1")"
cd "$(dirname -- "$1")" &&
command zip -r "$name.zip" "$name"
}
# Due to Sierra, this has to be put in .zshrc instead of .zshenv.
# Default to Homebrew's Python, coreutils, LateX, and my own binaries.
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
export PATH=/usr/local/bin:$(brew --prefix coreutils)/libexec/gnubin:$PATH
export PATH=$PATH:$HOME/bin
export PATH=$PATH:/Library/TeX/texbin
source /usr/local/bin/virtualenvwrapper.sh
export WORKON_HOME=~/Envs
export PYTHONSTARTUP=~/.pythonrc
alias tmux="tmux -2" # add 256 colors