use '.' to toggle hidden files

This commit is contained in:
Night Kaly 2024-03-20 18:21:02 +00:00
parent b459866236
commit 1251bc9aed
No known key found for this signature in database
GPG key ID: 8E829D3381CFEBBE
2 changed files with 12 additions and 2 deletions

13
ccc.c
View file

@ -35,6 +35,7 @@ void draw_border_title(WINDOW *window, bool active);
unsigned int focus = 0; unsigned int focus = 0;
long current_selection = 0; long current_selection = 0;
bool dirs_size = DIRS_SIZE; bool dirs_size = DIRS_SIZE;
bool show_hidden = SHOW_HIDDEN;
char *cwd; char *cwd;
char *p_cwd; /* previous cwd */ char *p_cwd; /* previous cwd */
int half_width; int half_width;
@ -244,9 +245,17 @@ int main(int argc, char** argv)
change_dir(p_cwd, 0); change_dir(p_cwd, 0);
break; break;
/* show help */
case '?': case '?':
show_help(); show_help();
break; break;
case '.':
show_hidden = !show_hidden;
clear_files();
populate_files(cwd, 0);
highlight_current_line();
break;
/* mark one file */ /* mark one file */
case SPACE: case SPACE:
@ -430,8 +439,8 @@ void populate_files(const char *path, int ftype)
filename[0] = '\0'; filename[0] = '\0';
strcat(filename, ep->d_name); strcat(filename, ep->d_name);
/* can't be strncmp as that would filter out the dotfiles */ /* use strncmp to filter out dotfiles */
if (strcmp(filename, ".") && strcmp(filename, "..")) { if ((show_hidden && strncmp(filename, ".", 1) && strncmp(filename, "..", 2)) || (!show_hidden && strcmp(filename, ".") && strcmp(filename, ".."))) {
/* construct full file path */ /* construct full file path */
filename[0] = '\0'; filename[0] = '\0';
strcat(filename, cwd); strcat(filename, cwd);

View file

@ -8,6 +8,7 @@
#define DRAW_BORDERS true /* Draw borders around windows? */ #define DRAW_BORDERS true /* Draw borders around windows? */
#define DRAW_PREVIEW true /* Draw file preview? */ #define DRAW_PREVIEW true /* Draw file preview? */
#define SHOW_HIDDEN true /* show hidden files/dotfiles in preview */
/* set width offset for windows: /* set width offset for windows:
+-------------%-------------+ +-------------%-------------+