1 |
vapier 10/02/15 02:10:40 |
2 |
|
3 |
Modified: eutils.eclass |
4 |
Log: |
5 |
eshopts_{push,pop}: add support for the extended options available only via `shopt` |
6 |
|
7 |
Revision Changes Path |
8 |
1.330 eclass/eutils.eclass |
9 |
|
10 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/eutils.eclass?rev=1.330&view=markup |
11 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/eutils.eclass?rev=1.330&content-type=text/plain |
12 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/eutils.eclass?r1=1.329&r2=1.330 |
13 |
|
14 |
Index: eutils.eclass |
15 |
=================================================================== |
16 |
RCS file: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v |
17 |
retrieving revision 1.329 |
18 |
retrieving revision 1.330 |
19 |
diff -u -r1.329 -r1.330 |
20 |
--- eutils.eclass 28 Jan 2010 22:00:12 -0000 1.329 |
21 |
+++ eutils.eclass 15 Feb 2010 02:10:39 -0000 1.330 |
22 |
@@ -1,6 +1,6 @@ |
23 |
# Copyright 1999-2009 Gentoo Foundation |
24 |
# Distributed under the terms of the GNU General Public License v2 |
25 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.329 2010/01/28 22:00:12 betelgeuse Exp $ |
26 |
+# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.330 2010/02/15 02:10:39 vapier Exp $ |
27 |
|
28 |
# @ECLASS: eutils.eclass |
29 |
# @MAINTAINER: |
30 |
@@ -75,13 +75,16 @@ |
31 |
} |
32 |
|
33 |
# @FUNCTION: eshopts_push |
34 |
-# @USAGE: [options to `set`] |
35 |
+# @USAGE: [options to `set` or `shopt`] |
36 |
# @DESCRIPTION: |
37 |
# Often times code will want to enable a shell option to change code behavior. |
38 |
# Since changing shell options can easily break other pieces of code (which |
39 |
# assume the default state), eshopts_push is used to (1) push the current shell |
40 |
# options onto a stack and (2) pass the specified arguments to set. |
41 |
# |
42 |
+# If the first argument is '-s' or '-u', we assume you want to call `shopt` |
43 |
+# rather than `set` as there are some options only available via that. |
44 |
+# |
45 |
# A common example is to disable shell globbing so that special meaning/care |
46 |
# may be used with variables/arguments to custom functions. That would be: |
47 |
# @CODE |
48 |
@@ -98,9 +101,15 @@ |
49 |
# have to assume __ESHOPTS_SAVE__ isn't screwed with |
50 |
# as a `declare -a` here will reset its value |
51 |
local i=${#__ESHOPTS_SAVE__[@]} |
52 |
- __ESHOPTS_SAVE__[$i]=$- |
53 |
- [[ $# -eq 0 ]] && return 0 |
54 |
- set "$@" || die "eshopts_push: bad options to set: $*" |
55 |
+ if [[ $1 == -[su] ]] ; then |
56 |
+ __ESHOPTS_SAVE__[$i]=$(shopt -p) |
57 |
+ [[ $# -eq 0 ]] && return 0 |
58 |
+ shopt "$@" || die "eshopts_push: bad options to shopt: $*" |
59 |
+ else |
60 |
+ __ESHOPTS_SAVE__[$i]=$- |
61 |
+ [[ $# -eq 0 ]] && return 0 |
62 |
+ set "$@" || die "eshopts_push: bad options to set: $*" |
63 |
+ fi |
64 |
} |
65 |
|
66 |
# @FUNCTION: eshopts_pop |
67 |
@@ -114,8 +123,12 @@ |
68 |
[[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" |
69 |
local s=${__ESHOPTS_SAVE__[$i]} |
70 |
unset __ESHOPTS_SAVE__[$i] |
71 |
- set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" |
72 |
- set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" |
73 |
+ if [[ ${s} == "shopt -"* ]] ; then |
74 |
+ eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" |
75 |
+ else |
76 |
+ set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" |
77 |
+ set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" |
78 |
+ fi |
79 |
} |
80 |
|
81 |
# @VARIABLE: EPATCH_SOURCE |