Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] enhancement for doicon/newicon in eutils.eclass
Date: Tue, 22 May 2012 02:49:33
Message-Id: 201205212249.40692.vapier@gentoo.org
In Reply to: [gentoo-dev] enhancement for doicon/newicon in eutils.eclass by hasufell
1 On Sunday 20 May 2012 19:24:13 hasufell wrote:
2 > case ${2} in
3
4 please use $1/$2/etc... with positional variables when possible
5
6 > 16|22|24|32|36|48|64|72|96|128|192|256)
7 > size=${2}x${2};;
8 > 16x16|22x22|24x24|32x32|36x36|48x48|64x64|72x72|96x96|128x128|
9 192x192|256x256)
10 > size=${2};;
11 > scalable)
12 > size=scalable;;
13 > *)
14 > eqawarn "${2} is an unsupported icon size!"
15 > ((++ret));;
16 > esac
17
18 you can write this w/out having to duplicate two lists:
19 size=
20 if [[ $2 == "scalable" ]] ; then
21 size=$2
22 elif [[ ${2:0:2}x${2:0:2} == "$2" ]] ; then
23 size=${2:0:2}
24 case ${size} in
25 16|22|24|32|36|48|64|72|96|128|192|256) ;;
26 *) size= ;;
27 esac
28 fi
29 if [[ -z ${size} ]] ; then
30 eqawarn "${2} is an unsupported icon size!"
31 ((++ret))
32 fi
33 shift 2
34
35 shift 2;;
36 -t|--theme)
37 theme=${2}
38 shift 2;;
39 -c|--context)
40 context=${2}
41 shift 2;;
42 *)
43 > if [[ -z ${size} ]] ; then
44 > dir=/usr/share/pixmaps
45 > else
46 > dir=/usr/share/icons/${theme}/${size}/${context}
47 > fi
48 >
49 > insinto "${dir}"
50
51 considering you only use $dir once, you could just call `insinto` directly on
52 the path rather than using the dir variable at all
53
54 > elif [[ -d ${1} ]] ; then
55 > for i in "${1}"/*.{png,svg} ; do
56 > doins "${i}"
57 > ((ret+=$?))
58 > done
59
60 why loop ? `doins "${1}"/*.{png,svg}` works just as well
61
62 you probably want to enable nullglobbing here, otherwise this will cause
63 problems if you try to doicon on a dir that contains just svg.
64
65 also, what about other file types ? people install xpm, svgz, gif, and other
66 file types ...
67
68 > exit ${ret}
69
70 bash masks error codes to [0..255], so all the ret updates should probably be
71 changed to just: ret=1
72
73 after all, i doubt anyone cares how many errors there were, just that one
74 occurred. and while you're here, might want to make it auto die on failure
75 like we've done with all our other helpers.
76 -mike

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies