1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Support' started by Avi Shmidman, Mar 23, 2012.

  1. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    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.
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    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".
     
  3. Matt

    Joined:
    Jan 15, 2009
    Messages:
    16
    Likes Received:
    0
    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.
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    There is no built-in way to do this (though it could be done with a plugin).
     
  5. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    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

     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    You'll have to reimplement the auto completion; there aren't any hooks into the middle of the TCC completion code.
     
  7. Avi Shmidman

    Joined:
    Feb 23, 2012
    Messages:
    238
    Likes Received:
    3
    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.

     

Share This Page