Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How to? Limiting Autocompletion to Directory Names (on-the-fly)

Feb
240
3
In the page on Customizing Filename Completion, there is a very useful option which allows specifying that autocompletion for a given command (e.g. cdd) should be limited to folder names only (the "dirs" file extension).
I'm wondering whether how this can be done on-the-fly, while typing out a mask on the command line.
That is: as we know, if we want to cycle through all of the *.txt files in a given place, we can type a space plus the mask:
[C:\] *.txt
And then hit TAB.
But how can I specify a mask that will limit the auto-completion to directory names only?
I've tried two possibilities that occurred to me:
[C:\] \
and
[C:\] dirs
But neither of these worked as a dynamic completion mask.
 
If you want a "normal" filecompletion mask as well as a dynamic one, use the OPTION dialog to create a FileCompletion directive in your .INI file. When you want to change it dynamically, just use "SET FILECOMPLETION=..." to override it. Of course you must remember to UNSET it to restore your customized default. Unfortunately there is no method to make changes to the TCMD operating environment (by which I mean the totality of environment variables, aliases, etc.) which affect only the next command.

Regardless, why would you want to change the filecompletion mask to directories only when there is no command on the line? The only reason I can think of is "automatic directory change" - which is nothing but an implied CD (of CDD) command. My suggestion is to use the FileCompletion directive or the FILECOMPLETION variable to restrict completion to directories when the command is one to change directories as I do (you can also add any aliases and batch file names you use for the purpose, as are cdx and cdz below):
filecompletion=cd cdd cdx cdz chdir pushd:dirs
and type in the two or three letters CD or CDD - just as quick as your typing "dirs".
 
Using the OPTION command, go to "Command Line" tab, the "Filename Completion" area and type

cd:dirs

in the "Options:" box. Click the "Apply" button.

Then at the command line type cd <space> then hit the tab key to cycle through directories.
 
In the page on Customizing Filename Completion, there is a very useful option which allows specifying that autocompletion for a given command (e.g. cdd) should be limited to folder names only (the "dirs" file extension).
I'm wondering whether how this can be done on-the-fly, while typing out a mask on the command line.

There is no built-in way to do this (though it could be done with a plugin).
 
Hi Rex,
Thanks for your reply. I'm willing to take this on as my first TCC plugin project, but I'd first like to clarify what you're envisioning. Is there a mechanism in place to allow the plugin to interface with, and slightly modify, the auto-completion functionality, or would the plug in have to reimplement the auto-completion functionality?
That is: I'll write a plug in that traps every keystroke, and if the keystroke is one of the autocompletion keystrokes (tab, shift-tab, etc.), then the plugin will check if the word "dirs" immediately precedes the cursor to the left. If this is the case, then I'll want the plugin to invoke the autocompletion module to only show directory names (as if it had been preconfigured with "dirs"). Can this be done directly? Or, alternatively, can the plug-in traverse the auto-completion results one-by-one, checking for directories? Or would the plug-in have to reimplement the autocompletion itself?
Thanks for your help,
Avi

There is no built-in way to do this (though it could be done with a plugin).
 
Oh, I see; that makes it into a much more formidable task; TCC's auto-completion really shines in its strong flexibility, but that would take a very significant effort to recode.
Would it make sense to suggest a feature as follows: to add a hotkey that would toggle TCC's auto-completion between regular mode (all files and directories) and between a mode in which it would cycle only through directories? That way, as someone types at the command line, the auto-completion feature could be toggled as necessary to function this way or that.

You'll have to reimplement the auto completion; there aren't any hooks into the middle of the TCC completion code.
 

Similar threads

Back
Top