Can I ignore dot files with cmd.exe tab completion?

3

I unfortunately need to work with cmd.exe from time to time and it usually doesn't bug me too much except when I am editing a file in vim and then try to run that file with tab-completion.

If I have the file foo.py open in vim, .foo.py.swp also exists in the directory. The behavior I see is:

C:\foo> f[TAB]
C:\foo> .foo.py.swp[TAB]
C:\foo> foo.py

This is rather infuriating and I'm wondering if there is any way to prevent this behavior short of a complete workaround like changing my swap file naming or using PowerShell. I did notice PowerShell does not emulate this behavior, but I really don't want to use it.

djs

Posted 2010-09-12T23:37:13.943

Reputation: 268

Why are you so opposed to using PowerShell? – Sasha Chedygov – 2010-09-13T00:22:22.183

I found it less useful than helpful... It's counter-intuitive to both cmd.exe and bash. – djs – 2010-09-19T00:35:42.663

1

There is now an excellent solution to this problem: clink provides bash readline functionality in a native cmd.exe window.

– djs – 2013-05-01T04:36:16.857

Answers

3

Windows is behaving exactly as you'd expect if you think it through (and to be honest, until seeing your question, I hadn't thought it completely through). A file name that begins with a '.' is seen as a file with a null file name with an extension. To see how this works, create a directory and then create the following files using touch (I'm assuming you're familiar with touch):

touch .a.aaa
touch a.aaa
touch .b.bbb
touch b.bbb

Now, in that directory, use the tab key to cyle through the files and you'll see that the sequence is:

.a.aaa
.b.bbb
a.aaa
b.bbb

If you want to go through the 'a' files, then type 'a' before the tab and you'll get a predictable .a.aaa, a.aaa.

As for the _ character in a file name, it's just like any other character and sorts after 'Z'.

BillP3rd

Posted 2010-09-12T23:37:13.943

Reputation: 5 353

1

The semantics of FindFirstFile (what CMD uses to enumerate matching files) means that the pattern is tested against the long file name (what you'd like to see) as well as against the autogenerated "8.3" file name. The short name generation is what is causing your spurious matches.

You can disable 8.3 generation via FSUTIL, but that stops FURTHER generation and doesn't remove already existing names. You'd have to run a script that would do renames to fully remove them.

This is dangerous, however, since some programs are clueless and will write the autogenerated shortnames down (say you are using a 16-bit installer, like old versions of MSOFFICE). If you disable their generation, then these installers may fail.

MJZ

Posted 2010-09-12T23:37:13.943

Reputation: 156