Disable the skel check if running off a cd
[grml-etc-core.git] / etc / zsh / zshrc
index 354fe82..9f3d87a 100644 (file)
@@ -1,4 +1,4 @@
-# Filename:      zshrc
+# 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/
@@ -91,53 +91,9 @@ if [[ $ZSH_PROFILE_RC -gt 0 ]] ; then
 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}
-BATTERY=${BATTERY:-0}
-GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
-GRML_ALWAYS_LOAD_ALL=${GRML_ALWAYS_LOAD_ALL:-0}
-GRML_WARN_SKEL=${GRML_WARN_SKEL:-1}
-
-if (( GRML_WARN_SKEL != 0 )) ; then
-    printf '
-Dear user,
-
-You updated grml'\''s zshrc which brings a major change.
-The configuration is kept only in one file, being the global zshrc.
-In the past, the configuration was split in two files, with the
-second file being the .zshrc file from /etc/skel.
-
-If you have a .zshrc file in your home directory that originally
-came from the skel directory, please remove it. This is also the case
-if you followed earlier instructions from the grml-zsh-refcard or
-from <http://grml.org/console> on non-grml systems.
-
-Please see the current grml-zsh-refcard for updated installation
-information. In short, you don'\''t want a .zshrc.global file. Install
-the global zshrc to ~/.zshrc and be done.
-
-If you need changes to the configuration, use ~/.zshrc.pre and
-~/.zshrc.local.
-
-To remove this warning execute '\''grml_do_not_warn_skel'\''.
-
-' | more
-
-function grml_do_not_warn_skel() {
-    printf '# Do not warn about old skel dot-files anymore\n' >>! ~/.zshrc.pre
-    printf 'GRML_WARN_SKEL=0\n' >>! ~/.zshrc.pre
-}
-
-fi
-
-# }}}
-
 # {{{ check for version/system
 # check for versions (compatibility reasons)
 is4(){
@@ -239,6 +195,118 @@ if ! [[ ${ZSH_VERSION} == 3.1.<7->*      \
     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() {
+    setopt local_options extended_glob
+    local fdir ffile
+    local -i ffound
+
+    ffile=${1}
+    (( found = 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
+}
+
+# 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 || is-at-least() { return 1 }
+
+# }}}
+
+# setting some default values {{{
+
+NOCOR=${NOCOR:-0}
+NOMENU=${NOMENU:-0}
+NOPRECMD=${NOPRECMD:-0}
+BATTERY=${BATTERY:-0}
+GRMLSMALL_SPECIFIC=${GRMLSMALL_SPECIFIC:-1}
+GRML_ALWAYS_LOAD_ALL=${GRML_ALWAYS_LOAD_ALL:-0}
+
+if isgrmlcd ; then
+    GRML_WARN_SKEL=${GRML_WARN_SKEL:-0}
+else
+    GRML_WARN_SKEL=${GRML_WARN_SKEL:-1}
+fi
+
+if (( GRML_WARN_SKEL != 0 )) ; then
+
+function grml_warn_skel_main() {
+    printf '
+Dear user,
+
+You updated grml'\''s zshrc which brings a major change.
+The configuration is kept only in one file, being the global zshrc.
+In the past, the configuration was split in two files, with the
+second file being the .zshrc file from /etc/skel.
+
+If you have a .zshrc file in your home directory that originally
+came from the skel directory, please remove it. This is also the case
+if you followed earlier instructions from the grml-zsh-refcard or
+from <http://grml.org/console/> on non-grml systems.
+
+Please see the current grml-zsh-refcard (available at
+<http://grml.org/zsh/>) for updated installation information. In short,
+you don'\''t want a .zshrc.global file. Install the global zshrc to
+~/.zshrc and be done.
+
+If you need changes to the configuration, use ~/.zshrc.pre and
+~/.zshrc.local.
+
+'
+}
+
+function grml_warn_skel_remove() {
+    printf 'To remove this warning execute '\''grml_do_not_warn_skel'\''.\n\n'
+}
+
+function grml_do_not_warn_skel() {
+    printf '# Do not warn about old skel dot-files anymore\n' >>! ~/.zshrc.pre
+    printf 'GRML_WARN_SKEL=0\n' >>! ~/.zshrc.pre
+}
+
+# let's try to guess how the user uses us.
+if is-at-least 4.3.7 ; then
+    # funcsourcetrace requires at least version 4.3.7 of zsh.
+    GRML_SRC_FILE="${${funcsourcetrace[1]}%:*}"
+
+    grml_warn_skel_main
+    case ${GRML_SRC_FILE} in
+        (${HOME}/.zshrc.global)
+            grml_warn_skel_remove
+            printf '\nIt looks like you copied the grml zshrc to '\''~/.zshrc.global'\''.\n'
+            printf 'Nowadays you just copy the global zshrc to '\''~/.zshrc'\'' to use\n'
+            printf 'it on a non-grml-system.\n'
+            ;;
+        (${HOME}/.zshrc)
+            printf '\nIt looks like you copied the grml zshrc to '\''~/.zshrc'\''.\n'
+            printf 'We'\''ll disable this warning automatically for later sessions.\n'
+            grml_do_not_warn_skel
+            ;;
+        (*)
+            grml_do_not_warn_skel
+            ;;
+    esac
+else
+    grml_warn_skel_main
+    grml_warn_skel_remove
+fi
+
+unfunction grml_warn_skel_remove grml_warn_skel_main
+
+fi # GRML_WARN_SKEL
+
 # }}}
 
 # utility functions {{{
@@ -375,37 +443,8 @@ xunfunction() {
     return 0
 }
 
-# autoload wrapper - use this one instead of autoload directly
-function zrcautoload() {
-    setopt local_options extended_glob
-    local fdir ffile
-    local -i ffound
-
-    ffile=${1}
-    (( found = 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
-}
-
 #}}}
 
-# 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 || is-at-least() { return 1 }
-
-# }}}
-
 # locale setup {{{
 if [[ -z "$LANG" ]] ; then
    xsource "/etc/default/locale"
@@ -479,12 +518,6 @@ fi
 # do Fink setup on darwin
 isdarwin && xsource /sw/bin/init.sh
 
-# set width of man pages to 80 for more convenient reading
-# export MANWIDTH=${MANWIDTH:-80}
-
-# Search path for the cd command
-#  cdpath=(.. ~)
-
 # completion functions go to /etc/zsh/completion.d
 # function files may be put into /etc/zsh/functions.d, from where they
 # will be automatically autoloaded.
@@ -2025,12 +2058,14 @@ hash -d www=/var/www
 # }}}
 
 # {{{ some aliases
-if [[ $UID -eq 0 ]] ; then
-    [[ -r /etc/grml/screenrc ]] && alias screen='/usr/bin/screen -c /etc/grml/screenrc'
-elif [[ -r $HOME/.screenrc ]] ; then
-    alias screen="/usr/bin/screen -c $HOME/.screenrc"
-else
-    [[ -r /etc/grml/screenrc_grml ]] && alias screen='/usr/bin/screen -c /etc/grml/screenrc_grml'
+if check_com -c screen ; then
+    if [[ $UID -eq 0 ]] ; then
+        [[ -r /etc/grml/screenrc ]] && alias screen="${commands[screen]} -c /etc/grml/screenrc"
+    elif [[ -r $HOME/.screenrc ]] ; then
+        alias screen="${commands[screen]} -c $HOME/.screenrc"
+    else
+        [[ -r /etc/grml/screenrc_grml ]] && alias screen="${commands[screen]} -c /etc/grml/screenrc_grml"
+    fi
 fi
 
 # do we have GNU ls with color-support?
@@ -2312,7 +2347,7 @@ limit -s
 # {{{ completion system
 
 # called later (via is4 && grmlcomp)
-# notice: use 'zstyle' for getting current settings
+# 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
 grmlcomp() {
     # TODO: This could use some additional information
@@ -2401,6 +2436,9 @@ grmlcomp() {
     zstyle ':completion:*:manuals.*'  insert-sections   true
     zstyle ':completion:*:man:*'      menu yes select
 
+    # provide .. as a completion
+    zstyle ':completion:*' special-dirs ..
+
     # run rehash on completion so new installed program are found automatically:
     _force_rehash() {
         (( CURRENT == 1 )) && rehash
@@ -3265,7 +3303,7 @@ if [[ -r ~/.terminfo/m/mostlike ]] ; then
 fi
 
 # d():Copyright 2005 Nikolai Weibull <nikolai@bitwi.se>
-# notice: option AUTO_PUSHD has to be set
+# note: option AUTO_PUSHD has to be set
 #f5# Jump between directories
 d() {
     emulate -L zsh
@@ -3529,7 +3567,7 @@ status() {
     print ""
     print "Date..: "$(date "+%Y-%m-%d %H:%M:%S")""
     print "Shell.: Zsh $ZSH_VERSION (PID = $$, $SHLVL nests)"
-    print "Term..: $TTY ($TERM), $BAUD bauds, $COLUMNS x $LINES cars"
+    print "Term..: $TTY ($TERM), ${BAUD:+$BAUD bauds, }$COLUMNS x $LINES cars"
     print "Login.: $LOGNAME (UID = $EUID) on $HOST"
     print "System: $(cat /etc/[A-Za-z]*[_-][rv]e[lr]*)"
     print "Uptime:$(uptime)"
@@ -3802,16 +3840,21 @@ mkmaildir() {
     mkdir -p ${root}/${subdir}/{cur,new,tmp}
 }
 
-# xtrename() rename xterm from within GNU-screen
+#f5# Change the xterm title from within GNU-screen
 xtrename() {
-    if [[ -z ${DISPLAY} ]] ; then
-        printf 'xtrename only makes sense in X11.\n'
-        return 1
+    if [[ ${1} != "-f" ]] ; then
+        if [[ -z ${DISPLAY} ]] ; then
+            printf 'xtrename only makes sense in X11.\n'
+            return 1
+        fi
+    else
+        shift
     fi
     if [[ -z ${1} ]] ; then
-        printf 'usage: xtrename() "title for xterm"\n'
+        printf 'usage: xtrename [-f] "title for xterm"\n'
         printf '  renames the title of xterm from _within_ screen.\n'
-        printf '  Also works without screen.\n'
+        printf '  also works without screen.\n'
+        printf '  will not work if DISPLAY is unset, use -f to override.\n'
         return 0
     fi
     print -n "\eP\e]0;${1}\C-G\e\\"