inline vector<string> glob(string pattern, bool only_files = false) {
    unique_ptr<glob_t, decltype(&globfree)> glob_buffer(new glob_t(), globfree);

    glob(pattern.c_str(), GLOB_TILDE, NULL, glob_buffer.get());

    strings fns;
    for (size_t i = 0; i < glob_buffer->gl_pathc; ++i) {
        fns.push_back(string(glob_buffer->gl_pathv[i]));
    }

    if (only_files) {
        strings file_fns;
        for (auto &fn : fns) {
            if (not is_dir(fn))
                file_fns.push_back(fn);
        }
        return file_fns;
    }
    return fns;
}