[Fawkes Git] branch/thofmann/bash-completion: created (0.5.0-3085-g98e1568)

Till Hofmann hofmann at kbsg.rwth-aachen.de
Mon Aug 15 16:08:59 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, thofmann/bash-completion has been created
        at  98e15681e065c6f170afdb0c550583238eaf1eda (commit)

http://git.fawkesrobotics.org/fawkes.git/thofmann/bash-completion

- *Log* ---------------------------------------------------------------
commit 478d4ab8cd88bf9eb6bfe39d65fbd692ffca9d99
Author:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
AuthorDate: Sat Jul 2 21:29:40 2016 +0200
Commit:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
CommitDate: Sat Jul 2 21:29:40 2016 +0200

    baseapp: interpret positional arguments as plugins to load
    
    This allows to load plugins without the parameter -p,
    e.g. 'fawkes skiller'.
    
    Furthermore, this allows easier bash completion for plugins.

http://git.fawkesrobotics.org/fawkes.git/commit/478d4ab
http://trac.fawkesrobotics.org/changeset/478d4ab

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit ba3405e3c37fe33dc14425d218724553eee09ea5
Author:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
AuthorDate: Sat Jul 2 22:29:23 2016 +0200
Commit:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
CommitDate: Sat Jul 2 22:29:23 2016 +0200

    add bash completion
    
    The completion expects the plugins to be given as positional parameter
    not as optional parameter, i.e. use 'fawkes skiller' instead of
    'fawkes -p skiller'.

http://git.fawkesrobotics.org/fawkes.git/commit/ba3405e
http://trac.fawkesrobotics.org/changeset/ba3405e

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 05a650dce2ca98492c5e153cea5cf8fa9333b05f
Author:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
AuthorDate: Sat Jul 2 22:57:25 2016 +0200
Commit:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
CommitDate: Sat Jul 2 22:59:31 2016 +0200

    bash completion: add completion for meta plugins
    
    We parse the yaml config and look read the meta plugins from the config.
    The yaml parse is quite simple:
    - it expects meta plugins to be defined in cfg/conf.d/meta_plugins.yaml,
    - it can only parse a subset of yaml,
    - it doesn't allow any other config values in the same config file;
      these will be misinterpreted as meta plugins.

http://git.fawkesrobotics.org/fawkes.git/commit/05a650d
http://trac.fawkesrobotics.org/changeset/05a650d

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 98e15681e065c6f170afdb0c550583238eaf1eda
Author:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
AuthorDate: Mon Aug 15 15:46:34 2016 +0200
Commit:     Till Hofmann <hofmann at kbsg.rwth-aachen.de>
CommitDate: Mon Aug 15 15:46:34 2016 +0200

    bash completion: fix -L autocompletion, improve -D, add -P, -c
    
    The option -L is somewhat a special case because it expects either
    '-L console' or '-L file:path/to/file'. Improve '-D' by listing files
    (possible PID files), and add completion for -P and -c.

http://git.fawkesrobotics.org/fawkes.git/commit/98e1568
http://trac.fawkesrobotics.org/changeset/98e1568

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 res/fawkes_completion.bash |   84 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)
 create mode 100644 res/fawkes_completion.bash


- *Diffs* -------------------------------------------------------------

- *commit* 478d4ab8cd88bf9eb6bfe39d65fbd692ffca9d99 - - - - - - - - - -
Author:  Till Hofmann <hofmann at kbsg.rwth-aachen.de>
Date:    Sat Jul 2 21:29:40 2016 +0200
Subject: baseapp: interpret positional arguments as plugins to load

 src/libs/baseapp/init_options.cpp |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/baseapp/init_options.cpp b/src/libs/baseapp/init_options.cpp
index e6b5943..4788633 100644
--- a/src/libs/baseapp/init_options.cpp
+++ b/src/libs/baseapp/init_options.cpp
@@ -244,9 +244,29 @@ InitOptions::InitOptions(int argc, char **argv)
   __show_help = argp->has_arg("h");
   __bb_cleanup = argp->has_arg("C");
 
-  __has_load_plugin_list = argp->has_arg("p");
+  __has_load_plugin_list = argp->has_arg("p") || argp->num_items() > 0;
   if (__has_load_plugin_list) {
-    __load_plugin_list = strdup(argp->arg("p"));
+    uint len = 0;
+    for (uint i = 0; i < argp->items().size(); i++) {
+      len += strlen(argp->items()[i]);
+    }
+    if (argp->has_arg("p")) {
+      len += strlen(argp->arg("p") + 1);
+    }
+    char res[len + argp->items().size()];
+    if (argp->has_arg("p") && argp->num_items() > 0) {
+      sprintf(res, "%s,%s,", argp->arg("p"), argp->items()[0]);
+    } else if (argp->has_arg("p")) {
+      sprintf(res, "%s", argp->arg("p"));
+    } else {
+      sprintf(res, "%s", argp->items()[0]);
+    }
+    for (uint i = 1; i < argp->items().size(); i++) {
+      char *tmp = strdup(res);
+      sprintf(res, "%s,%s", tmp, argp->items()[i]);
+      free(tmp);
+    }
+    __load_plugin_list = strdup(res);
   } else {
     __load_plugin_list = NULL;
   }

- *commit* ba3405e3c37fe33dc14425d218724553eee09ea5 - - - - - - - - - -
Author:  Till Hofmann <hofmann at kbsg.rwth-aachen.de>
Date:    Sat Jul 2 22:29:23 2016 +0200
Subject: add bash completion

 res/fawkes_completion.bash |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)


- *commit* 05a650dce2ca98492c5e153cea5cf8fa9333b05f - - - - - - - - - -
Author:  Till Hofmann <hofmann at kbsg.rwth-aachen.de>
Date:    Sat Jul 2 22:57:25 2016 +0200
Subject: bash completion: add completion for meta plugins

 res/fawkes_completion.bash |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

_Diff for modified files_:
diff --git a/res/fawkes_completion.bash b/res/fawkes_completion.bash
index cbee798..18a0ea0 100644
--- a/res/fawkes_completion.bash
+++ b/res/fawkes_completion.bash
@@ -1,3 +1,20 @@
+function parse_yaml {
+   local prefix=$2
+   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
+   sed -ne "s|^\($s\):|\1|" \
+        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
+        -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p"  $1 |
+   awk -F$fs '{
+      indent = length($1)/2;
+      vname[indent] = $2;
+      for (i in vname) {if (i > indent) {delete vname[i]}}
+      if (length($3) > 0) {
+         vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])}
+         printf("%s%s%s ", "'$prefix'",vn, $2, $3);
+      }
+   }'
+}
+
 _fawkes()
 {
   local cur prev opts base
@@ -26,7 +43,9 @@ _fawkes()
   esac
   local available_plugins=$(basename -s .so\
     $(ls  $(dirname ${COMP_WORDS[0]/#\~/$HOME})/../plugins))
-  COMPREPLY=( $(compgen -W "${available_plugins}" -- ${cur}) )
+  local meta_plugins=$(parse_yaml $(dirname\
+    ${COMP_WORDS[0]/#\~/$HOME})/../cfg/conf.d/meta_plugins.yaml)
+  COMPREPLY=( $(compgen -W "${available_plugins} ${meta_plugins}" -- ${cur}) )
   return 0
 }
 complete -F _fawkes fawkes

- *commit* 98e15681e065c6f170afdb0c550583238eaf1eda - - - - - - - - - -
Author:  Till Hofmann <hofmann at kbsg.rwth-aachen.de>
Date:    Mon Aug 15 15:46:34 2016 +0200
Subject: bash completion: fix -L autocompletion, improve -D, add -P, -c

 res/fawkes_completion.bash |   43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)

_Diff for modified files_:
diff --git a/res/fawkes_completion.bash b/res/fawkes_completion.bash
index 18a0ea0..fffd1fe 100644
--- a/res/fawkes_completion.bash
+++ b/res/fawkes_completion.bash
@@ -17,21 +17,54 @@ function parse_yaml {
 
 _fawkes()
 {
-  local cur prev opts base
+  local cur prev pprev opts base
   cur="${COMP_WORDS[COMP_CWORD]}"
   prev="${COMP_WORDS[COMP_CWORD-1]}"
+  pprev=${COMP_WORDS[COMP_CWORD-2]}
 
-  opts="-c -C -d -D -g -h -l -L -p -P -u --net-service-name"
+  opts="-c -C -d -D -g -h -l -L -p -P -q -qq -qqq -qqqq -u --net-service-name"
+
+  # -L needs special treatment; format for files is '-L file:path/to/file'
+  # 1) -L file: --> -L file:somedir
+  if [[ "${pprev}" = "-L" ]] && [[ "${prev}" = "file" ]]
+  then
+    # use default auto completion which will auto-complete files
+    compopt -o default
+    return 0
+  fi
+  # 2) -L file:so --> -L file:somedir
+  # this can also be used for other file: arguments
+  if [[ "${pprev}" = "file" ]] && [[ "${prev}" = ":" ]]
+  then
+    # use default auto completion which will auto-complete files
+    compopt -o default
+    return 0
+  fi
 
   case "${prev}" in
     -L)
-      #OPTIONS=( $(compgen -W "${available_plugins}" -- ${cur##*,}) )
-      #COMPREPLY=( ${OPTIONS[@]/#/${cur}} )
+      # turn off space because we don't want a space after 'file:'
+      compopt -o nospace
       COMPREPLY=( $(compgen -W "console file:" -- ${cur}) )
       return 0
       ;;
     -D*)
-      COMPREPLY=( $(compgen -W "-k -s" -- ${cur}) )
+      if [[ "${cur}" = -* ]] ; then
+        COMPREPLY=( $(compgen -W "-k -s" -- ${cur}) )
+      else
+        # use default auto completion which will auto-complete files
+        compopt -o default
+        COMPREPLY=()
+      fi
+      return 0
+      ;;
+    -P)
+      COMPREPLY=()
+      return 0
+      ;;
+    -c)
+      # use default auto completion which will auto-complete files
+      compopt -o default
       return 0
       ;;
   esac




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list