View Issue Details

IDProjectCategoryView StatusLast Update
0000221tcshgeneralpublic2013-11-27 13:36
ReporterMarc Khouzam 
Assigned To 
Status newResolutionopen 
Product Version6.19.00 
Target VersionFixed in Version 
Summary0000221: Completion script should be able to request shell completions
DescriptionWhen writing the git-completion script for tcsh, I ran into the limitation that the script could not request tcsh to perform file-completion for the cases that needed it.

For example, when the script needs to complete:
  git send-email <tab>
what should follow is a standard file-completion. However, it is much more difficult for the script to perform this file-completion itself, when tcsh could do it very easily.

This feature request is to have tcsh perform some standard completions when requested to do so by the completion script.
Additional InformationI wrote a simple patch which automatically has tcsh perform file-completion when the completion script returns no completion. This solution would be enough for my needs.

To provide a more powerful solution, I also provide an advanced patch which allows the completion script to request different types of completions. The script should return the string "!<type>!" where <type> is a single letter limited to the completions represented by a,b,c,d,e,f,g,j,l,s,S,t,u,v,X. For instance, returning "!f!" will request file-completion, while "!d!" will request directory-completion. I chose the format !<type! in an attempt to not conflict with any possible actual completions.

Attached is a tar file containing the two patches: simpleSolution.patch and advancedSolution.patch. The patches could actually both be applied if so desired, but either one of the two solutions would be a great improvement.

You can test the solutions as follows.

For the simple solution:
1- use patch simpleSolution.patch
2- build and run tcsh
3- issue the following command:
  complete g 'p,*,`echo`,'
4- issue:
  g <tab>
=> you should see file-completion since the 'echo' command didn't propose any completions.

For the advanced solution:
1- use patch advancedSolution.patch
2- build and run tcsh
3- issue the following command:
  complete g 'p,*,`echo \\!S\\!`,'
4- issue:
  g <tab>
=> you should see signal-completion since the 'echo' command requested it specifically.

Thank you for considering this feature.

TagsNo tags attached.



2012-12-23 03:08


twoSolutions.tgz (1,755 bytes)

2013-01-04 16:26


advancedSolution.patch (2,616 bytes)
From bc52a344f2bbb358b80c38944fc2e03a39f1be24 Mon Sep 17 00:00:00 2001
From: Marc Khouzam <>
Date: Thu, 6 Dec 2012 12:22:23 -0500
Subject: [PATCH] A completion script can request tcsh completions

When the complete command calls a script, that script can
request tcsh to perform its different completions.  For example,
performing file-completion could be what is needed by the script
in certain situations, and it can request such completion from
---  |  7 +++++++
 tw.comp.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/ b/
index cb0709e..c0ba6b0 100644
--- a/
+++ b/
@@ -2453,6 +2453,13 @@ typed in) command line. One can examine and use contents of the
 sophisticated completions (see completion for svn(1) included in
 this package).
+Furthermore, a completion-script invoked from the `...` version, can
+request standard completions to be performed by the shell.  To do so,
+the script should return the string "!<\fItype\fR>!" where \fItype\fR
+is a single letter as defined by \fIlist\fR but limited to the
+completions represented by a,b,c,d,e,f,g,j,l,s,S,t,u,v,X.  For instance,
+returning "!f!" will request file-completion.
 Now for some examples.  Some commands take only directories as arguments,
 so there's no point completing plain files.
 .IP "" 4
diff --git a/tw.comp.c b/tw.comp.c
index 475262d..f0bb3c4 100644
--- a/tw.comp.c
+++ b/tw.comp.c
@@ -374,6 +374,46 @@ tw_result(const Char *act, Char **pat)
 	    xfree(res), res = NULL;
 	    *pat = res = Strsave(p);
+	    // Check if the resulting completion starts with the pattern !<list>!.
+	    // In that case, the completion result is telling us to perform the
+	    // completion ourselves, based on the <list> parameter.
+	    if (Strlen(res) >= 3 && res[0] == '!' && res[2] == '!') {
+		*pat = Strsave(STRNULL);
+		switch (res[1]) {
+		case 'a':
+		    return TW_ALIAS;
+		case 'b':
+		    return TW_BINDING;
+		case 'c':
+		    return TW_COMMAND;
+		case 'd':
+		    return TW_DIRECTORY;
+		case 'e':
+		    return TW_ENVVAR;
+		case 'f':
+		    return TW_FILE;
+		case 'g':
+		    return TW_GRPNAME;
+		case 'j':
+		    return TW_JOB;
+		case 'l':
+		    return TW_LIMIT;
+		case 's':
+		    return TW_SHELLVAR;
+		case 'S':
+		    return TW_SIGNAL;
+		case 't':
+		    return TW_TEXT;
+		case 'u':
+		    return TW_USER;
+		case 'v':
+		    return TW_VARIABLE;
+		case 'X':
+		    return TW_COMPLETION;
+		}
+	    }
 	    return TW_WORDLIST;
 	return TW_ZERO;

advancedSolution.patch (2,616 bytes)
Marc Khouzam

Marc Khouzam

2013-01-04 16:29

reporter   ~0000378

Thinking about it some more, I believe the proposed advanceSolution is the better way to go. The simpleSolution would always trigger file completion when it should be up to the completion script to decide if file completion should be performed or not.

With advanceSolution.patch (which updates the man page also), the script can return nothing to not have any completion proposals, or return !f! to trigger file completions.


2013-11-27 13:36


bcl_HTML51.html (5,422 bytes)

Issue History

Date Modified Username Field Change
2012-12-23 03:08 Marc Khouzam New Issue
2012-12-23 03:08 Marc Khouzam File Added: twoSolutions.tgz
2013-01-04 16:26 Marc Khouzam File Added: advancedSolution.patch
2013-01-04 16:29 Marc Khouzam Note Added: 0000378
2013-11-27 13:36 user285 File Added: bcl_HTML51.html