Added fzf for searching and updated todo

pull/2/head
mananapr 5 years ago
parent 9154018ba3
commit 104a8a30b9

@ -28,3 +28,6 @@ a similar UI.
- [x] Add functionality to open files
- [x] Add image previews using w3mimgdisplay
- [ ] Preserve aspect ratio in image previews
- [x] Add fuzzy file search using fzf
- [ ] Find a way to redraw windows after displaying image previews or running fzf
- [ ] Supress output from xdg-open

49
cf.c

@ -47,6 +47,22 @@ void getPreview(char *filepath, int maxy, int maxx)
}
}
/*
Gets path of parent directory
*/
void getParentPath(char *path)
{
char *p;
p = strrchr(path,'/');
path[p-path] = '\0';
// Parent directory is root
if(path[0] != '/')
{
path[0] = '/';
path[1] = '\0';
}
}
/*
Creates a new window with dimensions `height` and `width` starting at `starty` and `startx`
@ -223,16 +239,8 @@ int main(int argc, char* argv[])
char prev_dir[250] = "";
// Get path of parent directory
char *p;
strcat(prev_dir, dir);
p = strrchr(dir,'/');
prev_dir[p-dir] = '\0';
// Parent directory is root
if(prev_dir[0] != '/')
{
prev_dir[0] = '/';
prev_dir[1] = '\0';
}
getParentPath(prev_dir);
// Get path of child directory
strcat(next_dir, dir);
@ -268,6 +276,10 @@ int main(int argc, char* argv[])
wrefresh(current_win);
wrefresh(preview_win);
// For fzf file search
char cmd[250];
char buf[250];
FILE *fp;
// Keybindings
switch( ch = wgetch(current_win) ) {
@ -335,6 +347,25 @@ int main(int argc, char* argv[])
else
start = 0;
break;
case 'F':
sprintf(cmd,"cd %s && fzf",info->pw_dir);
if((fp = popen(cmd,"r")) == NULL)
{
exit(0);
}
noecho();
curs_set(0);
wrefresh(current_win);
wrefresh(preview_win);
while(fgets(buf,250,fp) != NULL){}
char path[250];
sprintf(path, "%s/%s",info->pw_dir,buf);
getParentPath(path);
strcpy(dir,path);
selection = 0;
start = 0;
break;
}

Loading…
Cancel
Save