AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Windows Command Line Auto Completion [HowTo]

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources
View previous topic :: View next topic  
Author Message
BoBoĻ
Guest





PostPosted: Fri Sep 28, 2007 1:15 pm    Post subject: Windows Command Line Auto Completion [HowTo] Reply with quote

Quote:
Windows Command Line Auto Completion
Having explained this to a number of people in as many days, I thought I'd share this tip for working with long paths on the command line. The easist way to expalin this is to jump in feet first:

Open a command line (<Windows Key>-R, CMD<Enter> is engrained in my hands at this point in my career)
At the prompt, repeatedly hit tab
You will be cycling through all of the files and directories in your current directory. Now try this:

At a clean command prompt, type "dir \P" then start hitting tab.
Now you'll be cycling through all the directories that start with "P" in the root of the current drive (in my case, it cycles through "Program Files" then Projects). You'll also notice that for files with embedded spaces, quotes are automatically added. This works for as many characters as you wish to type. After you cycle to the directory you want, type a backslash, then hit tab again and you'll cycle through the files and sub-directories in that directory, and so on. On my current machine, I can type the following to open my machine.config:

notepad \win<tab>\mic<tab>\<tab>\v1.1<tab>\con<tab>\m<tab><enter>

This results in the following command line, which would take considerably more keystrokes or mouse clicks:

notepad \WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config

This works at just about any point in a command, as long as you are starting from a space. It will also work on UNC paths staring at the share name (Assuming you can authenticate to that particular share):

dir \\fileserver\share\<tab>

There may be a delay as CMD goes an enumerates the items on the share, but if you are trying to get to something deep down in some huge directory structure with really long path names, this helps a ton.

Though this has been in CMD for some time, I don't think it was enabled by default untill Windows XP which may explain why it isn't well known. If you're stuck on a Windows 2000 box (or, gasp! NT4), you can edit the registry to enable this (Standard registry disclaimer applies - don't do this unless you know what you're doing since you can render a box un-bootable with sufficient registry tweaking.):

Set HKCU\Software\Microsoft\Command Processor\CompetionChar to 9

KB244407 covers this in detail.

I used to hate the command line because I'm lazy and didn't want to type out huge paths (which I would end up misspelling). No longer!

[Home]
Cool
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 5581

PostPosted: Fri Sep 28, 2007 1:27 pm    Post subject: Reply with quote

How to enable Command Prompt auto-completion ?
http://www.autohotkey.com/forum/viewtopic.php?p=70640#70640

Cool
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Fri Sep 28, 2007 1:41 pm    Post subject: Reply with quote

To surf the web for usefull things looks more and more useless. Shocked
Have a stop at Skan's hawker's tray and you're done. Wink


@ Skan
I often thought about if it wouldn't make sense to change your threads subject line from this:
"TipsNTricks: How to enable Drag for a Static Control ?"
to that:
"Skan's TipsNTricks Compilation"
because the current/historic subject line didn't cover anymore what that thread has become meanwhile, an AHK treasure chest.
So do it! Cool
Back to top
SKAN



Joined: 26 Dec 2005
Posts: 5581

PostPosted: Fri Sep 28, 2007 2:42 pm    Post subject: Reply with quote

BoBoĻ wrote:
I often thought about if it wouldn't make sense to change your threads subject line from this:
"TipsNTricks: How to enable Drag for a Static Control ?"


Before I make a post, I edit the title post with the new subject and then make the actual post. Those who are watching the topic would receive email alert with the updated subject line..

Anyways! After Corrupt's and Peter's suggestion I have decided to make separate posts in future.

I will rename it soon.

Smile
Back to top
View user's profile Send private message
tazmanian



Joined: 17 Nov 2007
Posts: 16

PostPosted: Tue Jan 01, 2008 7:05 pm    Post subject: Reply with quote

Isn't this old news?

I am looking for REAL autocompletion. That if I type "note<tab>" from any directory it will complete it to "notepad" for me. This should be easy to implement anyway because all it needs to do is autocomplete anything that ends in .bat or .exe if it is in a folder in the PATH variable
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 383
Location: Berlin

PostPosted: Tue Jan 01, 2008 8:38 pm    Post subject: Reply with quote

tazmanian, may be this can be done with an AutoHotkey Script? Analyse all filenames and save them in a list. This shouldnt be such complicated. But not for the console ... so, who would need that?

Sounds like "which"...
Back to top
View user's profile Send private message Send e-mail
tazmanian



Joined: 17 Nov 2007
Posts: 16

PostPosted: Tue Jan 01, 2008 9:16 pm    Post subject: Reply with quote

Hello Tuncay,

I meant that when you press <tab> in cmd it completes excutable filenames found in the PATH variable.

Is there any way to extend cmd for this and how would it be done?

It is one of those knowledge things, if you have the knowledge of how things work then implementing it and making cmd more "intelligent" would be a trivial exercise.

Any volunteers?

Maybe if you made a command line utility that all it did was use cmd to execute things but had tab completion built into it? But as I say I am fairly new to programming and would not even know where to begin.
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 383
Location: Berlin

PostPosted: Tue Jan 01, 2008 9:52 pm    Post subject: Reply with quote

tazmanian, I dont think, that the internals of the command line could be extended by any AutoHotkey script (Gurus, pls correct me, I am missing). I meant just to write a separate GUI or something similiar.

Ther is a tool from Unix/Linux, ported to Windows also. It is named to "which". But its anything else than a tab completion. Whichīs first parameter is a string, and it searches in the current pathes for executables and returnes just the full path of it.

... but a real tab completion for the cmd.exe? I donīt have such a magical ability, sorry. Embarassed
Back to top
View user's profile Send private message Send e-mail
tonne



Joined: 06 Jun 2006
Posts: 1143
Location: Denmark

PostPosted: Tue Jan 01, 2008 10:08 pm    Post subject: Reply with quote

Collect the command line your self by watching!
This is a crude version:
Code:
cmdline =
programs =
#IfWinActive ahk_class ConsoleWindowClass
~a::
~b::
~c::
~d::
~e::
~f::
~g::
~h::
~i::
~j::
~k::
~l::
~m::
~n::
~o::
~p::
~q::
~r::
~s::
~t::
~u::
~v::
~w::
~x::
~y::
~z::
  cmdline := cmdline . substr(A_ThisHotkey,2)
  traytip commandline, %cmdline%
  Return

~bs::
  StringTrimRight,cmdline,cmdline,1
  traytip commandline, %cmdline%
  Return

tab::
  if (!programs)
    FindPrograms()
  pos := InStr(programs, "|" . cmdline)
  If pos
  {
    pos     := InStr(programs, "*", false, pos) + 1
    posend  := InStr(programs, "|", false, pos+1) 
    program := SubStr(programs,pos,posend-pos)
    len     := StrLen(cmdline)
    if program
      SendInput {bs %len%}%program%
  }
 
  return

#IfWinActive

FindPrograms()
{
  Global programs
  EnvGet,Path,Path
  Loop,Parse,Path,;
  {
    Loop,%A_LoopField%\*.exe
    {
      programs .= "|" A_LoopFileName . "*" . A_LoopFileFullPath
    }
  }
}

_________________
there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face

- Kashmir
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Utilities & Resources All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group