-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellrc
More file actions
770 lines (690 loc) · 20.8 KB
/
Copy pathshellrc
File metadata and controls
770 lines (690 loc) · 20.8 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
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
#!/bin/bash
# NOTE: The she-bang is the most portable way to tell editor to use
# bash syntax highlight
# Copyright (c) 2013-2026, chys <admin@CHYS.INFO>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of chys <admin@CHYS.INFO> nor the names of other
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# This script is compatible with bash and zsh
# Source me from .bashrc or .zshrc
if [ -f ~/.shellrc.pre.local ]; then
. ~/.shellrc.pre.local
fi
if [[ -n "$ZSH_VERSION" ]]; then
zmodload -F zsh/stat b:zstat
zmodload zsh/datetime
has_executable() {
(( $+commands[$1] ))
}
else
has_executable() {
local IFS=:
local p
for p in ${PATH}; do
if [[ -x "$p/$1" ]]; then
return 0
fi
done
return 1
}
fi
has_function() {
declare -f "$1" &>/dev/null
}
# Define some common variables
__shellrc_host="${HOST:-${HOSTNAME}}" # zsh:HOST; bash:HOSTNAME
__shellrc_display_host="${__shellrc_host%%.*}" # Can be tweaked
__shellrc_display_user="$USER"
if has_function __shellrc_tweak_predefined_variables; then
__shellrc_tweak_predefined_variables
fi
if [[ "$OSTYPE" == darwin* ]]; then
if [[ -x /opt/homebrew/bin/brew ]]; then
if [[ ! -f ~/.shellrc.homebrew_shellenv_cache ]]; then
/opt/homebrew/bin/brew shellenv > ~/.shellrc.homebrew_shellenv_cache
elif [[ -n "$ZSH_VERSION" ]]; then
# In zsh, we also refresh the shellenv cache every week
zstat -A mtime +mtime ~/.shellrc.homebrew_shellenv_cache
if (( EPOCHSECONDS - mtime > 86400*7 )); then
/opt/homebrew/bin/brew shellenv > ~/.shellrc.homebrew_shellenv_cache
fi
fi
# Source it even if it's already in path, to ensure that brew path goes first
. ~/.shellrc.homebrew_shellenv_cache
fi
if has_executable gls; then
alias ls='gls --color=auto --file-type'
alias ll='ls -l --time-style=long-iso'
else
alias ls='ls --color=auto'
alias ll='ls -l'
fi
else
alias ls='ls --color=auto --file-type'
alias ll='ls -l --time-style=long-iso'
fi
alias lh='ll -h'
if [[ "$OSTYPE" == darwin* ]]; then
for v in awk cp date df find mv readlink rm sed stat tar xargs; do
if has_executable g$v; then
alias $v=g$v
fi
done
unset -v v
fi
#alias rm='rm -i'
#alias cp='cp -ip'
#alias mv='mv -i'
#alias convmv='convmv -i'
alias cdp='cd -P'
has_executable lsof && alias lsof='lsof -n'
has_executable traceroute && alias traceroute='traceroute -n'
has_executable netstat && alias netstat='netstat -n'
has_executable apt && alias apt='nice ionice -n 7 apt'
grep_options="--color=auto --devices=skip --exclude-dir=.{svn,git,hg}"
for v in grep egrep fgrep; do
if [[ "$OSTYPE" == darwin* ]] && has_executable g$v; then
alias $v="g$v $grep_options"
else
alias $v="$v $grep_options"
fi
done
unset -v v grep_options
_warn_dangerous_command() {
echo "Command $1 is aliased because it can be dangerous."
echo "Use \\\\$1 if you really want to use it."
return 1
}
add_dangerous() {
local r
for r; do
if [[ -x "$r" ]] || { [[ "$r" != */* ]] && has_executable "$r"; }; then
r="${r##*/}"
alias $r="_warn_dangerous_command $r"
fi
done
}
add_dangerous startx shred enconv import
[ "$EUID" = 0 ] && add_dangerous mkswap /sbin/mk*fs*
unset -f add_dangerous
if [ -n "$ZSH_VERSION" ]; then
unsetopt nomatch
fi
for dir in ~/{bin,bin2} {~,/usr/local}/bin.d/*; do
if [[ -d "$dir" ]]; then
export PATH="$dir:$PATH"
fi
done
unset -v dir
__shellrc_path_dedup() {
local newpath=
local IFS=:
local p
for p in ${ZSH_VERSION:+${path}}${BASH_VERSION:+${PATH}}; do
if [[ "$p" != /* ]]; then
continue
fi
# Most Linux distributions have done the /usr merge.
# Let's drop /bin and /sbin as duplicates if possible.
if [[ "$p" =~ ^/s?bin$ && "$p" -ef "/usr$p" ]]; then
p="/usr$p"
fi
if [[ "$p" == /usr/sbin && /usr/sbin -ef /usr/bin ]]; then
p=/usr/bin
fi
if [[ "$p" == /usr/local/sbin && /usr/local/sbin -ef /usr/local/bin ]]; then
p=/usr/local/bin
fi
case "$newpath" in
$p|$p:*|*:$p|*:$p:*);;
?*) newpath+=":$p";;
'') newpath="$p";;
esac
done
export PATH="$newpath"
}
__shellrc_path_dedup
unset -f __shellrc_path_dedup
if [[ -n "$ZSH_VERSION" ]]; then
# Zsh has great support for deduplication
# Not using this for $PATH because we want to do more (check for merged /usr)
typeset -U fpath FPATH manpath MANPATH
typeset -xT INFOPATH infopath :
typeset -U infopath
typeset -xT LD_LIBRARY_PATH ld_library_path :
typeset -U ld_library_path
else
__shellrc_ld_library_dedup() {
if [[ -z "$LD_LIBRARY_PATH" ]]; then
return
fi
local IFS=:
local new=
local p
for p in $LD_LIBRARY_PATH; do
if [[ "$p" != /* ]]; then
continue
fi
case "$new" in
$p|$p:*|*:$p|*:$p:*);;
?*) new+=":$p";;
'') new="$p";;
esac
done
export LD_LIBRARY_PATH="$new"
}
__shellrc_ld_library_dedup
unset -f __shellrc_ld_library_dedup
fi
unset -v MAIL MAILPATH MAILCHECK
temp=()
if [ -d "$HOME/Maildir/new" ]; then
export MAIL="$HOME/Maildir"
if [[ -h "$MAIL" ]]; then
if [[ -n "$ZSH_VERSION" ]]; then
export MAIL="${MAIL:A}"
else
export MAIL="$(readlink -f "$MAIL")"
fi
fi
temp+=("$HOME/Maildir")
fi
if [ -f "/var/spool/mail/$USER" ]; then
temp+=("/var/spool/mail/$USER")
fi
temp="${temp[*]}"
if [[ -n "$temp" ]]; then
MAILPATH="${temp// /:}"
fi
unset -v temp
if [[ -n "$MAILPATH" ]]; then
MAILCHECK=60
if [[ -n "$ZSH_VERSION" ]]; then
unsetopt mail_warning
else
shopt -u mailwarn
fi
fi
if [[ "$USER" != 'root' && -n "$USER" && -d /run/U/"$USER" && "$LESSHISTFILE" = '-' ]]; then
export LESSHISTFILE="/run/U/$USER/lesshst"
fi
# Some diestributions have bad default values. The upstream default is actually reasonable.
unset LESS
if has_executable svn && has_executable colordiff; then
_svn_wrapper() {
if ! [[ -t 1 ]]; then
'svn' "$@"
return
fi
local arg
for arg; do
case "$arg" in
-*)
;;
*)
if [[ "$arg" =~ ^di(ff)?$ ]]; then
'svn' "$@" | colordiff | less -R
return
elif [[ "$arg" == log ]]; then
'svn' "$@" | less
return
fi
esac
done
'svn' "$@"
}
alias svn=_svn_wrapper
fi
if has_executable git; then
alias g=git
fi
if has_executable tmux; then
alias ta='tmux attach'
fi
if has_executable journalctl; then
alias journalctl='journalctl -o short-precise --no-hostname'
fi
if has_executable fd; then
export FZF_DEFAULT_COMAND='fd --type f'
else
unset FZF_DEFAULT_COMMAND
fi
if [[ -n "$ZSH_VERSION" && "$USER" != root ]]; then
alias root='su - -s /bin/zsh'
fi
# It's weird that I always have problems defining local arrays in zsh
precmd_showstatus() {
local tmp
local q=$1
shift
local r
local msg=
for r; do :; done
if ((q != 0 && q != r)); then
if ((q > 128)); then
if [ -n "$ZSH_VERSION" ]; then # This is worthwhile because it prevents a fork
tmp=${signals[q-127]:+SIG${signals[q-127]}}
else
tmp=$(builtin kill -l "$q" 2>/dev/null)
fi
q=${tmp:-$q}
fi
msg="[$q]"
fi
if [[ "$*" == *[^0\ ]* ]]; then # At least one non-zero value
msg+=' ['
for r; do
if ((r > 128)); then
if [ -n "$ZSH_VERSION" ]; then
tmp=${signals[r-127]:+SIG${signals[r-127]}}
else
tmp=$(builtin kill -l "$r" 2>/dev/null)
fi
r=${tmp:-$r}
fi
msg+="$r "
done
msg="${msg% }]"
fi
msg="${msg# }"
[ -n "$msg" ] && builtin echo -e "\033[31;1m$msg\033[0m"
}
case "$TERM" in
xterm*|rxvt*|[akE]term|gnome*|interix|screen|screen-*|tmux-*)
if [ -n "$TMUX" -a "$SHLVL" -eq 1 ]; then
__default_shell="${ZSH_VERSION:+zsh}${BASH_VERSION:+bash}"
elif [[ "$OSTYPE" == darwin* ]]; then
__default_shell=zsh
elif [ -z "$__default_shell" -a -r /etc/passwd ]; then
__default_shell="$(sed -n -e '/^[^:]\+:[^:]\+:'$UID':/ { s!.*/\(.*\)!\1!p; q }' /etc/passwd)"
if [ "$__default_shell" = sh -a -L /bin/sh ]; then
__default_shell=$(readlink -f /bin/sh)
__default_shell="${__default_shell##*/}"
fi
fi
precmd_maketitle()
{
local pwd="${PWD}/"
# pwd="${pwd/#"${HOME}"\//~/}" confuses some versions of VIM highlight
if [ "${pwd##$HOME/}" != "$pwd" ]; then
pwd="~${pwd##$HOME}"
fi
pwd="${pwd%/}"
if ((${#pwd} >= 10)) && [[ "$pwd" == */*/* ]]; then
pwd="*/${pwd##*/}"
fi
if [ -n "$Shell_NoHistory" ]; then
pwd="${pwd//[^\/A-Za-z0-9\ \.\-_]/*}"
fi
local sh="${ZSH_VERSION:+zsh}${BASH_VERSION:+bash}"
local prefix=
if [ "$__default_shell" != "$sh" ]; then
prefix="[$sh]"
fi
if [[ -z "$__DONT_SCREAM_AT_GB" && ${LC_ALL:-${LC_CTYPE:-${LANG:-${LANGUAGE}}}} == *.[Gg][Bb]* ]]; then
prefix="[GB]$prefix"
fi
if [[ -n "$prefix" ]]; then
prefix+=' '
fi
local prompt_message=""
if [[ "$TERM" == screen-* || "$TERM" == tmux-* ]]; then
# In tmux, we try to change both window title and name (\x5c is backslash - work around VIM highlighting)
builtin echo -ne "\033]0;${prefix}${__shellrc_display_host%%.*}: ${__shellrc_display_user}: ${pwd}\007\033k${prefix}${pwd}\033\x5c"
else
builtin echo -ne "\033]0;${prefix}${__shellrc_display_host%%.*}: ${__shellrc_display_user}: ${pwd}\007"
fi
}
;;
*)
precmd_maketitle() { :; }
;;
esac
if [ -n "$ZSH_VERSION" ]; then
autoload -Uz vcs_info
zstyle ':vcs_info:*' actionformats \
'%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats \
'%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{5}]%f '
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
zstyle ':vcs_info:*' enable git svn
__last_vcs_info_pwd=
__last_vcs_info_time=0
precmd_vcs_info_cmd_test() {
if [[ ! "$1" == *"$2"* && ! "$1" == *"$3"* ]]; then
return 1
elif [[ "$1" =~ ^\ *(git|g|q?svn)\ +(blame|diff|log|st|status)(\ |$) ]]; then
return 1
elif [[ "$1" =~ ^\ *(git|g)\ +(cat-file|describe|di|f|fetch|gc|[efp]?grep|ls|push|ps|shortlog|show|wc|whatchanged)(\ |$) ]]; then
return 1
elif [[ "$1" =~ ^\ *q?svn\ +(di|info|cat)(\ |$) ]]; then
return 1
else
return 0
fi
}
precmd_vcs_info() {
# Let's detect .git and .svn dirs ourselves without invoking any
# external command
local pwd="$PWD"
local found=
local alternative=
while [ -n "$pwd" -a "$pwd" != '/' ]; do
# .git may not necessarily be a dir. It could be regular file in a worktree.
if [ -e "$pwd/.git" ]; then
found=git
alternative=g
break
elif [ -d "$pwd/.svn" ]; then
found=svn
alternative=svn
break
fi
pwd="${pwd%/*}"
done
if [ -z "$found" ]; then
vcs_info_msg_0_=
__last_vcs_info_pwd=
return
fi
# Does it appear that anything has changed?
local likely_changed=0
if [ "$pwd" != "$__last_vcs_info_pwd" ]; then
likely_changed=1
elif ((SECONDS > __last_vcs_info_time + 60)); then
# Run at least every minute
likely_changed=1
elif precmd_vcs_info_cmd_test "$(fc -ln $((HISTCMD-1)))" "$found" "$alternative"; then
# Run if any relevant command has intervened
likely_changed=1
fi
if ((likely_changed)); then
__last_vcs_info_pwd="$pwd"
__last_vcs_info_time=$SECONDS
if [[ "$OSTYPE" == *cygwin* && "$found" == 'svn' ]]; then
# Default behavior is too damn slow under cygwin. Do our own, in the simplest way
vcs_info_msg_0_='%F{5}(%fsvn%F{5})%f '
else
vcs_info
fi
fi
}
fi
precmd() {
# If either $? or any component of PIPESTATUS is nonzero, display it.
precmd_showstatus $? ${BASH_VERSION:+${PIPESTATUS[@]}} ${ZSH_VERSION:+${pipestatus[@]}}
# Write window title if the terminal supports it.
precmd_maketitle
# Show current git branch
if [ -n "$ZSH_VERSION" ]; then
precmd_vcs_info
fi
}
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND='precmd'
# Set locales
# For darwin host, we trust the system's defaults
if [[ "$OSTYPE" != darwin* ]]; then
charset='UTF-8'
if [[ "$OSTYPE" == *cygwin* ]]; then
charset='UTF-8@cjknarrow'
fi
unset -v LC_ALL LC_MESSAGES LC_NUMERIC LC_MONETARY LC_TIME
export LC_COLLATE="zh_CN.$charset" LC_CTYPE="zh_CN.$charset"
if [[ "$OSTYPE" == *linux* ]]; then
export LANG="C.UTF-8"
else
export LANG="en_US.$charset"
fi
unset -v charset
fi
# Assert my terminal emulator supports 256 colors
if [[ "$TERM" == 'xterm' ]]; then
export TERM=xterm-256color
elif [[ "$TERM" == 'screen' && -n "$DISPLAY" ]]; then
# Screen and tmux support 256 colors at least when they're running within
# a modern X terminal emulator
export TERM=screen-256color
fi
if [ -n "$BASH_VERSION" ]; then
#Workaround for the poor design of new versions of bash-completion
if ! complete -p cd &>/dev/null; then
[ -f /etc/profile.d/bash-completion.sh ] && . /etc/profile.d/bash-completion.sh
fi
for i in {/usr/local,"$HOME"}/bin*/bashcomp*.sh; do
[ -f "$i" ] && . "$i"
done
unset -v i
# Bash options
#set -C
# histappend: It appears bash has some heuristics to determine whether to append
shopt -s autocd 2>/dev/null # Old versions do not support autocd
shopt -s extglob cmdhist no_empty_cmd_completion checkwinsize
shopt -u sourcepath dotglob nullglob
if [ "$UID" = 0 ]; then
if [[ -n "$SSH_TTY" || -n "$SSH2_CLIENT" ]]; then
PS1='\[\033[01;31m\]\h\[\033[01;34m\] \w \[\033[1;$((31+3*!$?))m\]\$\[\033[00m\] '
else
PS1='\[\033[01;31m\]\w \[\033[1;$((31+!$?))m\]\$\[\033[00m\] '
fi
else
if [[ -n "$SSH_TTY" || -n "$SSH2_CLIENT" ]]; then
PS1='\[\033[01;32m\]\h\[\033[01;34m\] \w \[\033[1;$((31+3*!$?))m\]\$\[\033[00m\] '
else
PS1='\[\033[01;34m\]\w \[\033[1;$((31+!$?))m\]\$\[\033[00m\] '
fi
fi
if [ $SHLVL -gt 1 ]; then
PS1="[$SHLVL] $PS1"
fi
if [[ -z "$__DONT_SCREAM_AT_GB" && ${LC_ALL:-${LC_CTYPE:-${LANG}}} == *.[Gg][Bb]* ]]; then
PS1="[GB] $PS1"
fi
fi # Bash-specific
if [ -n "$ZSH_VERSION" ]; then
autoload -Uz compinit
compinit
PS1='%(2L.[%L] .)%B%(!.%F{red}.%F{blue})%~%f%(1j. (%j job%(2j.s.)%).) ${vcs_info_msg_0_}%(!.%F{red}.%F{blue})▶%f%b '
RPS1='%F{yellow}%D{%m-%d %H:%M:%S}%f'
RPS2="$RPS1"
[[ -n "$SSH_TTY" || -n "$SSH2_CLIENT" ]] && PS1="%B[SSH ${__shellrc_display_host%%.*}]%b $PS1"
if [[ -z "$__DONT_SCREAM_AT_GB" && ${LC_ALL:-${LC_CTYPE:-${LANG}}} == *.[Gg][Bb]* ]]; then
PS1="[GB] $PS1"
fi
setopt prompt_subst
setopt notify pushdtohome autolist
setopt autocd longlistjobs
setopt clobber
# Don't turn on ksh_glob, which contradicts "(N)" etc.
setopt pushdminus extended_glob rcquotes
unsetopt cdablevars # It's very annoying that "cd username" goes to a home dir
unsetopt nomatch # I can't get used to nomatch
unsetopt bgnice pushdsilent autopushd
unsetopt correct correctall globdots
unsetopt multios
zstyle ':completion:*' verbose yes
zstyle ':completion:*' menu select
# It appears LS_COLORS is not set by default.
if has_executable gdircolors; then
eval "$(gdircolors)"
elif has_executable dircolors; then
eval "$(dircolors)"
fi
# Use the same colors as ls
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
local __oh_my_zsh=$HOME/external/oh-my-zsh
if [[ ! -d "$__oh_my_zsh" && "$UID" = 0 ]]; then
for v in /home/*/external/oh-my-zsh; do
if [[ -d "$v" ]]; then
__oh_my_zsh="$v"
fi
done
unset -v v
fi
if [[ -r "$__oh_my_zsh/lib/key-bindings.zsh" ]]; then
. "$__oh_my_zsh/lib/key-bindings.zsh"
else
echo "oh-my-zsh/lib/key-bindings.sh not found" >&2
fi
unset -v __oh_my_zsh
# More key bindings not present in oh-my-zsh
bindkey -M emacs '^[[1;3D' backward-word
bindkey -M viins '^[[1;3D' backward-word
bindkey -M vicmd '^[[1;3D' backward-word
bindkey -M emacs '^[[1;3C' forward-word
bindkey -M viins '^[[1;3C' forward-word
bindkey -M vicmd '^[[1;3C' forward-word
bindkey -M emacs '^[[3;3~' kill-word
bindkey -M viins '^[[3;3~' kill-word
bindkey -M vicmd '^[[3;3~' kill-word
bindkey -M emacs '^H' backward-delete-word
bindkey -M viins '^H' backward-delete-word
bindkey -M vicmd '^H' backward-delete-word
fi # Zsh-specific
# Shell history conf
HISTSIZE=50000
if [ -n "$BASH_VERSION" ]; then
HISTCONTROL='ignorespace:erasedups'
HISTFILESIZE=50000
else # zsh
HISTFILE="$HOME/.zsh_history"
SAVEHIST=50000
setopt inc_append_history hist_ignore_all_dups hist_ignore_space
setopt hist_expire_dups_first hist_fcntl_lock
setopt hist_reduce_blanks hist_save_no_dups
unsetopt hist_verify
# This imports ~/.zsh_history to the current session, like share_history
# See zsh documentation for share_history
sync_history() {
fc -RI
}
fi
if [ -n "$Shell_NoHistory" ]; then
PS1="(nohist) $PS1"
HISTFILE=
if [[ "$Shell_NoHistory" != "1" && -d "$Shell_NoHistory" ]]; then
v="$Shell_NoHistory"
while [[ -n "$v" ]]; do
if [[ -f "$v/.sh_nohist" ]]; then
HISTFILE="$v/.sh_nohist"
echo "Set HISTFILE to $HISTFILE" >&2
break
fi
if [[ "$v" != */* ]]; then
break
fi
v="${v%/*}"
done
unset -v v
fi
if [[ -z "$HISTFILE" ]]; then
HISTFILE=/tmp/.nohist.$USER
touch "$HISTFILE"
echo "Setting HISTFILE to $HISTFILE" >&2
echo "Create a .sh_nohist file for customized location" >&2
fi
else
nohist() {
(
if [[ -n "$1" ]]; then
if [[ ! -d "$1" ]]; then
echo "No such file or directory: $1" >&2
return 1
fi
cd -- "$1"
export Shell_NoHistory="$PWD"
else
export Shell_NoHistory=1
fi
exec ${BASH_VERSION:+bash}${ZSH_VERSION:+zsh}
)
}
if [ -n "$BASH_VERSION" ]; then
complete -d nohist
elif [ -n "$ZSH_VERSION" ]; then
zstyle ':completion:*:nohist:*' file-patterns '*(/):directories'
fi
fi
if [[ -z "$GOPATH" && -d ~/go ]]; then
export GOPATH=~/go
fi
set -o emacs
umask 022
if [ -f ~/.shellrc.local ]; then
. ~/.shellrc.local
fi
if [[ -d ~/.shellrc.local.d ]]; then
for v in ~/.shellrc.local.d/*.sh; do
if [[ -r "$v" ]]; then
. "$v"
fi
done
unset -v v
fi
if [ -n "$ZSH_VERSION" ]; then
# This doesn't work for bash
alias shellrc=". $0"
fi
# Create multiple windows in TMUX
if [[ -n "$TMUX" && "$TMUX_PANE" = "%0" && -z "$__shellrc_tmux" ]]; then
if ! tmux showenv __shellrc_tmux 2>/dev/null; then
export __shellrc_tmux=1 # For current shell
tmux setenv __shellrc_tmux 1
start_tmux_windows() {
local cd0="$1"
shift
local v
for v; do
if [[ -z "$v" ]]; then
tmux neww -d
else
if [[ "$v" != /* ]]; then
v="$HOME/$v"
fi
tmux neww -d -c "$v"
fi
done
if [[ -n "$cd0" ]]; then
if [[ "$cd0" != /* ]]; then
cd0="$HOME/$cd0"
fi
cd "$cd0"
fi
}
# Could be defined in ~/.shellrc.local
if [[ -n "${__shellrc_tmux_dirs[*]}" ]]; then
start_tmux_windows "${__shellrc_tmux_dirs[@]}"
else
start_tmux_windows '' '' '' '' '' '' ''
fi
unset -f start_tmux_windows
fi
fi
if ((`ulimit -n` < 16384)); then
ulimit -n 16384 2>/dev/null
fi
: