summaryrefslogtreecommitdiff
blob: 627c0c52a215dad1973bb9b3e60a4899a78c8a15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
--- gentoo-bashcomp-1.0_beta4/src/gentoo	2005-01-12 06:26:08.380227552 -0500
+++ gentoo-bashcomp/src/gentoo	2005-01-12 06:25:05.153839424 -0500
@@ -12,7 +12,7 @@
 #
 _portdir()
 {
-	sed -n -e '/^PORTDIR=/ { s/^[^=]\+=\("[^"]\+\|\S\+\).*/\1/p ; q }' \
+	sed -n -e '/^PORTDIR=/ { s/^[^=]\+="\?\([^"]\+\|\S\+\).*/\1/p ; q }' \
 		/etc/make.conf /etc/make.globals
 }
 
@@ -272,7 +272,7 @@
 	cur=${COMP_WORDS[COMP_CWORD]}
 	if [ $COMP_CWORD -eq 1 ]; then
 		#COMPREPLY=($(compgen -o filenames -X "!*.ebuild" $cur))
-		COMPREPLY=($(compgen -o filenames))
+		COMPREPLY=($(compgen -o filenames -A file -W "--debug" -- ${cur}))
 	elif [ $COMP_CWORD -eq 2 ]; then
 		COMPREPLY=($(compgen -W 'clean compile config \
 			depend digest \
@@ -292,10 +292,27 @@
 }
 
 #
-# simple completion for Gentoo style init
+# Gentoo init.d completion
 #
-complete -W "start stop restart pause zap ineed needsme iuse usesme broken" \
-	$(for i in /etc/init.d/*; do echo ${i##*/}; done)
+
+_gentoo_style_init()
+{
+	local script="${COMP_WORDS[0]}"
+	local cur="${COMP_WORDS[$COMP_CWORD]}"
+
+	if [[ ( -f "${script}" || -h "${script}" ) && -r "${script}" ]] \
+	&& [[ "${script}" != *.sh ]] \
+	&& [[ "$(head -n 1 "${script}")" = "#!/sbin/runscript" ]]; then
+		[[ $COMP_CWORD -gt 1 ]] && return 1
+		COMPREPLY=($(opts="start stop status restart pause zap ineed needsme iuse usesme broken"; eval "$(grep '^opts=' "${script}")"; echo "${opts}"))
+		[[ "$COMPREPLY" ]] || COMPREPLY=(start stop restart zap)
+		COMPREPLY=($(compgen -W "${COMPREPLY[*]}" -- "${cur}"))
+	else
+		COMPREPLY=($(compgen -o default -- "${cur}"))
+	fi
+	return 0
+}
+complete -F _gentoo_style_init /etc/init.d/*
 
 #
 # rc completion command
@@ -730,7 +747,7 @@
 	for i in "${COMP_WORDS[@]}"; do
 		if [ $j -lt $COMP_CWORD ]; then
 			j=$((j + 1))
-			case $i in @(belongs|ch@(anges|eck)|dep@(ends|graph)|files|glsa|list|s@(ize|tats)|uses|which))
+			case $i in @(belongs|ch@(anges|eck)|dep@(ends|graph)|files|glsa|list|s@(ize|tats)|uses|which|hasuse))
 				mode=$i
 				;;
 			esac
@@ -745,11 +762,11 @@
 					COMPREPLY=($(compgen -W "-q --quiet -C --nocolor -h --help -V --version" -- $cur))
 					;;
 				*)
-					COMPREPLY=($(compgen -W "belongs changes check depends depgraph files glsa list size stats uses which" -- $cur))
+					COMPREPLY=($(compgen -W "belongs changes check depends depgraph files glsa hasuse list size stats uses which" -- $cur))
 					;;
 			esac
 			;;
-		changes|depends|glsa|stats)
+		changes|glsa|stats)
 			# These commands have not been implemented in 'equery' yet ...
 			echo -n "# Not implemented! "
 			;;
@@ -829,9 +846,32 @@
 						COMPREPLY=($(compgen -W "-U --no-useflags -l --linear" -- $cur))
 						;;
 					*)
-						# Complete on all package names.
-						_pkgname -A $cur
+						# Complete on installed package names.
+						_pkgname -I $cur
+						;;
+				esac
+			fi
+			;;
+		depends)
+			# Only complete if the previous entry on the command line is not
+			# a package name.
+			if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+				case $cur in
+					-*)
+						COMPREPLY=($(compgen -W "-a --all-packages -d --direct -D --indirect" -- $cur))
 						;;
+					*)
+						case $prev in
+						    -a|--all-packages)
+							    # Complete on all package names.							
+							    _pkgname -A $cur
+							    ;;
+						    *)
+							    # Complete on installed package names.
+							    _pkgname -I $cur
+							    ;;
+
+						esac
 				esac
 			fi
 			;;
@@ -858,12 +898,33 @@
 				esac
 			fi
 			;;
+		hasuse)
+		   	# Only complete if the previous entry on the command line is not
+			# a package name.
+			if [[ ${prev} == ${mode} || ${prev:0:1} == "-" ]]; then
+				case $cur in
+					-*)
+						COMPREPLY=($(compgen -W "-i --installed -I --exclude-installed -p --portage-tree -o --overlay" -- $cur))
+						;;
+					*)
+						local glob loc
+						glob=$(sed -n -e 's/^\([^ ]\+\) - .*$/\1/p' ${portdir}/profiles/use.desc)
+						loc=$(sed -n -e 's/^[^ ]\+:\([^ ]*\) - .*$/\1/p' ${portdir}/profiles/use.local.desc)
+						COMPREPLY=($(compgen -W "$glob $loc" -- $cur))
+						;;
+				esac
+			fi
+			;;
 	esac
 	return 0
 }
 complete -F _equery -o filenames equery
 }
 
+#
+# ekeyword completion
+#
+
 have ekeyword && {
 _ekeyword()
 {