[packages/bash-completion] builder-completion: try to parse .spec from commandline

glen glen at pld-linux.org
Sun Aug 12 20:15:49 CEST 2012


commit b6d1f536cf07f2526efdc35a275f0c2f973ce8a0
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sun Aug 12 21:15:23 2012 +0300

    builder-completion: try to parse .spec from commandline

 builder.bash-completion | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/builder.bash-completion b/builder.bash-completion
index eb80e88..da7f04c 100644
--- a/builder.bash-completion
+++ b/builder.bash-completion
@@ -1,5 +1,21 @@
 # PLD Linux builder(1) script completion
 
+# get active spec file from commandline
+# caller should make $spec local variable
+# TODO: it gets it wrong if some option arg is found before spec itself
+_builder_get_spec()
+{
+	local i
+	spec=
+	for (( i=1; i < ${#words[@]}-1; i++ )); do
+		if [[ ${words[i]} != -* ]]; then
+			spec=${words[i]}
+			break
+		fi
+	done
+	[[ ! -f $spec ]] && return 0
+}
+
 _builder()
 {
 	local cur prev words cword
@@ -7,12 +23,14 @@ _builder()
 
 	case $prev in
 	-r)
-		local spec=*.spec
+		local spec
+		_builder_get_spec
 		COMPREPLY=( $( compgen -W '$( git tag )' -- "$cur" ) )
 		return 0
 		;;
 	--with|--without)
-		local spec=*.spec
+		local spec
+		_builder_get_spec
 		$1 -nn -ncs --show-avail-bconds $spec
 		return 0
 		;;


More information about the pld-cvs-commit mailing list