CLI Folder navigation via TAB completion

Discuss anything related to command line tools here.
Post Reply
Message
Author
User avatar
__philippe
Posts: 687
Joined: Wed Jun 26, 2013 2:09 am

CLI Folder navigation via TAB completion

#1 Post by __philippe »

After messing about with CLI under WinXP/7 for more years than I care to remember, just stumbled upon this neat time-saving trick :
(possibly an open secret to everyone else ?)

Quick CLI Directory navigation via TAB completion

Code: Select all

C:\>CD <Tab> 

(space required between CD and <Tab>)

Each <Tab> press will cycle thru every sub-directory name existing in the current directory structure.
(If the current directory has no subdir, Win will just beep once.)

Pressing <Return> after a subdir name will land control in that subdir.

Further usage tips for quick TAB Completion navigation:

As noted above, the bare "CD <Tab>" Directory search will cycle thru every subdir.
The search scope can also easily be constrained to match specific conditions:

Limiting Directory search scope to subdir names starting with specific character(s):

Code: Select all

C:\>CD img<Tab>
Limiting Directory search scope to subdir names ending with specific character(s):

Code: Select all

C:\>CD *img<Tab>
Limiting Directory search scope to subdir names including specific character(s):

Code: Select all

C:\>CD *img*<Tab>
Beats hands-down the aggravation of remembering and typing correctly awkwardly long directory names...;-)
Last edited by __philippe on Tue Jul 12, 2016 1:56 am, edited 1 time in total.

shnbwmn
Posts: 265
Joined: Sat Jul 11, 2015 12:59 am

Re: CLI Folder navigation via TAB completion

#2 Post by shnbwmn »

Thanks for the tip :)

TP109
Posts: 571
Joined: Sat Apr 08, 2006 7:12 pm
Location: Midwestern US

Re: CLI Folder navigation via TAB completion

#3 Post by TP109 »

good tip. thanks.

User avatar
__philippe
Posts: 687
Joined: Wed Jun 26, 2013 2:09 am

Re: CLI Folder navigation via TAB completion

#4 Post by __philippe »

see Further usage tips for quick TAB Completion navigation added to OP above

User avatar
Midas
Posts: 6705
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: CLI Folder navigation via TAB completion

#5 Post by Midas »

Great tip, __philippe. I use the Tab completion feature all the time but never noticed the different behavior after a CD command. And those truncation hints are life-savers, really... 8)

BTW, there's a possibility for customizing the key used for completion somewhere -- I just don't recall where and how, ATM...

User avatar
__philippe
Posts: 687
Joined: Wed Jun 26, 2013 2:09 am

Re: CLI Folder navigation via TAB completion

#6 Post by __philippe »

Midas wrote:...BTW, there's a possibility for customizing the key used for completion somewhere -- I just don't recall where and how, ATM...
@Midas

The Tab Completion feature appears to be available within the CLI running under many OS'es, be they Windows, Unix, Mac OS X...

In Unix, for instance, the basic Tab Completion feature (which is more powerful than its Win equivalent BTW),
can indeed be further customized (under the Bash shell) with the Compgen Tab Completion customization command.

Unclear if there is a similar customization function in the Windows realm... :?:

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: CLI Folder navigation via TAB completion

#7 Post by lintalist »

I'll admit I haven't tested portability as I simply installed it but I think clink might be of interest to you none the less https://mridgers.github.io/clink/ (you can download a "portable zip file")
Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities. Readline is best known for its use in the well-known Unix shell Bash, the standard shell for Mac OS X and many Linux distributions.
Features
  • The same line editing as Bash (from GNU’s Readline library).
  • History persistence between sessions.
  • Context sensitive completion;
    • Executables (and aliases).
    • Directory commands.
    • Environment variables
    • Thirdparty tools; Git, Mercurial, SVN, Go, and P4.
  • New keyboard shortcuts;
    • Paste from clipboard (Ctrl-V).
    • Incremental history search (Ctrl-R/Ctrl-S).
    • Powerful completion (TAB).
    • Undo (Ctrl-Z).
    • Automatic “cd ..” (Ctrl-Alt-U).
    • Environment variable expansion (Ctrl-Alt-E).
    • (press Alt-H for many more…)
  • Scriptable completion with Lua.
  • Coloured and scriptable prompt.
  • Auto-answering of the “Terminate batch job?” prompt.
Usage
There are a variety of ways to start Clink;
  • If you installed the autorun option then simply start cmd.exe. Run clink autorun –help for more info.
  • To manually start, run the Clink shortcut from the Start menu (or the clink.bat located in the install directory).
  • To establish Clink to an existing cmd.exe process, use “<install_dir>\clink.exe inject”
Edit: I searched after posting, found a clink thread here http://www.portablefreeware.com/forums/ ... =2&t=21583 started by midas
Edit2: by I am Baas :-)
Last edited by lintalist on Thu Jul 14, 2016 8:26 am, edited 1 time in total.

User avatar
__philippe
Posts: 687
Joined: Wed Jun 26, 2013 2:09 am

Re: CLI Folder navigation via TAB completion

#8 Post by __philippe »

@lintalist
Thanks for your timely reminder about Clink intriguing Bash shell emulation capabilities under Windows.
( extra Kudos for crediting early references by Baas and Midas...;-) )

User avatar
Midas
Posts: 6705
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: CLI Folder navigation via TAB completion

#9 Post by Midas »

:!: Please don't overlook Cmder (viewtopic.php?t=22051), as it's portable and includes a pre-configured version of Clink...
lintalist wrote:Edit: I searched after posting, found a clink thread here viewtopic.php?t=21583 started by midas
Correction: that topic was in fact started by I am Baas.

BTW, other (loosely) related topics:


User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: CLI Folder navigation via TAB completion

#10 Post by lintalist »

@midas my bad, I probably landed directly on your post after the search instead of the top of the thread. Cmder doesn't work for me (crashes and also "too big" to my taste, conemu does work well for me though)

User avatar
Midas
Posts: 6705
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: CLI Folder navigation via TAB completion

#11 Post by Midas »

@lintalist: hey, whatever works... 8)

But I hope you noticed that Cmder has a mini version. :wink:

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: CLI Folder navigation via TAB completion

#12 Post by lintalist »

@Midas yes I saw that and tried it also. Still crashes. :-)

Post Reply