Gentoo Archives: gentoo-dev

From: David Leverton <levertond@××××××××××.com>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] versionator.eclass: convert to eshopts_{push,pop}
Date: Mon, 19 Jul 2010 20:08:18
Message-Id: AANLkTildI8JFCju8rJS_YQEiuQiL1SHiknXrDaUn964e@mail.gmail.com
In Reply to: Re: [gentoo-dev] versionator.eclass: convert to eshopts_{push,pop} by Mike Frysinger
On 19 July 2010 20:43, Mike Frysinger <vapier@g.o> wrote:
> On Monday, July 19, 2010 03:38:39 Ciaran McCreesh wrote: >> On Sun, 18 Jul 2010 20:17:45 -0700 Alec Warner wrote: >> > Can we do away with all the extra foo && return bullshit and just set >> > a trap? >> > >> > trap "eshopts pop" RETURN >> > >> >  ? >> >> That strikes me as a horribly fragile way of doing things that's bound >> to come back and screw things up at some point... > > nifty in theory, but i'm inclined to agree with Ciaran > -mike
Is something like the below function too hideous (not massively tested, but it seems to work)? Usage is something like: [dleverton@shiny-one ~] $ foo() { shopt -p extglob; } [dleverton@shiny-one ~] $ eshopts_need foo -s extglob [dleverton@shiny-one ~] $ shopt -p extglob shopt -u extglob [dleverton@shiny-one ~] $ foo shopt -s extglob [dleverton@shiny-one ~] $ shopt -p extglob shopt -u extglob eshopts_need() { [[ $# -ge 1 ]] || die "eshopts_need needs at least one argument" local func=$1 shift local opts=( "${@}" ) if [[ $1 == -[su] ]] ; then eval "_eshopts_need_shopt_$(declare -f $func)" eval "$func() { local old=\$(shopt -p) $(declare -p opts) shopt \"\${opts[@]}\" _eshopts_need_shopt_$func \"\$@\" local status=\$? eval \"\$old\" return \$status }" else eval "_eshopts_need_set_$(declare -f $func)" eval "$func() { local old=\$- $(declare -p opts) set \"\${opts[@]}\" _eshopts_need_set_$func \"\$@\" local status=\$? set +\$- set -\$old return \$status }" fi }

Replies

Subject Author
Re: [gentoo-dev] versionator.eclass: convert to eshopts_{push,pop} Mike Frysinger <vapier@g.o>