X-Git-Url: https://git.grml.org/?a=blobdiff_plain;f=etc%2Fzsh%2Fzshrc;h=cf15db68a6feafc0ee5bb9bcc913366ed5651739;hb=c0fd246d36df74a7f36b8c3ce25a2e2d6250a4ed;hp=7edb9765fc389737013a87d9e3562f4a81e23661;hpb=b78fe008bd17e50641a9598d263208e3845fdba1;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 7edb976..cf15db6 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -92,6 +92,10 @@ fi # }}} # setting some default values {{{ + +# load .zshrc.pre to give the user the chance to overwrite the defaults +[[ -r ${HOME}/.zshrc.pre ]] && source ${HOME}/.zshrc.pre + NOCOR=${NOCOR:-0} NOMENU=${NOMENU:-0} NOPRECMD=${NOPRECMD:-0} @@ -2841,6 +2845,63 @@ bk() { # exec $SHELL $SHELL_ARGS "$@" # } +#f1# grep for patterns in grml's zsh setup +zg() { +#{{{ + LANG=C perl -e ' + +sub usage { + print "usage: zg -[anr] \n"; + print " Search for patterns in grml'\''s zshrc.\n"; + print " zg takes no or exactly one option plus a non empty pattern.\n\n"; + print " options:\n"; + print " -- no options (use if your pattern starts in with a dash.\n"; + print " -a search for the pattern in all code regions\n"; + print " -n search for the pattern in non-root code only\n"; + print " -r search in code for everyone (also root) only\n\n"; + print " The default is -a for non-root users and -r for root.\n\n"; + print " If you installed the zshrc to a non-default locations (ie *NOT*\n"; + print " in /etc/zsh/zshrc) do: export GRML_ZSHRC=\$HOME/.zshrc\n"; + print " ...in case you copied the file to that location.\n\n"; + exit 1; +} + +if ($ENV{GRML_ZSHRC} ne "") { + $RC = $ENV{GRML_ZSHRC}; +} else { + $RC = "/etc/zsh/zshrc"; +} + +usage if ($#ARGV < 0 || $#ARGV > 1); +if ($> == 0) { $mode = "allonly"; } +else { $mode = "all"; } + +$opt = $ARGV[0]; +if ($opt eq "--") { shift; } +elsif ($opt eq "-a") { $mode = "all"; shift; } +elsif ($opt eq "-n") { $mode = "nonroot"; shift; } +elsif ($opt eq "-r" ) { $mode = "allonly"; shift; } +elsif ($opt =~ m/^-/ || $#ARGV > 0) { usage(); } + +$pattern = $ARGV[0]; +usage() if ($pattern eq ""); + +open FH, "<$RC" or die "zg: Could not open $RC: $!\n"; +while ($line = ) { + chomp $line; + if ($line =~ m/^#:grep:marker:for:mika:/) { $markerfound = 1; next; } + next if ($mode eq "nonroot" && markerfound == 0); + break if ($mode eq "allonly" && markerfound == 1); + print $line, "\n" if ($line =~ /$pattern/); +} +close FH; +exit 0; + + ' -- "$@" +#}}} + return $? +} + # }}} # log out? set timeout in seconds {{{ @@ -2872,56 +2933,18 @@ fi #@# split functions-search 8 ## }}} -# add variable to be able to check whether the file has been read {{{ -ZSHRC_GLOBAL_HAS_BEEN_READ=1 -# }}} - -### -### non-root (EUID == 0) code below +#:grep:marker:for:mika: :-) +### non-root (EUID != 0) code below ### (( GRML_ALWAYS_LOAD_ALL == 0 )) && (( $EUID == 0 )) && return 0 -# source ~/.zshrc.global {{{ - -# see /etc/zsh/zshrc for some general settings -# If you don't have write permissions to /etc/zsh/zshrc on your own -# copy the file to your $HOME as /.zshrc.global and we source it: - -# Note, that xsource() is defined in the global file, so here, -# we will have to do the sourcing manually for once: - -[[ -z "$ZSHRC_GLOBAL_HAS_BEEN_READ" ]] \ -&& [[ -r "${HOME}/.zshrc.global" ]] \ -&& source "${HOME}/.zshrc.global" -# }}} - -# check whether global file has been read {{{ -if [[ -z "$ZSHRC_GLOBAL_HAS_BEEN_READ" ]] ; then - print 'Warning: global zsh config has not been read.' >&2 - print ' prepare for possible errors!' >&2 - print '' >&2 - print 'See our refcard for info on how to get the complete configuration:' >&2 - print ' ' >&2 -fi -# }}} - # autoloading stuff {{{ # associate types and extensions (be aware with perl scripts and anwanted behaviour!) # check_com zsh-mime-setup || { autoload zsh-mime-setup && zsh-mime-setup } # alias -s pl='perl -S' # }}} -# completion system {{{ -# just make sure it is loaded in this file too -# TODO: is this *really* needed? compsys should be run in the global zshrc already. -check_com compinit || { autoload -U compinit && compinit } -# }}} - -# make sure isgrmlsmall is defined {{{ -check_com isgrmlsmall || function isgrmlsmall () { return 1 } -# }}} - # variables {{{ # set terminal property (used e.g. by msgid-chooser)