Gentoo Archives: gentoo-dev

From: Fabian Groffen <grobian@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Re: [gentoo-commits] gentoo-x86 commit in eclass: gnustep-base.eclass
Date: Fri, 05 Oct 2007 18:24:16
Message-Id: 20071005181215.GK15541@gentoo.org
In Reply to: [gentoo-dev] Re: [gentoo-commits] gentoo-x86 commit in eclass: gnustep-base.eclass by Donnie Berkholz
1 On 05-10-2007 11:03:56 -0700, Donnie Berkholz wrote:
2 > > - echo '#!/usr/bin/env bash' > "${T}"/${cfile}
3 > > - echo "echo Applying ${P} default configuration ..." >> "${T}"/${cfile}
4 > > + cat << EOF > "${T}"/${cfile}
5 > > +#!/usr/bin/env bash
6 > > +gnustep_append_default() {
7 > > + if [[ -z \$1 || -z \$2 || -z \$3 ]]; then
8 > > + echo "warning: invalid script invocation"
9 > > + return
10 > > + fi
11 > > + dom=\$1
12 > > + key=\$2
13 > > + val=\$3
14 > > + cur=\$(defaults read \${dom} \${key}) 2> /dev/null
15 > > + if [[ -z \$cur ]] ; then
16 > > + echo " * setting \${dom} \${key}"
17 > > + defaults write \${dom} \${key} "( \${val} )"
18 > > + elif [[ \${cur} != *\${val}* ]] ; then
19 > > + echo " * adding \${val} to \${dom} \${key}"
20 > > + echo "\${cur%)\'}, \"\${val}\" )'" | defaults write
21 > > + else
22 > > + echo " * \${val} already present in \${dom} \${key}"
23 > > + fi
24 > > +}
25 > > +
26 > > +gnustep_set_default() {
27 > > + if [[ -z \$1 || -z \$2 || -z \$3 ]]; then
28 > > + echo "warning: invalid script invocation"
29 > > + return
30 > > + fi
31 > > + dom=\$1
32 > > + key=\$2
33 > > + val=\$3
34 > > + echo " * setting \${dom} \${key}"
35 > > + defaults write \${dom} \${key} \${val}
36 > > +}
37 > > +
38 > > +echo "Applying ${P} default configuration ..."
39 > > +EOF
40 > > +
41 >
42 > There's gotta be a better way of doing this. All those escapes really
43 > start to obfuscate the code. Anyone got a better idea?
44
45 If you have it, let us know. We write bash code to a file here to be
46 executed lateron.
47 To give you some background; we first used separate echo statements, and
48 found that this was the most readable form. One option may be using an
49 echo '
50 code
51 code ${bla}
52 '
53
54 Honestly I forgot why we didn't do this.
55
56
57 --
58 Fabian Groffen
59 Gentoo on a different level
60 --
61 gentoo-dev@g.o mailing list