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
1 On 19 July 2010 20:43, Mike Frysinger <vapier@g.o> wrote:
2 > On Monday, July 19, 2010 03:38:39 Ciaran McCreesh wrote:
3 >> On Sun, 18 Jul 2010 20:17:45 -0700 Alec Warner wrote:
4 >> > Can we do away with all the extra foo && return bullshit and just set
5 >> > a trap?
6 >> >
7 >> > trap "eshopts pop" RETURN
8 >> >
9 >> >  ?
10 >>
11 >> That strikes me as a horribly fragile way of doing things that's bound
12 >> to come back and screw things up at some point...
13 >
14 > nifty in theory, but i'm inclined to agree with Ciaran
15 > -mike
16
17 Is something like the below function too hideous (not massively
18 tested, but it seems to work)? Usage is something like:
19
20 [dleverton@shiny-one ~] $ foo() { shopt -p extglob; }
21 [dleverton@shiny-one ~] $ eshopts_need foo -s extglob
22 [dleverton@shiny-one ~] $ shopt -p extglob
23 shopt -u extglob
24 [dleverton@shiny-one ~] $ foo
25 shopt -s extglob
26 [dleverton@shiny-one ~] $ shopt -p extglob
27 shopt -u extglob
28
29 eshopts_need() {
30 [[ $# -ge 1 ]] || die "eshopts_need needs at least one argument"
31 local func=$1
32 shift
33 local opts=( "${@}" )
34 if [[ $1 == -[su] ]] ; then
35 eval "_eshopts_need_shopt_$(declare -f $func)"
36 eval "$func() {
37 local old=\$(shopt -p)
38 $(declare -p opts)
39 shopt \"\${opts[@]}\"
40 _eshopts_need_shopt_$func \"\$@\"
41 local status=\$?
42 eval \"\$old\"
43 return \$status
44 }"
45 else
46 eval "_eshopts_need_set_$(declare -f $func)"
47 eval "$func() {
48 local old=\$-
49 $(declare -p opts)
50 set \"\${opts[@]}\"
51 _eshopts_need_set_$func \"\$@\"
52 local status=\$?
53 set +\$-
54 set -\$old
55 return \$status
56 }"
57 fi
58 }

Replies

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