From e8d1bac3ec0dc38db34d51cc2249f56bc789ae0f Mon Sep 17 00:00:00 2001 From: Teemu Murtola Date: Thu, 30 Jan 2014 18:28:43 +0200 Subject: [PATCH] Fix shell completions of ffMULT options Now file names for options with ffMULT set are completed also after one file name has already been provided. Fixes #1159, related to #1410. Change-Id: I1f4f0b6a5817ce3193a0195d1cb4a2491c397593 --- src/gromacs/commandline/shellcompletions.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/gromacs/commandline/shellcompletions.cpp b/src/gromacs/commandline/shellcompletions.cpp index de4cb802ba..9697a5cbfe 100644 --- a/src/gromacs/commandline/shellcompletions.cpp +++ b/src/gromacs/commandline/shellcompletions.cpp @@ -60,14 +60,20 @@ static void pr_fopts(FILE *fp, int nf, const t_filenm tfn[]) { for (int i = 0; i < nf; i++) { - const int ftp = tfn[i].ftp; + const int ftp = tfn[i].ftp; + const char *multiplicity = "(( $n == 1 )) && "; + if (tfn[i].flag & ffMULT) + { + multiplicity = ""; + } if (ftp == efRND) { - fprintf(fp, "%s) COMPREPLY=( $(compgen -S ' ' -d $c) );;\n", - tfn[i].opt); + fprintf(fp, "%s) %sCOMPREPLY=( $(compgen -S ' ' -d $c) );;\n", + tfn[i].opt, multiplicity); continue; } - fprintf(fp, "%s) COMPREPLY=( $(compgen -S ' ' -X '!*.", tfn[i].opt); + fprintf(fp, "%s) %sCOMPREPLY=( $(compgen -S ' ' -X '!*.", + tfn[i].opt, multiplicity); const int genericCount = ftp2generic_count(ftp); if (genericCount > 0) { @@ -132,7 +138,7 @@ static void pr_enums(FILE *fp, int npargs, t_pargs pa[]) { if (pa[i].type == etENUM) { - fprintf(fp, "%s) COMPREPLY=( $(compgen -S ' ' -W $'", pa[i].option); + fprintf(fp, "%s) (( $n == 1 )) && COMPREPLY=( $(compgen -S ' ' -W $'", pa[i].option); for (int j = 1; pa[i].u.c[j]; j++) { fprintf(fp, "%s%s", (j == 1 ? "" : "\\n"), pa[i].u.c[j]); @@ -151,9 +157,13 @@ static void write_bashcompl(FILE *out, * p and c hold the previous and current word on the command line. */ fprintf(out, "%s() {\n", funcName); - fprintf(out, "local p c\n"); fprintf(out, "local IFS=$'\\n'\n"); - fprintf(out, "COMPREPLY=() c=${COMP_WORDS[COMP_CWORD]} p=${COMP_WORDS[COMP_CWORD-1]}\n"); + fprintf(out, "local c=${COMP_WORDS[COMP_CWORD]}\n"); + fprintf(out, "local n\n"); + fprintf(out, "for ((n=1;nfile_->writeLine("COMPREPLY=()"); impl_->file_->writeLine("unset COMP_WORDS[0]"); impl_->file_->writeLine("for ((i=1;ifile_->writeLine("if [[ \"${COMP_WORDS[i]}\" != -* ]]; then break ; fi"); + impl_->file_->writeLine("[[ \"${COMP_WORDS[i]}\" != -* ]] && break"); impl_->file_->writeLine("unset COMP_WORDS[i]"); impl_->file_->writeLine("done"); impl_->file_->writeLine("if (( i == COMP_CWORD )); then"); -- 2.11.4.GIT