diff --git a/Makefile b/Makefile index a5ec0a4..e215440 100644 --- a/Makefile +++ b/Makefile @@ -81,7 +81,6 @@ uninstall: fi; \ [ ! "$$prefix" ] && prefix="/usr/local"; \ [ ! "$$sysconfdir" ] && sysconfdir=/etc; \ - [ ! "$$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME=~/.config; \ echo "Deleting..."; \ rm -rvf "$$prefix/bin/$(NAME)" "$$prefix/share/man/man1/$(NAME).1" "$$sysconfdir/xdg/bb"; \ printf "\033[1mIf you created any config files in ~/.config/bb, you may want to delete them manually.\033[0m" diff --git a/bb.c b/bb.c index d5cda7a..fad458f 100644 --- a/bb.c +++ b/bb.c @@ -460,27 +460,21 @@ int populate_files(bb_t *bb, const char *path) bb->files[bb->nfiles++] = e; } } else { - DIR *dir = opendir(bb->path); - if (!dir) - err("Couldn't open dir: %s", bb->path); - - for (struct dirent *dp; (dp = readdir(dir)) != NULL; ) { - if (dp->d_name[0] == '.') { - if (dp->d_name[1] == '.' && dp->d_name[2] == '\0') { - if (!bb->show_dotdot || strcmp(bb->path, "/") == 0) continue; - } else if (dp->d_name[1] == '\0') { - if (!bb->show_dot) continue; - } else if (!bb->show_dotfiles) continue; - } + glob_t globbuf = {0}; + char *pat, *tmpglob = memcheck(strdup(bb->globpats)); + while ((pat = strsep(&tmpglob, " ")) != NULL) + glob(pat, GLOB_NOSORT|GLOB_APPEND, NULL, &globbuf); + free(tmpglob); + for (size_t i = 0; i < globbuf.gl_pathc; i++) { if ((size_t)bb->nfiles + 1 > space) bb->files = memcheck(realloc(bb->files, (space += 100)*sizeof(void*))); // Don't normalize path so we can get "." and ".." - entry_t *entry = load_entry(bb, dp->d_name); - if (!entry) err("Failed to load entry: '%s'", dp->d_name); + entry_t *entry = load_entry(bb, globbuf.gl_pathv[i]); + if (!entry) err("Failed to load entry: '%s'", globbuf.gl_pathv[i]); entry->index = bb->nfiles; bb->files[bb->nfiles++] = entry; } - closedir(dir); + globfree(&globbuf); } for (int i = 0; i < bb->nfiles; i++) { @@ -551,10 +545,10 @@ void run_bbcmd(bb_t *bb, const char *cmd) if (value) ++value; #define set_bool(target) do { if (!value) { target = !target; } else { target = value[0] == '1'; } } while (0) if (matches_cmd(cmd, ".")) { // +. - set_bool(bb->show_dot); + set_globs(bb, ". *"); populate_files(bb, bb->path); } else if (matches_cmd(cmd, "..")) { // +.. - set_bool(bb->show_dotdot); + set_globs(bb, ".. *"); populate_files(bb, bb->path); } else if (matches_cmd(cmd, "bind:")) { // +bind::