Introduction
Introduction Statistics Contact Development Disclaimer Help
Add directory sorting - noice - small file browser (mirror / fork from 2f30.org)
git clone git://git.codemadness.org/noice
Log
Files
Refs
README
LICENSE
---
commit 4799ca8afd18a7443bdb4faff2ce2c5cd02b84e8
parent 3ae2cb00d7db3a1aec7d0687bdc32c814d96581a
Author: dok <[email protected]>
Date: Sun, 6 Jan 2019 18:42:49 +0100
Add directory sorting
Diffstat:
M config.def.h | 3 +++
M noice.1 | 2 ++
M noice.c | 25 +++++++++++++++++++++++++
3 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/config.def.h b/config.def.h
@@ -3,6 +3,7 @@
#define CURSR " > "
#define EMPTY " "
+int dirorder = 0; /* Set to 1 to sort by directory first */
int mtimeorder = 0; /* Set to 1 to sort by time modified */
int icaseorder = 0; /* Set to 1 to sort by ignoring case */
int idletimeout = 0; /* Screensaver timeout in seconds, 0 to disable */
@@ -79,6 +80,8 @@ struct key bindings[] = {
{ '~', SEL_CDHOME },
/* Toggle hide .dot files */
{ '.', SEL_TOGGLEDOT },
+ /* Toggle sort by directory first */
+ { 'd', SEL_DSORT },
/* Toggle sort by time */
{ 't', SEL_MTIME },
/* Toggle case sensitivity */
diff --git a/noice.1 b/noice.1
@@ -57,6 +57,8 @@ Change to the
directory.
.It Ic \&.
Toggle hidden .dot files.
+.It Ic d
+Toggle sort by directory first.
.It Ic t
Toggle sort by time modified.
.It Ic i
diff --git a/noice.c b/noice.c
@@ -65,6 +65,7 @@ enum action {
SEL_CD,
SEL_CDHOME,
SEL_TOGGLEDOT,
+ SEL_DSORT,
SEL_MTIME,
SEL_ICASE,
SEL_REDRAW,
@@ -266,10 +267,28 @@ visible(regex_t *regex, char *file)
}
int
+dircmp(mode_t a, mode_t b)
+{
+ if (S_ISDIR(a) && S_ISDIR(b))
+ return 0;
+ if (!S_ISDIR(a) && !S_ISDIR(b))
+ return 0;
+ if (S_ISDIR(a))
+ return -1;
+ else
+ return 1;
+}
+
+int
entrycmp(const void *va, const void *vb)
{
const struct entry *a = va, *b = vb;
+ if (dirorder) {
+ if (dircmp(a->mode, b->mode) != 0)
+ return dircmp(a->mode, b->mode);
+ }
+
if (mtimeorder)
return b->t - a->t;
if (icaseorder)
@@ -801,6 +820,12 @@ nochange:
if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(…
goto begin;
+ case SEL_DSORT:
+ dirorder = !dirorder;
+ /* Save current */
+ if (ndents > 0)
+ mkpath(path, dents[cur].name, oldpath, sizeof(…
+ goto begin;
case SEL_ICASE:
icaseorder = !icaseorder;
/* Save current */
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.