sfm

simple file manager
git clone git://git.afify.dev/sfm
Log | Files | Refs | README | LICENSE

commit bed4042559f4d597dcfeb215e6ab1bf206c8dd71
parent 66027260af032e04df0edea4b4295249e6deeacc
Author: afify <hassan@afify.dev>
Date:   Sun,  6 Jun 2021 01:56:17 +0300

[feat] toggle dotfiles with . key (#17)

Diffstat:
Mconfig.def.h | 4++++
Msfm.c | 30+++++++++++++++++++++++++++---
2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -90,6 +90,7 @@ static Key nkeys[] = { { {.ch = 'c'}, rname, {0} }, { {.key = TB_KEY_SPACE}, switch_pane, {0} }, { {.ch = '\\'}, bkmrk, {.v = root} }, + { {.ch = '.'}, toggle_df, {0} }, }; /* visual keys */ @@ -114,6 +115,9 @@ static const size_t vkeyslen = LEN(vkeys); static const mode_t ndir_perm = S_IRWXU; static const mode_t nf_perm = S_IRUSR | S_IWUSR; +/* dotfiles */ +static int show_dotfiles = 1; + /* statusbar */ static const char dtfmt[] = "%F %R"; /* date time format */ diff --git a/sfm.c b/sfm.c @@ -151,6 +151,7 @@ static int addwatch(Pane *); static int read_events(void); static void rmwatch(Pane *); static void fsev_shdn(void); +static void toggle_df(const Arg *arg); static void start_filter(const Arg *arg); static void start_vmode(const Arg *arg); static void exit_vmode(const Arg *arg); @@ -1157,6 +1158,23 @@ fsev_shdn(void) } static void +toggle_df(const Arg *arg) +{ + show_dotfiles = !show_dotfiles; + if (cpane == &pane_l) { + if (listdir(&pane_r) < 0) + print_error(strerror(errno)); + if (listdir(&pane_l) < 0) + print_error(strerror(errno)); + } else if (cpane == &pane_r) { + if (listdir(&pane_l) < 0) + print_error(strerror(errno)); + if (listdir(&pane_r) < 0) + print_error(strerror(errno)); + } +} + +static void start_filter(const Arg *arg) { if (cpane->dirc < 1) @@ -1567,9 +1585,15 @@ set_direntr(Pane *pane, struct dirent *entry, DIR *dir, char *filter) pane->direntr = erealloc(pane->direntr, (10 + pane->dirc) * sizeof(Entry)); while ((entry = readdir(dir)) != 0) { - if ((strncmp(entry->d_name, ".", 2) == 0 || - strncmp(entry->d_name, "..", 3) == 0)) - continue; + if (show_dotfiles == 1) { + if (entry->d_name[0] == '.' && + (entry->d_name[1] == '\0' || entry->d_name[1] == '.')) + continue; + } else { + if (entry->d_name[0] == '.') + continue; + + } if (filter == NULL) { ADD_ENTRY