Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-dev
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-dev@g.o
From: David Leverton <levertond@...>
Subject: Re: versionator.eclass: convert to eshopts_{push,pop}
Date: Mon, 19 Jul 2010 21:07:56 +0100
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:
Re: versionator.eclass: convert to eshopts_{push,pop}
-- Mike Frysinger
References:
versionator.eclass: convert to eshopts_{push,pop}
-- Mike Frysinger
Re: versionator.eclass: convert to eshopts_{push,pop}
-- Alec Warner
Re: versionator.eclass: convert to eshopts_{push,pop}
-- Ciaran McCreesh
Re: versionator.eclass: convert to eshopts_{push,pop}
-- Mike Frysinger
Navigation:
Lists: gentoo-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
Re: versionator.eclass: convert to eshopts_{push,pop}
Next by thread:
Re: versionator.eclass: convert to eshopts_{push,pop}
Previous by date:
Re: versionator.eclass: convert to eshopts_{push,pop}
Next by date:
Re: Over using preserve_old_lib, don't do that


Updated Jun 29, 2012

Summary: Archive of the gentoo-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.