1

Normally, one can hit the tab key after entering the first few characters of a filename and get the complete filename (or suggestions in case there are many with the same beginning characters).

However for filenames with peculiar characters, this doesn't seem to work. Specifically, I'm in the ~/.vim/view dir - which contains files with details like fold locations (line numbers) for all files opened with vim. These are the files that vim uses to restore the same "view" with the proper folds, etc. when one reopens a previously used file. Now (at least on my box) these very useful files seem to have the most curious filenames, e.g. ~=+temp=+test.sh=, or =+temp=+test.sh= These files have info on the last "view" of the ~/temp/test.sh and the /temp/test.sh files respectively.

When I go in this dir, and do something like a ls -l ~=+tem and then hit tab, I'd normally expect it to autocomplete to ~=+temp=+test.sh=

But that doesn't happen. Why? And how (if at all) can I make it happen?

I'm using Bash on FreeBSD. For the record, I've tried this on zsh, csh, tcsh and sh (same OS). I've not added any question tags for specific shells, but do feel free to do so if you think it should be done.

ahron
  • 402

1 Answers1

2

It seems to me that Bash ignores the = and the part before it when completing a filename, probably to support GNU style long options like --some-file=<filename>.

For example, if the files foofoo and foobar exist, typing echo asdf=f<tab>, will autocomplete the prefix foo, and list the two filenames.

With a file called asdf=xyz, echo asdf=a<tab> will happily autocomplete that in the part after the =, giving echo asdf=asdf\=xyz.

So yes, you need to escape the = in Bash when autocompleting filenames. It's not an issue for the resulting command, however, it has no special meaning to the shell in that sense.

On the other hand, the tilde in your file names probably isn't a problem. Unless you have a user called =+temp=+test.sh= it should be left as-is.

ilkkachu
  • 138,973
  • Thanks for clarifying that escaping the '=' is necessary only for autocomplete. Because when I type out the filename as such, there's no need to escape it. – ahron Mar 26 '19 at 05:09