1 |
On Friday 16 December 2011 02:29:25 Steven J Long wrote: |
2 |
> Mike Frysinger wrote: |
3 |
> > + [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments" |
4 |
> |
5 |
> ((..)) is quicker than [[ .. ]] for arithmetic stuff, and usually easier to |
6 |
> grok swiftly. |
7 |
|
8 |
i'm not used to using this style, so for now i think i'll keep the existing |
9 |
(and it's more common in Gentoo atm, or at least in the code base i sample, |
10 |
ignoring the obvious selection bias). i'll noodle on this though and see if i |
11 |
can't convince myself to start using this and live migrating code in the tree. |
12 |
|
13 |
> (($#)) || die .. is how this would normally be done. |
14 |
|
15 |
i think this is a little less clear, but considering some of the |
16 |
[advanced/complicated] bash code i've written elsewhere in Gentoo, maybe |
17 |
that's a specious argument ... |
18 |
|
19 |
> > eshopts_push() { |
20 |
> > if [[ $1 == -[su] ]] ; then |
21 |
> > - __ESHOPTS_SAVE__[$i]=$(shopt -p) |
22 |
> > + estack_push eshopts "$(shopt -p)" |
23 |
> > [[ $# -eq 0 ]] && return 0 |
24 |
> |
25 |
> I'm not sure how this will ever match, given that $1 has been checked |
26 |
> above? (($#==1)) && return 0 # if that applies (might be a 'bug'.) |
27 |
|
28 |
the larger idea when i first wrote eshopts_{push,pop} was to not do any arg |
29 |
parsing at all, but then i hit the issue that `shopt` and `set` options are |
30 |
like a venn diagram -- a lot of common stuff, but each also has unique options. |
31 |
so i had to introduce a little arg parsing to make it actually work. and the |
32 |
duplicated/forked code in the sub-branches were kept as similar as possible to |
33 |
(hopefully) make things simpler to read at a glance. but that means sharper |
34 |
eyes notice a code branch which can never be hit as you've highlighted here. |
35 |
|
36 |
as for the $#==1 check at the top, i don't want these helpers to require |
37 |
arguments as it would prevent more creative uses. such as: |
38 |
eshopts_push |
39 |
. ./some-script-from-a-package |
40 |
eshopts_pop |
41 |
but maybe that's not a big deal ... |
42 |
-mike |