My dmenu build
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
837 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <dirent.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7. #include <sys/stat.h>
  8. static void lsx(const char *s);
  9. int
  10. main(int argc, char *argv[]) {
  11. int i;
  12. if(argc < 2)
  13. lsx(".");
  14. else if(!strcmp(argv[1], "-v"))
  15. puts("lsx-0.2, © 2006-2011 dmenu engineers, see LICENSE for details");
  16. else for(i = 1; i < argc; i++)
  17. lsx(argv[i]);
  18. return EXIT_SUCCESS;
  19. }
  20. void
  21. lsx(const char *dir) {
  22. char buf[PATH_MAX];
  23. struct dirent *d;
  24. struct stat st;
  25. DIR *dp;
  26. if(!(dp = opendir(dir))) {
  27. perror(dir);
  28. return;
  29. }
  30. while((d = readdir(dp))) {
  31. snprintf(buf, sizeof buf, "%s/%s", dir, d->d_name);
  32. if(stat(buf, &st) == -1)
  33. perror(buf);
  34. else if(S_ISREG(st.st_mode) && access(buf, X_OK) == 0)
  35. puts(d->d_name);
  36. }
  37. closedir(dp);
  38. }