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? Alias tab-completion like in zsh

Oct
1
0
Hello,

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


setifname=netsh interface set interface name="Local Area Connection" newname="eth0"
setdhcp=netsh interface ip set address name="eth0" source=dhcp
setip=netsh interface ip set address name="eth0" source=static addr=89.x.x.x mask=255.255.255.252 gateway=89.x.x.1 1
set_prv_ip=netsh interface ip set address name="eth0" source=static addr=192.168.3.33 mask=255.255.255.0 gateway=192.168.3.1 1
setdns1=netsh interface ip set dns name="eth0" source="static" addr="8.8.8.8"
setdns2=netsh interface ip add dns name="eth0" addr="9.9.9.9" index=2
getip=netsh interface ip show config
getdns=netsh interface ip show dns

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
 
Any ideas?

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.
 
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.
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?
 
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?
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
 
Back
Top
[FOX] Ultimate Translator
Translate