Skip to content

Commit

Permalink
[feat] toggle dotfiles with . key (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
afify committed Jun 5, 2021
1 parent 6602726 commit bed4042
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */

Expand Down
30 changes: 27 additions & 3 deletions sfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1156,6 +1157,23 @@ fsev_shdn(void)
#endif
}

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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bed4042

Please sign in to comment.