From 892d64f3a2883ef700e573b425f1b8b12dd0d079 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Wed, 26 Mar 2008 20:21:48 +0100 Subject: [PATCH] Adding print -l ${(u)foobar} workaround for pre-4.2.0 shells This also enabled the dirstack magic for such shells again. Also, this patch only sets defaults for DIRSTACKSIZE and introduces a new variable DIRSTACKFILE (which defaults to ~/.zdirs). That way you may change these defaults in your .zshenv for example. --- debian/changelog | 6 ++++++ etc/zsh/zshrc | 41 ++++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 595693f..7f0972c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +grml-etc-core (0.3.51) unstable; urgency=low + + * zshrc: Add persistent dirstack support for shells older than 4.2.0 + + -- Frank Terbeck Wed, 26 Mar 2008 13:57:12 +0100 + grml-etc-core (0.3.50) unstable; urgency=low [ Michael Prokop ] diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index b414c93..9a2a6c8 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -258,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 @@ -931,21 +954,21 @@ isgrmlcd && SAVEHIST=1000 || SAVEHIST=10000 # useful for setopt append_history # dirstack handling {{{ -# TODO: the is42 tests are in place, because (u) requires at least 4.2.0 -# of zsh. We also disable loading potentielly old .zdir files when -# starting a pre-4.2.0 zsh. -# Implementing a workaround-(u) for older shells is the obvious -# solution here, if we want this for all supported shells. +DIRSTACKSIZE=${DIRSTACKSIZE:-20} +DIRSTACKFILE=${DIRSTACKFILE:-${HOME}/.zdirs} -DIRSTACKSIZE=20 -if is42 && [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]] ; then - dirstack=( ${(f)"$(< ~/.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() { - is42 && builtin print -l ${(u)dirstack} >! ~/.zdirs + if is42 ; then + builtin print -l ${(u)dirstack} >! ${DIRSTACKFILE} + else + uprint dirstack >! ${DIRSTACKFILE} + fi } # }}} -- 2.1.4