Implement zsh shell completions.
authorJames W. Barnett <jbarnet4@tulane.edu>
Tue, 14 Jul 2015 23:24:40 +0000 (18:24 -0500)
committerJames W. Barnett <jbarnet4@tulane.edu>
Wed, 15 Jul 2015 15:37:44 +0000 (10:37 -0500)
zsh completions when gmx prefix was used were not implemented. Use zsh builtin
bashcompinit to use the bash completions. Remove 'shopt -s extglob'
from gmx-completion.bash and place it in GMXRC.bash, since it is incompatible
with zsh. gmx-completion.bash and gmx-completion-gmx.bash can now be used for
completions in both bash and zsh.

Change-Id: Ib8f3cf0535d39e91a6b31933f41aa7548755b351

scripts/GMXRC.bash.cmakein
src/gromacs/commandline/shellcompletions.cpp

index eed26cafe75135267189a786f84660e611175624..18457a637735b89544c46224aacf6a8f68b62f31 100644 (file)
@@ -74,6 +74,18 @@ unset old_IFS
 # and this shell supports extended globbing
 if test -n "${BASH_VERSION+set}" && (complete) > /dev/null 2>&1; then
   if (shopt -s extglob) > /dev/null 2>&1; then
+    shopt -s extglob
+    if [ -f $GMXBIN/gmx-completion.bash ]; then
+      source $GMXBIN/gmx-completion.bash
+      for cfile in $GMXBIN/gmx-completion-*.bash ; do
+        source $cfile
+      done
+    fi
+  fi
+elif test -n "${ZSH_VERSION+set}" > /dev/null 2>&1 ; then
+  autoload bashcompinit
+  if (bashcompinit) > /dev/null 2>&1; then
+    bashcompinit
     if [ -f $GMXBIN/gmx-completion.bash ]; then
       source $GMXBIN/gmx-completion.bash
       for cfile in $GMXBIN/gmx-completion-*.bash ; do
@@ -81,12 +93,4 @@ if test -n "${BASH_VERSION+set}" && (complete) > /dev/null 2>&1; then
       done
     fi
   fi
-# read zsh completions if understand how to use them
-# Currently disabled, since the completions don't work with the new
-# gmx binary with subcommands.
-# Contributions to get the functionality back are welcome.
-#elif test -n "${ZSH_VERSION+set}" && compctl >& /dev/null; then
-#  if [ -f $GMXBIN/gmx-completion.zsh ]; then
-#    source $GMXBIN/gmx-completion.zsh;
-#  fi
 fi
index 1eefeda1cf6fd282965b63511aab391030368ca4..ce9f08a71779219b18ce4cb5a4786e91d9b17339 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -218,7 +218,6 @@ File *ShellCompletionWriter::outputFile()
 void ShellCompletionWriter::startCompletions()
 {
     impl_->file_.reset(new File(impl_->binaryName_ + "-completion.bash", "w"));
-    impl_->file_->writeLine("shopt -s extglob");
 }
 
 void ShellCompletionWriter::writeModuleCompletions(