contrib/casesmash.py
author Sean Farley <sean.michael.farley@gmail.com>
Wed, 20 Nov 2013 14:45:18 -0500
changeset 20126 25cb1d96c307
parent 19378 9de689d20230
child 28351 42a7301fb4d5
permissions -rw-r--r--
bash_completion: fix issue with subdirectories not being completed Previously, if there was a directory between the file and first-level directory (e.g. 'bar' in foo/bar/file), then bash_completion would only list 'foo/file' instead of 'foo/bar/file'. This behavior was introduced in 80f3ae36f908 to fix spaces in file names. In this patch, we keep that behavior while also fixing subdirectory completion by reverting 80f3ae36f908 and instead add backslashes to whitespace manually. This approach means adding the completion option 'nospace' since we do this manually now.

import os, __builtin__
from mercurial import util

def lowerwrap(scope, funcname):
    f = getattr(scope, funcname)
    def wrap(fname, *args, **kwargs):
        d, base = os.path.split(fname)
        try:
            files = os.listdir(d or '.')
        except OSError:
            files = []
        if base in files:
            return f(fname, *args, **kwargs)
        for fn in files:
            if fn.lower() == base.lower():
                return f(os.path.join(d, fn), *args, **kwargs)
        return f(fname, *args, **kwargs)
    scope.__dict__[funcname] = wrap

def normcase(path):
    return path.lower()

os.path.normcase = normcase

for f in 'file open'.split():
    lowerwrap(__builtin__, f)

for f in "chmod chown open lstat stat remove unlink".split():
    lowerwrap(os, f)

for f in "exists lexists".split():
    lowerwrap(os.path, f)

lowerwrap(util, 'posixfile')