<commit_before>
local exports = {}

local path = require('path')
local w = require('tables').wrap

exports.dirs = function(word)
    -- Strip off any path components that may be on text.
    local prefix = ""
    local i = word:find("[\\/:][^\\/:]*$")
    if i then
        prefix = word:sub(1, i)
    end
    local include_dots = word:find("%.+$") ~= nil

    -- Find matches.
    local matches = w(clink.find_dirs(word.."*", true))
    :filter(function (dir)
        return clink.is_match(word, prefix..dir) and
            (include_dots or path.is_real_dir(dir))
    end)
    :map(function(dir)
        return prefix..dir
    end)

    -- If there was no matches but word is a dir then use it as the single match.
    -- Otherwise tell readline that matches are files and it will do magic.
    if #matches == 0 and clink.is_dir(rl_state.text) then
        return {rl_state.text}
    end

    clink.matches_are_files()
    return matches
end

exports.files = function (word)
    -- Strip off any path components that may be on text.
    local prefix = ""
    local i = word:find("[\\/:][^\\/:]*$")
    if i then
        prefix = word:sub(1, i)
    end

    -- Find matches.
    local matches = w(clink.find_files(word.."*", true))
    :filter(function (file)
        return clink.is_match(word, prefix..file)
    end)
    :map(function(file)
        return prefix..file
    end)

    -- Tell readline that matches are files and it will do magic.
    if #matches ~= 0 then
        clink.matches_are_files()
    end

    return matches
end

exports.create_dirs_matcher = function (dir_pattern, show_dotfiles)
    return function (token)
        return w(clink.find_dirs(dir_pattern))
        :filter(function(dir)
            return clink.is_match(token, dir) and (path.is_real_dir(dir) or show_dotfiles)
        end )
    end
end

exports.create_files_matcher = function (file_pattern)
    return function (token)
        return w(clink.find_files(file_pattern))
        :filter(function(file)
            -- Filter out '.' and '..' entries as well<commit_msg>clink: use clink's builtin matchers<commit_after>
local exports = {}

local path = require('path')
local w = require('tables').wrap

exports.dirs = clink.dirmatches

exports.files = clink.filematches

exports.create_dirs_matcher = function (dir_pattern, show_dotfiles)
    return function (token)
        return w(clink.find_dirs(dir_pattern))
        :filter(function(dir)
            return clink.is_match(token, dir) and (path.is_real_dir(dir) or show_dotfiles)
        end )
    end
end

exports.create_files_matcher = function (file_pattern)
    return function (token)
        return w(clink.find_files(file_pattern))
        :filter(function(file)
            -- Filter out '.' and '..' entries as well
{'fraction_non_alphanumeric': 0.11732851985559567, 'fraction_numerical': 0.001444043321299639, 'mean_word_length': 2.6799468791500662, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4120077', 'n_tokens_mistral': 886, 'n_tokens_neox': 875, 'n_words': 246}