Gentoo Archives: gentoo-dev

From: Zach Forrest <diatribe@××××.ca>
To: gentoo-dev@g.o
Subject: Re: [gentoo-dev] updated emerge bash completion + question
Date: Thu, 13 Dec 2001 15:13:34
Message-Id: 3C1919E5.4010701@shaw.ca
In Reply to: [gentoo-dev] updated emerge bash completion + question by Geert Bevin
1 This seems to work (see attachment).
2
3 [DISCLAIMER: I make no claims that this is pretty.]
4
5 Geert,
6
7 I think the problem with filename completion when '--usepkg' is
8 specified has to do with the suffix and glob flags when setting $setsma.
9 I made a few other changes and was having the same problem (i.e. after
10 the dirname was completed, it appended a "/" and added a space;
11 interestingly, though, was that when I backspaced, it then completed on
12 filenames properly). To get it working, I removed the '-S' flag and
13 changed the glob pattern to "*/" (only when '--usepkg' is specified, of
14 course).
15
16 Maybe one of us should mail this addition to the bash_completion
17 maintainer so it can be included in the main package. (He might also be
18 able to clean it up a bit. If you'd like to send it in, feel free to
19 point the finger at me for the hacks. ;-) )
20
21 Zach
22
23
24 Geert Bevin wrote:
25
26 > Hi all,
27 >
28 > here is a slightly updated emerge bash completion which also completes
29 > the arguments now and adds 'update' and 'system' to the completions.
30 >
31 > I have one problem though. emerge --usepkg should complete on files.
32 > Normally a command that completes on files is defined with 'complete -f
33 > command'. The bash info says that the 'comspec' builtin which is used to
34 > generate completion matches generates those matches in the same way as
35 > 'complete', however when using 'comspec -f' the filename completion
36 > stops after one path element and doesn't continue until a file has been
37 > reached. Does someone know how to work around this?
38 >
39 > Geert.
40 >
41 >
42 >
43 > ------------------------------------------------------------------------
44 >
45 > # Gentoo emerge completion.
46 > #
47 > _emerge()
48 > {
49 > local cur prev grepcmd sedcmd systemactions setsma setbig
50 >
51 > COMPREPLY=()
52 > cur=${COMP_WORDS[COMP_CWORD]}
53 > prev=${COMP_WORDS[COMP_CWORD-1]}
54 >
55 > if [ $COMP_CWORD -eq 1 ] && [[ "$cur" == -* ]]; then
56 > COMPREPLY=( $( compgen -W '--pretend \
57 > --autoclean \
58 > --usepkg \
59 > --buildpkg' | grep ^$cur ) )
60 > elif [ "$prev" == "--usepkg" ]; then
61 > COMPREPLY=( $( compgen -f $cur ) )
62 > else
63 > cd /usr/portage
64 > grepcmd="grep -E ^$cur.*"
65 > sedcmd="sed -e /CVS/d \
66 > -e /BUGS-TODO/d \
67 > -e /ChangeLog.*/d \
68 > -e /header.txt/d \
69 > -e /skel.build/d \
70 > -e /distfiles/d \
71 > -e /eclass/d \
72 > -e /files/d \
73 > -e /incoming/d \
74 > -e /packages/d \
75 > -e /profiles/d \
76 > -e /scripts/d"
77 > systemactions=$'\n'"system"$'\n'"upgrade"
78 > setsma="`compgen -S '/' -G "*" | $sedcmd`"$systemactions
79 > setbig="`compgen -G "*/*" | $sedcmd`"$systemactions
80 > if [ $cur ]; then
81 > if [ `echo $cur | grep '/'` ]; then
82 > COMPREPLY=( $( echo "$setbig" | $grepcmd ) )
83 > else
84 > if [ `echo "$setsma" | $grepcmd | grep '/' | wc -l` = 1 ]; then
85 > COMPREPLY=( $( echo "$setbig" | $grepcmd ) )
86 > else
87 > COMPREPLY=( $( echo "$setsma" | $grepcmd ) )
88 > fi
89 > fi
90 > else
91 > COMPREPLY=( $( echo "$setsma" ) )
92 > fi
93 > fi
94 >
95 > return 0
96 > }
97 > complete -F _emerge emerge
98 >

Attachments

File name MIME type
emerge.completion text/plain

Replies

Subject Author
Re: [gentoo-dev] updated emerge bash completion + question Geert Bevin <gbevin@×××××××.be>