Created
September 18, 2013 08:49
-
-
Save sgur/6606428 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import vim | |
import re | |
import os | |
import os.path | |
import fnmatch | |
custom_ignore = vim.eval('g:ctrlp_custom_ignore') | |
if custom_ignore['dir'][:2] == '\\v': | |
custom_ignore['dir'] = custom_ignore['dir'][2 :] | |
if custom_ignore['file'][:2] == '\\v': | |
custom_ignore['file'] = custom_ignore['file'][2 :] | |
if custom_ignore['link'][:2] == '\\v': | |
custom_ignore['link'] = custom_ignore['link'][2 :] | |
fs_encoding = vim.eval('&termencoding') | |
progress_fn = vim.Function('ctrlp#progress') | |
max_depth = int(vim.eval('exists("b:ctrlp_max_depth") ? b:ctrlp_max_depth : g:ctrlp_max_depth')) | |
wildignore = vim.eval('&wildignore').split(',') | |
def glob(base_dir): | |
start = base_dir.count(os.sep) | |
files_path = [] | |
for root, dirs, files in os.walk(base_dir, topdown=True): | |
files_path += filter((lambda x: re.match(custom_ignore["file"], x) == None), map((lambda x: os.path.join(os.path.normpath(root), x).decode(fs_encoding)), files)) | |
progress_fn(len(files_path), 1) | |
for i in reversed(range(len(dirs))): | |
depth = os.path.join(os.path.normpath(root), dirs[i]).count(os.sep) | |
if depth - start >= max_depth or dirs[i][0] == '.' \ | |
or re.match(custom_ignore["dir"], dirs[i]) != None: | |
del dirs[i] | |
for ptn in wildignore: | |
files_path = filter((lambda x: not fnmatch.fnmatch(x, ptn)), files_path) | |
return files_path | |
files = glob(sys.argv[0].replace('\\ ', ' ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment