[game-data-packager] 01/01: bash completion: add long options & packages names

Alexandre Detiste detiste-guest at moszumanska.debian.org
Mon Mar 9 18:20:31 UTC 2015


This is an automated email from the git hooks/post-receive script.

detiste-guest pushed a commit to branch master
in repository game-data-packager.

commit 1355c4ce1e5ec0e9c5706df713dcd6443cb17ee7
Author: Alexandre Detiste <alexandre.detiste at gmail.com>
Date:   Mon Mar 9 19:16:54 2015 +0100

    bash completion: add long options & packages names
    
    the package names list are precomputed
    with a minimalist yaml parser
---
 Makefile                                  |  8 +++++-
 debian/game-data-packager.bash-completion | 29 ++++++++++++++++++---
 debian/game-data-packager.install         |  2 ++
 game_data_packager/bash_completion.py     | 43 +++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 9424126..9eb8f22 100644
--- a/Makefile
+++ b/Makefile
@@ -14,16 +14,21 @@ TEST_SUITE += rott spear-of-destiny wolf3d
 
 png       := $(patsubst ./data/%.xpm,./out/%.png,$(wildcard ./data/*.xpm))
 svgz      := $(patsubst ./data/%.svg,./out/%.svgz,$(wildcard ./data/*.svg))
+in_yaml   := $(wildcard ./data/*.yaml)
 yaml      := $(patsubst ./data/%,./out/%,$(wildcard ./data/*.yaml))
 copyright := $(patsubst ./data/%,./out/%,$(wildcard ./data/*.copyright))
 dot_in    := $(patsubst ./data/%,./out/%,$(wildcard ./data/*.in))
 
 default: $(DIRS) $(png) $(svgz) $(yaml) $(copyright) $(dot_in) \
-         out/changelog.gz out/copyright out/game-data-packager
+      out/bash_completion out/changelog.gz out/copyright out/game-data-packager
 
 out/%: data/%
 	if [ -L $< ]; then cp -a $< $@ ; else install -m644 $< $@ ; fi
 
+out/bash_completion: $(in_yaml)
+	python3 game_data_packager/bash_completion.py > ./out/bash_completion
+	chmod 0644 ./out/bash_completion
+
 out/changelog.gz: debian/changelog
 	gzip -nc9 debian/changelog > ./out/changelog.gz
 	chmod 0644 ./out/changelog.gz
@@ -41,6 +46,7 @@ $(DIRS):
 	mkdir -p $@
 
 clean:
+	rm -f ./out/bash_completion
 	rm -f ./out/changelog.gz
 	rm -f ./out/copyright
 	rm -f ./out/game-data-packager
diff --git a/debian/game-data-packager.bash-completion b/debian/game-data-packager.bash-completion
index 27c641f..58ce057 100644
--- a/debian/game-data-packager.bash-completion
+++ b/debian/game-data-packager.bash-completion
@@ -1,9 +1,32 @@
 _game_data_packager()
 {
-    if [ $COMP_CWORD -eq 1 ]
+    # FIXME: currently only works 100% correctly when
+    #        GAME is the first argument
+
+    local cur prev
+    cur="${COMP_WORDS[COMP_CWORD]}"
+    prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+    if [ "${cur:0:1}" == "-" ]
+    then
+      local longopts
+      longopts='--compress --destination --help --install --no-compress --no-download --no-search --package --save-downloads'
+      COMPREPLY=( $( compgen -W "$longopts" -- $cur ) )
+    elif [ "$prev" == '--package' ]
+    then
+      local line packages
+      while read line
+      do
+          if [ "${COMP_WORDS[1]}" == "$line" ]
+          then
+              read packages
+              break
+          fi
+      done < /usr/share/games/game-data-packager/bash_completion
+      COMPREPLY=( $( compgen -W "$packages" -- $cur ) )
+    elif [ $COMP_CWORD -eq 1 ]
     then
-      local cur supported
-      cur=${COMP_WORDS[COMP_CWORD]}
+      local supported
       supported=$(cd  /usr/share/games/game-data-packager/; ls -1 *.yaml |cut -d'.' -f1)
       COMPREPLY=( $( compgen -W "$supported" -- $cur ) )
     else
diff --git a/debian/game-data-packager.install b/debian/game-data-packager.install
index 4b69509..b2db58d 100644
--- a/debian/game-data-packager.install
+++ b/debian/game-data-packager.install
@@ -10,5 +10,7 @@ out/*.png                     usr/share/games/game-data-packager
 out/*.svgz                    usr/share/games/game-data-packager
 out/*.preinst.in              usr/share/games/game-data-packager
 out/*.README.Debian.in        usr/share/games/game-data-packager
+out/bash_completion           usr/share/games/game-data-packager
 out/changelog.gz              usr/share/games/game-data-packager
+out/copyright                 usr/share/games/game-data-packager
 out/*.yaml                    usr/share/games/game-data-packager
diff --git a/game_data_packager/bash_completion.py b/game_data_packager/bash_completion.py
new file mode 100644
index 0000000..f853042
--- /dev/null
+++ b/game_data_packager/bash_completion.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python3
+# encoding=utf-8
+#
+# Copyright © 2015 Alexandre Detiste <alexandre at detiste.be>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# You can find the GPL license text on a Debian system under
+# /usr/share/common-licenses/GPL-2.
+
+# pre-calculate a list of packages from yaml files
+# for bash auto-completion
+
+import os
+import glob
+#import yaml
+
+for yaml_file in sorted(glob.glob('data/*.yaml')):
+    print(os.path.splitext(os.path.basename(yaml_file))[0])
+    with open(yaml_file, encoding='utf-8') as raw:
+        #yaml_data = yaml.load(raw)
+        #for key in sorted(yaml_data['packages'].keys()):
+        #    print(key, end=' ')
+
+        for line in raw:
+            if line.strip() == 'packages:':
+                break
+        for line in raw:
+            if line == '\n':
+                continue
+            if line[0] != ' ':
+                break
+            if line[2] != ' ':
+                print(line.strip(':\n '), end=' ')
+
+        print('')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list