summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2014-02-23 18:48:04 +0100
committerMichael Olbrich <m.olbrich@pengutronix.de>2014-02-25 09:02:58 +0100
commit3efd41819bd09d8ae5fdc14bcf35ef98cc78de79 (patch)
treeebe72c1fad861efc5c75df94cabd332e1e5353b0 /scripts
parent33bc759e7df12817091fb021e4fccf4aa38fe492 (diff)
downloadptxdist-3efd41819bd09d8ae5fdc14bcf35ef98cc78de79.tar.gz
ptxdist-3efd41819bd09d8ae5fdc14bcf35ef98cc78de79.tar.xz
bash_completion: cache package list when possible
Keep the old behaviour for old ptxdist versions that do not printing multiple variables. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bash_completion11
1 files changed, 10 insertions, 1 deletions
diff --git a/scripts/bash_completion b/scripts/bash_completion
index 7ca9c9694..63e28e7e9 100644
--- a/scripts/bash_completion
+++ b/scripts/bash_completion
@@ -10,6 +10,15 @@ if have ptxdist; then
declare -a _ptxdist_completion_opts
declare -a _ptxdist_completion_cmds
declare -a _ptxdist_completion_newpkg
+__ptxdist_completion_packages() {
+ set -- $(${_ptxdist_cmd} print STATEDIR PTXDIST_PTXCONFIG PTXDIST_PLATFORMCONFIG PTXDIST_COLLECTIONCONFIG)
+ local cache="${1}/.bash_completion_packages"
+ if [ -z "${2}" -o "${2}" -nt "${cache}" -o "${3}" -nt "${cache}" -o "${4}" -nt "${cache}" ]; then
+ ${_ptxdist_cmd} print PTX_PACKAGES_SELECTED 2>/dev/null | tee "${cache}" 2>/dev/null
+ else
+ cat "${cache}"
+ fi
+}
_ptxdist_completion()
{
local cur prev words cword split
@@ -114,7 +123,7 @@ _ptxdist_completion()
COMPREPLY=( $( compgen -W root -- $cur ) )
;&
get|extract|prepare|compile|install|targetinstall|tags)
- COMPREPLY+=( $( compgen -W "$( $_ptxdist_cmd print PTX_PACKAGES_SELECTED 2> /dev/null)" -- $cur ) )
+ COMPREPLY+=( $( compgen -W "$(__ptxdist_completion_packages)" -- $cur ) )
;;
drop)
COMPREPLY=( $( compgen -W "$( cd $($_ptxdist_cmd print PTXDIST_PLATFORMDIR)/state; ls *.+(get|extract|prepare|compile|install|targetinstall) )" -- $cur ) )