-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc.bk
4087 lines (3577 loc) · 131 KB
/
.zshrc.bk
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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Filename: /etc/zsh/zshrc
# Purpose: config file for zsh (z shell)
# Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
# Bug-Reports: see http://grml.org/bugs/
# License: This file is licensed under the GPL v2.
################################################################################
# This file is sourced only for interactive shells. It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin
################################################################################
# USAGE
# If you are using this file as your ~/.zshrc file, please use ~/.zshrc.pre
# and ~/.zshrc.local for your own customisations. The former file is read
# before ~/.zshrc, the latter is read after it. Also, consider reading the
# refcard and the reference manual for this setup, both available from:
# <http://grml.org/zsh/>
# Contributing:
# If you want to help to improve grml's zsh setup, clone the grml-etc-core
# repository from git.grml.org:
# git clone git://git.grml.org/grml-etc-core.git
#
# Make your changes, commit them; use 'git format-patch' to create a series
# of patches and send those to the following address via 'git send-email':
# grml-etc-core@grml.org
#
# Doing so makes sure the right people get your patches for review and
# possibly inclusion.
# zsh-refcard-tag documentation:
# You may notice strange looking comments in this file.
# These are there for a purpose. grml's zsh-refcard can now be
# automatically generated from the contents of the actual configuration
# file. However, we need a little extra information on which comments
# and what lines of code to take into account (and for what purpose).
#
# Here is what they mean:
#
# List of tags (comment types) used:
# #a# Next line contains an important alias, that should
# be included in the grml-zsh-refcard.
# (placement tag: @@INSERT-aliases@@)
# #f# Next line contains the beginning of an important function.
# (placement tag: @@INSERT-functions@@)
# #v# Next line contains an important variable.
# (placement tag: @@INSERT-variables@@)
# #k# Next line contains an important keybinding.
# (placement tag: @@INSERT-keybindings@@)
# #d# Hashed directories list generation:
# start denotes the start of a list of 'hash -d'
# definitions.
# end denotes its end.
# (placement tag: @@INSERT-hasheddirs@@)
# #A# Abbreviation expansion list generation:
# start denotes the beginning of abbreviations.
# end denotes their end.
# Lines within this section that end in '#d .*' provide
# extra documentation to be included in the refcard.
# (placement tag: @@INSERT-abbrev@@)
# #m# This tag allows you to manually generate refcard entries
# for code lines that are hard/impossible to parse.
# Example:
# #m# k ESC-h Call the run-help function
# That would add a refcard entry in the keybindings table
# for 'ESC-h' with the given comment.
# So the syntax is: #m# <section> <argument> <comment>
# #o# This tag lets you insert entries to the 'other' hash.
# Generally, this should not be used. It is there for
# things that cannot be done easily in another way.
# (placement tag: @@INSERT-other-foobar@@)
#
# All of these tags (except for m and o) take two arguments, the first
# within the tag, the other after the tag:
#
# #<tag><section># <comment>
#
# Where <section> is really just a number, which are defined by the
# @secmap array on top of 'genrefcard.pl'. The reason for numbers
# instead of names is, that for the reader, the tag should not differ
# much from a regular comment. For zsh, it is a regular comment indeed.
# The numbers have got the following meanings:
# 0 -> "default"
# 1 -> "system"
# 2 -> "user"
# 3 -> "debian"
# 4 -> "search"
# 5 -> "shortcuts"
# 6 -> "services"
#
# So, the following will add an entry to the 'functions' table in the
# 'system' section, with a (hopefully) descriptive comment:
# #f1# Edit an alias via zle
# edalias() {
#
# It will then show up in the @@INSERT-aliases-system@@ replacement tag
# that can be found in 'grml-zsh-refcard.tex.in'.
# If the section number is omitted, the 'default' section is assumed.
# Furthermore, in 'grml-zsh-refcard.tex.in' @@INSERT-aliases@@ is
# exactly the same as @@INSERT-aliases-default@@. If you want a list of
# *all* aliases, for example, use @@INSERT-aliases-all@@.
# zsh profiling
# just execute 'ZSH_PROFILE_RC=1 zsh' and run 'zprof' to get the details
if [[ $ZSH_PROFILE_RC -gt 0 ]] ; then
zmodload zsh/zprof
fi
typeset -A GRML_STATUS_FEATURES
function grml_status_feature () {
emulate -L zsh
local f=$1
local -i success=$2
if (( success == 0 )); then
GRML_STATUS_FEATURES[$f]=success
else
GRML_STATUS_FEATURES[$f]=failure
fi
return 0
}
function grml_status_features () {
emulate -L zsh
local mode=${1:-+-}
local this
if [[ $mode == -h ]] || [[ $mode == --help ]]; then
cat <<EOF
grml_status_features [-h|--help|-|+|+-|FEATURE]
Prints a summary of features the grml setup is trying to load. The
result of loading a feature is recorded. This function lets you query
the result.
The function takes one argument: "-h" or "--help" to display this help
text, "+" to display a list of all successfully loaded features, "-" for
a list of all features that failed to load. "+-" to show a list of all
features with their statuses.
Any other word is considered to by a feature and prints its status.
The default mode is "+-".
EOF
return 0
fi
if [[ $mode != - ]] && [[ $mode != + ]] && [[ $mode != +- ]]; then
this="${GRML_STATUS_FEATURES[$mode]}"
if [[ -z $this ]]; then
printf 'unknown\n'
return 1
else
printf '%s\n' $this
fi
return 0
fi
for key in ${(ok)GRML_STATUS_FEATURES}; do
this="${GRML_STATUS_FEATURES[$key]}"
if [[ $this == success ]] && [[ $mode == *+* ]]; then
printf '%-16s %s\n' $key $this
fi
if [[ $this == failure ]] && [[ $mode == *-* ]]; then
printf '%-16s %s\n' $key $this
fi
done
return 0
}
# load .zshrc.pre to give the user the chance to overwrite the defaults
[[ -r ${ZDOTDIR:-${HOME}}/.zshrc.pre ]] && source ${ZDOTDIR:-${HOME}}/.zshrc.pre
# check for version/system
# check for versions (compatibility reasons)
function is51 () {
[[ $ZSH_VERSION == 5.<1->* ]] && return 0
return 1
}
function is4 () {
[[ $ZSH_VERSION == <4->* ]] && return 0
return 1
}
function is41 () {
[[ $ZSH_VERSION == 4.<1->* || $ZSH_VERSION == <5->* ]] && return 0
return 1
}
function is42 () {
[[ $ZSH_VERSION == 4.<2->* || $ZSH_VERSION == <5->* ]] && return 0
return 1
}
function is425 () {
[[ $ZSH_VERSION == 4.2.<5->* || $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
return 1
}
function is43 () {
[[ $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
return 1
}
function is433 () {
[[ $ZSH_VERSION == 4.3.<3->* || $ZSH_VERSION == 4.<4->* \
|| $ZSH_VERSION == <5->* ]] && return 0
return 1
}
function is437 () {
[[ $ZSH_VERSION == 4.3.<7->* || $ZSH_VERSION == 4.<4->* \
|| $ZSH_VERSION == <5->* ]] && return 0
return 1
}
function is439 () {
[[ $ZSH_VERSION == 4.3.<9->* || $ZSH_VERSION == 4.<4->* \
|| $ZSH_VERSION == <5->* ]] && return 0
return 1
}
#f1# Checks whether or not you're running grml
function isgrml () {
[[ -f /etc/grml_version ]] && return 0
return 1
}
#f1# Checks whether or not you're running a grml cd
function isgrmlcd () {
[[ -f /etc/grml_cd ]] && return 0
return 1
}
if isgrml ; then
#f1# Checks whether or not you're running grml-small
function isgrmlsmall () {
if [[ ${${${(f)"$(</etc/grml_version)"}%% *}##*-} == 'small' ]]; then
return 0
fi
return 1
}
else
function isgrmlsmall () { return 1 }
fi
GRML_OSTYPE=$(uname -s)
function islinux () {
[[ $GRML_OSTYPE == "Linux" ]]
}
function isdarwin () {
[[ $GRML_OSTYPE == "Darwin" ]]
}
function isfreebsd () {
[[ $GRML_OSTYPE == "FreeBSD" ]]
}
function isopenbsd () {
[[ $GRML_OSTYPE == "OpenBSD" ]]
}
function issolaris () {
[[ $GRML_OSTYPE == "SunOS" ]]
}
#f1# are we running within an utf environment?
function isutfenv () {
case "$LANG $CHARSET $LANGUAGE" in
*utf*) return 0 ;;
*UTF*) return 0 ;;
*) return 1 ;;
esac
}
# check for user, if not running as root set $SUDO to sudo
(( EUID != 0 )) && SUDO='sudo' || SUDO=''
# change directory to home on first invocation of zsh
# important for rungetty -> autologin
# Thanks go to Bart Schaefer!
isgrml && function checkhome () {
if [[ -z "$ALREADY_DID_CD_HOME" ]] ; then
export ALREADY_DID_CD_HOME=$HOME
cd
fi
}
# check for zsh v3.1.7+
if ! [[ ${ZSH_VERSION} == 3.1.<7->* \
|| ${ZSH_VERSION} == 3.<2->.<->* \
|| ${ZSH_VERSION} == <4->.<->* ]] ; then
printf '-!-\n'
printf '-!- In this configuration we try to make use of features, that only\n'
printf '-!- require version 3.1.7 of the shell; That way this setup can be\n'
printf '-!- used with a wide range of zsh versions, while using fairly\n'
printf '-!- advanced features in all supported versions.\n'
printf '-!-\n'
printf '-!- However, you are running zsh version %s.\n' "$ZSH_VERSION"
printf '-!-\n'
printf '-!- While this *may* work, it might as well fail.\n'
printf '-!- Please consider updating to at least version 3.1.7 of zsh.\n'
printf '-!-\n'
printf '-!- DO NOT EXPECT THIS TO WORK FLAWLESSLY!\n'
printf '-!- If it does today, you'\''ve been lucky.\n'
printf '-!-\n'
printf '-!- Ye been warned!\n'
printf '-!-\n'
function zstyle () { : }
fi
# autoload wrapper - use this one instead of autoload directly
# We need to define this function as early as this, because autoloading
# 'is-at-least()' needs it.
function zrcautoload () {
emulate -L zsh
setopt extended_glob
local fdir ffile
local -i ffound
ffile=$1
(( ffound = 0 ))
for fdir in ${fpath} ; do
[[ -e ${fdir}/${ffile} ]] && (( ffound = 1 ))
done
(( ffound == 0 )) && return 1
if [[ $ZSH_VERSION == 3.1.<6-> || $ZSH_VERSION == <4->* ]] ; then
autoload -U ${ffile} || return 1
else
autoload ${ffile} || return 1
fi
return 0
}
# The following is the ‘add-zsh-hook’ function from zsh upstream. It is
# included here to make the setup work with older versions of zsh (prior to
# 4.3.7) in which this function had a bug that triggers annoying errors during
# shell startup. This is exactly upstreams code from f0068edb4888a4d8fe94def,
# with just a few adjustments in coding style to make the function look more
# compact. This definition can be removed as soon as we raise the minimum
# version requirement to 4.3.7 or newer.
function add-zsh-hook () {
# Add to HOOK the given FUNCTION.
# HOOK is one of chpwd, precmd, preexec, periodic, zshaddhistory,
# zshexit, zsh_directory_name (the _functions subscript is not required).
#
# With -d, remove the function from the hook instead; delete the hook
# variable if it is empty.
#
# -D behaves like -d, but pattern characters are active in the function
# name, so any matching function will be deleted from the hook.
#
# Without -d, the FUNCTION is marked for autoload; -U is passed down to
# autoload if that is given, as are -z and -k. (This is harmless if the
# function is actually defined inline.)
emulate -L zsh
local -a hooktypes
hooktypes=(
chpwd precmd preexec periodic zshaddhistory zshexit
zsh_directory_name
)
local usage="Usage: $0 hook function\nValid hooks are:\n $hooktypes"
local opt
local -a autoopts
integer del list help
while getopts "dDhLUzk" opt; do
case $opt in
(d) del=1 ;;
(D) del=2 ;;
(h) help=1 ;;
(L) list=1 ;;
([Uzk]) autoopts+=(-$opt) ;;
(*) return 1 ;;
esac
done
shift $(( OPTIND - 1 ))
if (( list )); then
typeset -mp "(${1:-${(@j:|:)hooktypes}})_functions"
return $?
elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 )); then
print -u$(( 2 - help )) $usage
return $(( 1 - help ))
fi
local hook="${1}_functions"
local fn="$2"
if (( del )); then
# delete, if hook is set
if (( ${(P)+hook} )); then
if (( del == 2 )); then
set -A $hook ${(P)hook:#${~fn}}
else
set -A $hook ${(P)hook:#$fn}
fi
# unset if no remaining entries --- this can give better
# performance in some cases
if (( ! ${(P)#hook} )); then
unset $hook
fi
fi
else
if (( ${(P)+hook} )); then
if (( ${${(P)hook}[(I)$fn]} == 0 )); then
set -A $hook ${(P)hook} $fn
fi
else
set -A $hook $fn
fi
autoload $autoopts -- $fn
fi
}
# Load is-at-least() for more precise version checks Note that this test will
# *always* fail, if the is-at-least function could not be marked for
# autoloading.
zrcautoload is-at-least || function is-at-least () { return 1 }
# set some important options (as early as possible)
# append history list to the history file; this is the default but we make sure
# because it's required for share_history.
setopt append_history
# import new commands from the history file also in other zsh-session
is4 && setopt share_history
# save each command's beginning timestamp and the duration to the history file
setopt extended_history
# remove command lines from the history list when the first character on the
# line is a space
setopt histignorespace
# if a command is issued that can't be executed as a normal command, and the
# command is the name of a directory, perform the cd command to that directory.
setopt auto_cd
# in order to use #, ~ and ^ for filename generation grep word
# *~(*.gz|*.bz|*.bz2|*.zip|*.Z) -> searches for word not in compressed files
# don't forget to quote '^', '~' and '#'!
setopt extended_glob
# display PID when suspending processes as well
setopt longlistjobs
# report the status of backgrounds jobs immediately
setopt notify
# whenever a command completion is attempted, make sure the entire command path
# is hashed first.
setopt hash_list_all
# not just at the end
setopt completeinword
# Don't send SIGHUP to background processes when the shell exits.
setopt nohup
# make cd push the old directory onto the directory stack.
setopt auto_pushd
# avoid "beep"ing
setopt nobeep
# don't push the same dir twice.
setopt pushd_ignore_dups
# * shouldn't match dotfiles. ever.
setopt noglobdots
# use zsh style word splitting
setopt noshwordsplit
# don't error out when unset parameters are used
setopt unset
# setting some default values
NOCOR=${NOCOR:-0}
NOETCHOSTS=${NOETCHOSTS:-0}
NOMENU=${NOMENU:-0}
NOPRECMD=${NOPRECMD:-0}
COMMAND_NOT_FOUND=${COMMAND_NOT_FOUND:-0}
GRML_ZSH_CNF_HANDLER=${GRML_ZSH_CNF_HANDLER:-/usr/share/command-not-found/command-not-found}
GRML_DISPLAY_BATTERY=${GRML_DISPLAY_BATTERY:-${BATTERY:-0}}
GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
ZSH_NO_DEFAULT_LOCALE=${ZSH_NO_DEFAULT_LOCALE:-0}
typeset -ga ls_options
typeset -ga grep_options
# Colors on GNU ls(1)
if ls --color=auto / >/dev/null 2>&1; then
ls_options+=( --color=auto )
# Colors on FreeBSD and OSX ls(1)
elif ls -G / >/dev/null 2>&1; then
ls_options+=( -G )
fi
# Natural sorting order on GNU ls(1)
# OSX and IllumOS have a -v option that is not natural sorting
if ls --version |& grep -q 'GNU' >/dev/null 2>&1 && ls -v / >/dev/null 2>&1; then
ls_options+=( -v )
fi
# Color on GNU and FreeBSD grep(1)
if grep --color=auto -q "a" <<< "a" >/dev/null 2>&1; then
grep_options+=( --color=auto )
fi
# utility functions
# this function checks if a command exists and returns either true
# or false. This avoids using 'which' and 'whence', which will
# avoid problems with aliases for which on certain weird systems. :-)
# Usage: check_com [-c|-g] word
# -c only checks for external commands
# -g does the usual tests and also checks for global aliases
function check_com () {
emulate -L zsh
local -i comonly gatoo
comonly=0
gatoo=0
if [[ $1 == '-c' ]] ; then
comonly=1
shift 1
elif [[ $1 == '-g' ]] ; then
gatoo=1
shift 1
fi
if (( ${#argv} != 1 )) ; then
printf 'usage: check_com [-c|-g] <command>\n' >&2
return 1
fi
if (( comonly > 0 )) ; then
(( ${+commands[$1]} )) && return 0
return 1
fi
if (( ${+commands[$1]} )) \
|| (( ${+functions[$1]} )) \
|| (( ${+aliases[$1]} )) \
|| (( ${+reswords[(r)$1]} )) ; then
return 0
fi
if (( gatoo > 0 )) && (( ${+galiases[$1]} )) ; then
return 0
fi
return 1
}
# creates an alias and precedes the command with
# sudo if $EUID is not zero.
function salias () {
emulate -L zsh
local only=0 ; local multi=0
local key val
while getopts ":hao" opt; do
case $opt in
o) only=1 ;;
a) multi=1 ;;
h)
printf 'usage: salias [-hoa] <alias-expression>\n'
printf ' -h shows this help text.\n'
printf ' -a replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n'
printf ' be careful using this option.\n'
printf ' -o only sets an alias if a preceding sudo would be needed.\n'
return 0
;;
*) salias -h >&2; return 1 ;;
esac
done
shift "$((OPTIND-1))"
if (( ${#argv} > 1 )) ; then
printf 'Too many arguments %s\n' "${#argv}"
return 1
fi
key="${1%%\=*}" ; val="${1#*\=}"
if (( EUID == 0 )) && (( only == 0 )); then
alias -- "${key}=${val}"
elif (( EUID > 0 )) ; then
(( multi > 0 )) && val="${val// ; / ; sudo }"
alias -- "${key}=sudo ${val}"
fi
return 0
}
# Check if we can read given files and source those we can.
function xsource () {
if (( ${#argv} < 1 )) ; then
printf 'usage: xsource FILE(s)...\n' >&2
return 1
fi
while (( ${#argv} > 0 )) ; do
[[ -r "$1" ]] && source "$1"
shift
done
return 0
}
# Check if we can read a given file and 'cat(1)' it.
function xcat () {
emulate -L zsh
if (( ${#argv} != 1 )) ; then
printf 'usage: xcat FILE\n' >&2
return 1
fi
[[ -r $1 ]] && cat $1
return 0
}
# Remove these functions again, they are of use only in these
# setup files. This should be called at the end of .zshrc.
function xunfunction () {
emulate -L zsh
local -a funcs
local func
funcs=(salias xcat xsource xunfunction zrcautoload zrcautozle)
for func in $funcs ; do
[[ -n ${functions[$func]} ]] \
&& unfunction $func
done
return 0
}
# this allows us to stay in sync with grml's zshrc and put own
# modifications in ~/.zshrc.local
function zrclocal () {
xsource "/etc/zsh/zshrc.local"
xsource "${ZDOTDIR:-${HOME}}/.zshrc.local"
return 0
}
# locale setup
if (( ZSH_NO_DEFAULT_LOCALE == 0 )); then
xsource "/etc/default/locale"
fi
for var in LANG LC_ALL LC_MESSAGES ; do
[[ -n ${(P)var} ]] && export $var
done
builtin unset -v var
# set some variables
if check_com -c vim ; then
#v#
export EDITOR=${EDITOR:-vim}
else
export EDITOR=${EDITOR:-vi}
fi
#v#
export PAGER=${PAGER:-less}
#v#
export MAIL=${MAIL:-/var/mail/$USER}
# color setup for ls:
check_com -c dircolors && eval $(dircolors -b)
# color setup for ls on OS X / FreeBSD:
isdarwin && export CLICOLOR=1
isfreebsd && export CLICOLOR=1
# do MacPorts setup on darwin
if isdarwin && [[ -d /opt/local ]]; then
# Note: PATH gets set in /etc/zprofile on Darwin, so this can't go into
# zshenv.
PATH="/opt/local/bin:/opt/local/sbin:$PATH"
MANPATH="/opt/local/share/man:$MANPATH"
fi
# do Fink setup on darwin
isdarwin && xsource /sw/bin/init.sh
# load our function and completion directories
for fdir in /usr/share/grml/zsh/completion /usr/share/grml/zsh/functions; do
fpath=( ${fdir} ${fdir}/**/*(/N) ${fpath} )
done
typeset -aU ffiles
ffiles=(/usr/share/grml/zsh/functions/**/[^_]*[^~](N.:t))
(( ${#ffiles} > 0 )) && autoload -U "${ffiles[@]}"
unset -v fdir ffiles
# support colors in less
export LESS_TERMCAP_mb=$'\E[01;31m'
export LESS_TERMCAP_md=$'\E[01;31m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[01;44;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[01;32m'
# mailchecks
MAILCHECK=30
# report about cpu-/system-/user-time of command if running longer than
# 5 seconds
REPORTTIME=5
# watch for everyone but me and root
watch=(notme root)
# automatically remove duplicates from these arrays
typeset -U path PATH cdpath CDPATH fpath FPATH manpath MANPATH
# Load a few modules
is4 && \
for mod in parameter complist deltochar mathfunc ; do
zmodload -i zsh/${mod} 2>/dev/null
grml_status_feature mod:$mod $?
done && builtin unset -v mod
# autoload zsh modules when they are referenced
if is4 ; then
zmodload -a zsh/stat zstat
zmodload -a zsh/zpty zpty
zmodload -ap zsh/mapfile mapfile
fi
# completion system
COMPDUMPFILE=${COMPDUMPFILE:-${ZDOTDIR:-${HOME}}/.zcompdump}
if zrcautoload compinit ; then
typeset -a tmp
zstyle -a ':grml:completion:compinit' arguments tmp
compinit -d ${COMPDUMPFILE} "${tmp[@]}"
grml_status_feature compinit $?
unset tmp
else
grml_status_feature compinit 1
function compdef { }
fi
# completion system
# called later (via is4 && grmlcomp)
# note: use 'zstyle' for getting current settings
# press ^xh (control-x h) for getting tags in context; ^x? (control-x ?) to run complete_debug with trace output
function grmlcomp () {
# TODO: This could use some additional information
# Make sure the completion system is initialised
(( ${+_comps} )) || return 1
# allow one error for every three characters typed in approximate completer
zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )'
# don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '(aptitude-*|*\~)'
# start menu completion only if it could find no unambiguous initial string
zstyle ':completion:*:correct:*' insert-unambiguous true
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
zstyle ':completion:*:correct:*' original true
# activate color-completion
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# format on completion
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}'
# automatically complete 'cd -<tab>' and 'cd -<ctrl-d>' with menu
# zstyle ':completion:*:*:cd:*:directory-stack' menu yes select
# insert all expansions for expand completer
zstyle ':completion:*:expand:*' tag-order all-expansions
zstyle ':completion:*:history-words' list false
# activate menu
zstyle ':completion:*:history-words' menu yes
# ignore duplicate entries
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' stop yes
# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# separate matches into groups
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''
if [[ "$NOMENU" -eq 0 ]] ; then
# if there are more than 5 options allow selecting from a menu
zstyle ':completion:*' menu select=5
else
# don't use any menus at all
setopt no_auto_menu
fi
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:options' auto-description '%d'
# describe options in full
zstyle ':completion:*:options' description 'yes'
# on processes completion complete all user processes
zstyle ':completion:*:processes' command 'ps -au$USER'
# offer indexes before parameters in subscripts
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters
# provide verbose completion information
zstyle ':completion:*' verbose true
# recent (as of Dec 2007) zsh versions are able to provide descriptions
# for commands (read: 1st word in the line) that it will list for the user
# to choose from. The following disables that, because it's not exactly fast.
zstyle ':completion:*:-command-:*:' verbose false
# set format for warnings
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d'
# define files to ignore for zcompile
zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)'
zstyle ':completion:correct:' prompt 'correct to: %e'
# Ignore completion functions for commands you don't have:
zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*'
# Provide more processes in completion of programs like killall:
zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq'
# complete manual by their section
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
# Search path for sudo completion
zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
/usr/local/bin \
/usr/sbin \
/usr/bin \
/sbin \
/bin \
/usr/X11R6/bin
# provide .. as a completion
zstyle ':completion:*' special-dirs ..
# run rehash on completion so new installed program are found automatically:
function _force_rehash () {
(( CURRENT == 1 )) && rehash
return 1
}
## correction
# some people don't like the automatic correction - so run 'NOCOR=1 zsh' to deactivate it
if [[ "$NOCOR" -gt 0 ]] ; then
zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _files _ignored
setopt nocorrect
else
# try to be smart about when to use what completer...
setopt correct
zstyle -e ':completion:*' completer '
if [[ $_last_try != "$HISTNO$BUFFER$CURSOR" ]] ; then
_last_try="$HISTNO$BUFFER$CURSOR"
reply=(_complete _match _ignored _prefix _files)
else
if [[ $words[1] == (rm|mv) ]] ; then
reply=(_complete _files)
else
reply=(_oldlist _expand _force_rehash _complete _ignored _correct _approximate _files)
fi
fi'
fi
# command for process lists, the local web server details and host completion
zstyle ':completion:*:urls' local 'www' '/var/www/' 'public_html'
# Some functions, like _apt and _dpkg, are very slow. We can use a cache in
# order to speed things up
if [[ ${GRML_COMP_CACHING:-yes} == yes ]]; then
GRML_COMP_CACHE_DIR=${GRML_COMP_CACHE_DIR:-${ZDOTDIR:-$HOME}/.cache}
if [[ ! -d ${GRML_COMP_CACHE_DIR} ]]; then
command mkdir -p "${GRML_COMP_CACHE_DIR}"
fi
zstyle ':completion:*' use-cache yes
zstyle ':completion:*:complete:*' cache-path "${GRML_COMP_CACHE_DIR}"
fi
# host completion
_etc_hosts=()
_ssh_config_hosts=()
_ssh_hosts=()
if is42 ; then
if [[ -r ~/.ssh/config ]] ; then
_ssh_config_hosts=(${${(s: :)${(ps:\t:)${${(@M)${(f)"$(<$HOME/.ssh/config)"}:#Host *}#Host }}}:#*[*?]*})
fi
if [[ -r ~/.ssh/known_hosts ]] ; then
_ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*})
fi
if [[ -r /etc/hosts ]] && [[ "$NOETCHOSTS" -eq 0 ]] ; then
: ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(grep -v '^0\.0\.0\.0\|^127\.0\.0\.1\|^::1 ' /etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}}
fi
fi
local localname
localname="$(uname -n)"
hosts=(
"${localname}"
"$_ssh_config_hosts[@]"
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
# TODO: so, why is this here?
# zstyle '*' hosts $hosts
# use generic completion system for programs not yet defined; (_gnu_generic works
# with commands that provide a --help option with "standard" gnu-like output.)
for compcom in cp deborphan df feh fetchipac gpasswd head hnb ipacsum mv \
pal stow uname ; do
[[ -z ${_comps[$compcom]} ]] && compdef _gnu_generic ${compcom}
done; unset compcom
# see upgrade function in this file
compdef _hosts upgrade
}
# Keyboard setup: The following is based on the same code, we wrote for
# debian's setup. It ensures the terminal is in the right mode, when zle is
# active, so the values from $terminfo are valid. Therefore, this setup should
# work on all systems, that have support for `terminfo'. It also requires the
# zsh in use to have the `zsh/terminfo' module built.
#
# If you are customising your `zle-line-init()' or `zle-line-finish()'
# functions, make sure you call the following utility functions in there:
#
# - zle-line-init(): zle-smkx
# - zle-line-finish(): zle-rmkx
# Use emacs-like key bindings by default:
bindkey -e
# Custom widgets:
## beginning-of-line OR beginning-of-buffer OR beginning of history
## by: Bart Schaefer <schaefer@brasslantern.com>, Bernhard Tittelbach
function beginning-or-end-of-somewhere () {
local hno=$HISTNO
if [[ ( "${LBUFFER[-1]}" == $'\n' && "${WIDGET}" == beginning-of* ) || \
( "${RBUFFER[1]}" == $'\n' && "${WIDGET}" == end-of* ) ]]; then
zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
else
zle .${WIDGET:s/somewhere/line-hist/} "$@"
if (( HISTNO != hno )); then
zle .${WIDGET:s/somewhere/buffer-or-history/} "$@"
fi
fi
}
zle -N beginning-of-somewhere beginning-or-end-of-somewhere
zle -N end-of-somewhere beginning-or-end-of-somewhere
# add a command line to the shells history without executing it
function commit-to-history () {
print -rs ${(z)BUFFER}
zle send-break
}
zle -N commit-to-history
# only slash should be considered as a word separator:
function slash-backward-kill-word () {
local WORDCHARS="${WORDCHARS:s@/@}"
# zle backward-word
zle backward-kill-word
}
zle -N slash-backward-kill-word
# a generic accept-line wrapper
# This widget can prevent unwanted autocorrections from command-name
# to _command-name, rehash automatically on enter and call any number
# of builtin and user-defined widgets in different contexts.
#
# For a broader description, see:
# <http://bewatermyfriend.org/posts/2007/12-26.11-50-38-tooltime.html>
#
# The code is imported from the file 'zsh/functions/accept-line' from
# <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>, which
# distributed under the same terms as zsh itself.
# A newly added command will may not be found or will cause false
# correction attempts, if you got auto-correction set. By setting the
# following style, we force accept-line() to rehash, if it cannot
# find the first word on the command line in the $command[] hash.