Move version and system checking functions up in the file
authorFrank Terbeck <ft@grml.org>
Wed, 26 Mar 2008 19:21:26 +0000 (20:21 +0100)
committerFrank Terbeck <ft@grml.org>
Wed, 26 Mar 2008 19:21:26 +0000 (20:21 +0100)
I will need at least one of these earlier in the file and I do not see
why not to define these almost as early as possible.

etc/zsh/zshrc

index 0a15eb2..b414c93 100644 (file)
@@ -92,6 +92,99 @@ if [[ -n $ZSH_PROFILE_RC ]] ; then
 fi
 # }}}
 
+# {{{ check for version/system
+# check for versions (compatibility reasons)
+is4(){
+    [[ $ZSH_VERSION == <4->* ]] && return 0
+    return 1
+}
+
+is41(){
+    [[ $ZSH_VERSION == 4.<1->* || $ZSH_VERSION == <5->* ]] && return 0
+    return 1
+}
+
+is42(){
+    [[ $ZSH_VERSION == 4.<2->* || $ZSH_VERSION == <5->* ]] && return 0
+    return 1
+}
+
+is43(){
+    [[ $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
+    return 1
+}
+
+#f1# Checks whether or not you're running grml
+isgrml(){
+    [[ -f /etc/grml_version ]] && return 0
+    return 1
+}
+
+#f1# Checks whether or not you're running a grml cd
+isgrmlcd(){
+    [[ -f /etc/grml_cd ]] && return 0
+    return 1
+}
+
+if isgrml ; then
+#f1# Checks whether or not you're running grml-small
+    isgrmlsmall() {
+        [[ ${${${(f)"$(</etc/grml_version)"}%% *}##*-} == 'small' ]] && return 0 ; return 1
+    }
+else
+    isgrmlsmall() { return 1 }
+fi
+
+#f1# are we running within an utf environment?
+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 && 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
+
+# }}}
+
 # utility functions {{{
 # this function checks if a command exists and returns either true
 # or false. This avoids using 'which' and 'whence', which will
@@ -226,6 +319,14 @@ function zrcautoload() {
 
 #}}}
 
+# 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"
@@ -267,104 +368,6 @@ fi
 unset xof
 # }}}
 
-# {{{ check for version/system
-# check for versions (compatibility reasons)
-is4(){
-    [[ $ZSH_VERSION == <4->* ]] && return 0
-    return 1
-}
-
-is41(){
-    [[ $ZSH_VERSION == 4.<1->* || $ZSH_VERSION == <5->* ]] && return 0
-    return 1
-}
-
-is42(){
-    [[ $ZSH_VERSION == 4.<2->* || $ZSH_VERSION == <5->* ]] && return 0
-    return 1
-}
-
-is43(){
-    [[ $ZSH_VERSION == 4.<3->* || $ZSH_VERSION == <5->* ]] && return 0
-    return 1
-}
-
-# Use is-at-least, if you need to check more precisely.
-# 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 }
-
-#f1# Checks whether or not you're running grml
-isgrml(){
-    [[ -f /etc/grml_version ]] && return 0
-    return 1
-}
-
-#f1# Checks whether or not you're running a grml cd
-isgrmlcd(){
-    [[ -f /etc/grml_cd ]] && return 0
-    return 1
-}
-
-if isgrml ; then
-#f1# Checks whether or not you're running grml-small
-    isgrmlsmall() {
-        [[ ${${${(f)"$(</etc/grml_version)"}%% *}##*-} == 'small' ]] && return 0 ; return 1
-    }
-else
-    isgrmlsmall() { return 1 }
-fi
-
-#f1# are we running within an utf environment?
-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 && 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
-
-# }}}
-
 # {{{ set some variables
 if check_com -c vim ; then
 #v#