summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Gnatenko <i.gnatenko.brain@gmail.com>2014-06-18 15:11:34 +0400
committerIgor Gnatenko <i.gnatenko.brain@gmail.com>2014-06-18 15:11:34 +0400
commitf5e5d1af18df64b5e088d56a64e180f4a3110c15 (patch)
tree9c5628b74403635fe8d2c399f77ece2917e2cfd5
parenta92411b03c51358baf96a8bcb322e9bd1bfda6b7 (diff)
downloadappstream-glib-f5e5d1af18df64b5e088d56a64e180f4a3110c15.tar.gz
bash-completion: don't allow more than needed options for commands
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
-rw-r--r--data/appstream-util25
1 files changed, 16 insertions, 9 deletions
diff --git a/data/appstream-util b/data/appstream-util
index 5188006..70dd42a 100644
--- a/data/appstream-util
+++ b/data/appstream-util
@@ -31,6 +31,12 @@ _appstream-util()
fi
done
+ # How many'th non-option arg (1-based) for $command are we completing?
+ local i nth=1
+ for (( i=commandix+1; i < cword; i++ )); do
+ [[ ${words[i]} == -* ]] || (( nth++ ))
+ done
+
case $prev in
-h|--help|--version)
return
@@ -57,22 +63,23 @@ _appstream-util()
ext='@(xml.gz)'
;;
appdata-from-desktop)
- ext='@(desktop?(.in))'
- case $prev in
- *.desktop|*.desktop.in)
+ case $nth in
+ 1)
+ ext='@(desktop?(.in))'
+ ;;
+ 2)
COMPREPLY=( $( compgen -W '$( echo $prev | \
sed -e "s/desktop/appdata.xml/g" )' -- "$cur" ) )
ext=''
;;
- *.appdata.xml|*.appdata.xml.in)
- ext=''
- ;;
esac
;;
convert)
- ext='@(xml.gz|appdata.xml?(.in))'
- case $prev in
- *.xml.gz|*.appdata.xml?(.in))
+ case $nth in
+ 1)
+ ext='@(xml.gz|appdata.xml?(.in))'
+ ;;
+ *)
ext=''
;;
esac