zshrc: Do not discard the output of compinit
[grml-etc-core.git] / etc / zsh / zshrc
index cce0859..a204513 100644 (file)
 # Global Order: zshenv, zprofile, zshrc, zlogin
 ################################################################################
 
+# 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
@@ -121,6 +133,11 @@ is43(){
     return 1
 }
 
+is433(){
+    [[ $ZSH_VERSION == 4.3.<3->* || $ZSH_VERSION == <5->* ]] && return 0
+    return 1
+}
+
 #f1# Checks whether or not you're running grml
 isgrml(){
     [[ -f /etc/grml_version ]] && return 0
@@ -848,8 +865,8 @@ alias run-help >&/dev/null && unalias run-help
 zrcautoload run-help # use via 'esc-h'
 
 # completion system
-if zrcautoload compinit && compinit 2>/dev/null ; then
-    compinit 2>/dev/null || print 'Notice: no compinit available :('
+if zrcautoload compinit ; then
+    compinit || print 'Notice: no compinit available :('
 else
     print 'Notice: no compinit available :('
     function zstyle { }
@@ -1033,6 +1050,8 @@ chpwd() {
 
 # directory based profiles {{{
 
+if is433 ; then
+
 CHPWD_PROFILE='default'
 function chpwd_profiles() {
     # Say you want certain settings to be active in certain directories.
@@ -1045,10 +1064,20 @@ function chpwd_profiles() {
     # in the third part of the context, a function called chpwd_profile_grml,
     # for example, is called (if it exists).
     #
-    # If no pattern patches (read: no profile is detected) the profile is
+    # If no pattern matches (read: no profile is detected) the profile is
     # set to 'default', which means chpwd_profile_default is attempted to
     # be called.
     #
+    # A word about the context (the ':chpwd:profiles:*' stuff in the zstyle
+    # command) which is used: The third part in the context is matched against
+    # ${PWD}. That's why using a pattern such as /foo/bar(|/|/*) makes sense.
+    # Because that way the profile is detected for all these values of ${PWD}:
+    #   /foo/bar
+    #   /foo/bar/
+    #   /foo/bar/baz
+    # So, if you want to make double damn sure a profile works in /foo/bar
+    # and everywhere deeper in that tree, just use (|/|/*) and be happy.
+    #
     # The name of the detected profile will be available in a variable called
     # 'profile' in your functions. You don't need to do anything, it'll just
     # be there.
@@ -1065,6 +1094,32 @@ function chpwd_profiles() {
     #
     # The initial value for $CHPWD_PROFILE is 'default'.
     #
+    # Version requirement:
+    #   This feature requires zsh 4.3.3 or newer.
+    #   If you use this feature and need to know whether it is active in your
+    #   current shell, there are several ways to do that. Here are two simple
+    #   ways:
+    #
+    #   a) If knowing if the profiles feature is active when zsh starts is
+    #      good enough for you, you can put the following snippet into your
+    #      .zshrc.local:
+    #
+    #   (( ${+functions[chpwd_profiles]} )) && print "directory profiles active"
+    #
+    #   b) If that is not good enough, and you would prefer to be notified
+    #      whenever a profile changes, you can solve that by making sure you
+    #      start *every* profile function you create like this:
+    #
+    #   function chpwd_profile_myprofilename() {
+    #       [[ ${profile} == ${CHPWD_PROFILE} ]] && return 1
+    #       print "chpwd(): Switching to profile: $profile"
+    #     ...
+    #   }
+    #
+    #      That makes sure you only get notified if a profile is *changed*,
+    #      not everytime you change directory, which would probably piss
+    #      you off fairly quickly. :-)
+    #
     # There you go. Now have fun with that.
     local -x profile
 
@@ -1078,6 +1133,8 @@ function chpwd_profiles() {
 }
 chpwd_functions=( ${chpwd_functions} chpwd_profiles )
 
+fi # is433
+
 # }}}
 
 # {{{ display battery status on right side of prompt via running 'BATTERY=1 zsh'