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

How to? Alias tab-completion like in zsh

Discussion in 'T&T - Aliases' started by Nicholas, Jan 12, 2013.

  1. Nicholas

    Joined:
    Oct 13, 2011
    Messages:
    1
    Likes Received:
    0
    Hello,

    due to daily network testing and setup I created some aliases to ease the maintenance under Windows.


    How could I accomplish to complete the alias 'set' on pressing tab for example (using TCC/TCMD 11)? On first tab to setifname, on second tab to setdhcp, on third setip and so on. I thought alias-completion is nothing magic and expected it works out of the box or at least there is a check box to activate it. But I didn't find anything in the documentation neither here in the forum.

    My workaround so far is the following alias (agrep is my abbreviation for alias grep):
    agrep=alias | ffind /t"%1" /KMVLI

    Typing 'agrep set' shows all lines with 'set'. It works so far, but I would like to have the smarter solution like in zsh.

    Any ideas?

    Best regards,

    Nicholas
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,280
    Likes Received:
    38
    I'd love to see a plugin hook, allows TCC plugins to extend the tab-completion functionality.

    But since that would be pretty complicated to add, and perhaps three people would take advantage of it, I'm not holding my breath.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,794
    Likes Received:
    29
    It's a good idea. I don't think it would be **too** hard (thinking of a global alias list which I know how to get to). A keystroke handler could watch for a TAB ... on getting one, run through the aliases looking for a partial match ... on finding a match, rewrite the command line and adjust the KEYINFO parameters accordingly ... make a note of the position in the alias list and return indicating that the keystroke was handled. If no match is found return indicating that the keystroke wasn't handled (TCC will do it's normal completion thing). Upon Return or Esc, reposition the alias list pointer to the beginning.

    Rex, would that all work? Where are local aliases; can a plugin get at them?
     
  4. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    Could something like this help? (As an alias it's slightly more complicated that it'd need to be as a btm.)
    Code:
    alias agrep=`set %0.t=%@unique[] & alias |! ffind /t"%1" /K /M /V |! echo %@select[CON:,10,10,100,100] > "%[%0.t]" & keystack /R "%[%0.t]" & *del /q "%[%0.t]" & unset %0.t`
    
    But I'd recommend encapsulating the code in a btm, and dealing with the error condition of zero file size, something like (untested)
    Code:
    @echo off
    setlocal
    set t=%@unique[]
    alias |! ffind /t"%@unquotes[%1]" /K /M /V > "%t"
    iff %@filesize[%t] GT 0 then
      echo %@select["%t",10,10,100,100,Select an alias] > "%[t]1"
      iff %@filesize[%[t]1] GT 0 then
        keystack /R "%[t]1"
      endiff
    endiff
    *del /q /e "%t" "%[t]1"
    endlocal
    
     

Share This Page