Skip to content

Instantly share code, notes, and snippets.

@yaraki
Created July 3, 2014 13:26
Show Gist options
  • Save yaraki/54c505b8607ac8b42f5b to your computer and use it in GitHub Desktop.
Save yaraki/54c505b8607ac8b42f5b to your computer and use it in GitHub Desktop.
Lists up all the subdirectories in the current directory recursively.
#include <stdio.h>
#include <string.h>
#include <dirent.h>
void list(const char *path)
{
DIR *dir;
struct dirent *entry;
char entry_path[PATH_MAX];
char *entry_name = entry_path;
dir = opendir(path);
if (NULL == dir) {
return;
}
while ((*entry_name++ = *path++))
;
--entry_name;
*entry_name++ = '/';
while (NULL != (entry = readdir(dir))) {
if ('.' == *(entry->d_name)) {
continue;
}
if (DT_DIR == entry->d_type) {
strcpy(entry_name, entry->d_name);
puts(entry_path);
list(entry_path);
}
}
closedir(dir);
}
int main ()
{
list(".");
return 0;
}
@yaraki
Copy link
Author

yaraki commented Oct 5, 2016

Use [F2] to change directory using peco

j() {
        dir=$(simplefind | peco) && cd $dir
}
bind -x '"\eOQ"':"j"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment