X-Git-Url: https://git.grml.org/?a=blobdiff_plain;ds=sidebyside;f=etc%2Fzsh%2Fzshrc;h=d50f72c3becc057a4eed46759ecdbaa390fe6adb;hb=fc0aa71a93f54482517a96e01c200ffbdad825e5;hp=b864606487e000d6ed201eb622e704e217c4768a;hpb=bd6fb996af3e45ef0d3b403965027dc2d708d5ff;p=grml-etc-core.git diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index b864606..d50f72c 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -3,7 +3,7 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Mon Feb 11 18:00:55 CET 2008 [mika] +# Latest change: Sam Mai 17 22:52:34 CEST 2008 [mika] ################################################################################ # This file is sourced only for interactive shells. It # should contain commands to set up aliases, functions, @@ -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)"$( 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 @@ -165,6 +258,29 @@ salias() { return 0 } +# a "print -l ${(u)foo}"-workaround for pre-4.2.0 shells +# usage: uprint foo +# Where foo is the *name* of the parameter you want printed. +# Note that foo is no typo; $foo would be wrong here! +if ! is42 ; then + uprint () { + local -a u + local w + local parameter=${1} + + if [[ -z ${parameter} ]] ; then + printf 'usage: uprint \n' + return 1 + fi + + for w in ${(P)parameter} ; do + [[ -z ${(M)u:#${w}} ]] && u=( ${u} ${w} ) + done + + builtin print -l ${u} + } +fi + # Check if we can read given files and source those we can. xsource() { if (( ${#argv} < 1 )) ; then @@ -226,9 +342,17 @@ 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" + xsource "/etc/default/locale" fi export LANG=${LANG:-en_US.iso885915} @@ -267,104 +391,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)"$( 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# @@ -928,15 +954,21 @@ isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history # dirstack handling {{{ -DIRSTACKSIZE=20 -if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then - dirstack=( ${(f)"$(< ~/.zdirs)"} ) +DIRSTACKSIZE=${DIRSTACKSIZE:-20} +DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs} + +if [[ -f ${DIRSTACKFILE} ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then + dirstack=( ${(f)"$(< $DIRSTACKFILE)"} ) # "cd -" won't work after login by just setting $OLDPWD, so [[ -d $dirstack[0] ]] && cd $dirstack[0] && cd $OLDPWD fi chpwd() { - builtin print -l ${(u)dirstack} >! ~/.zdirs + if is42 ; then + builtin print -l ${(u)dirstack} >! ${DIRSTACKFILE} + else + uprint dirstack >! ${DIRSTACKFILE} + fi } # }}} @@ -1987,6 +2019,7 @@ for color in BLUE RED GREEN CYAN WHITE ; unset $color # source another config file if present {{{ xsource "/etc/zsh/zshrc.local" +xsource "${HOME}/.zshenv" # }}} # "persistent history" {{{