-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsfm-sort-ignoredot-0.3.1.diff
46 lines (41 loc) · 1.27 KB
/
sfm-sort-ignoredot-0.3.1.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From e358a1d600b87ab97a9e46563277e404fa129e4b Mon Sep 17 00:00:00 2001
From: tdu <[email protected]>
Date: Wed, 27 Oct 2021 17:42:11 +0300
Subject: [PATCH] Ignore the leading dot character when sorting files by name.
Can be disabled in config.h. Old: .bbb aaa ccc New: aaa
.bbb ccc
---
config.def.h | 1 +
sfm.c | 8 +++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h
index 5f322a8..ac332e1 100644
--- a/config.def.h
+++ b/config.def.h
@@ -122,6 +122,7 @@ static const mode_t nf_perm = S_IRUSR | S_IWUSR;
/* dotfiles */
static int show_dotfiles = 1;
+static const int sort_ignore_dot = 1;
/* statusbar */
static const char dtfmt[] = "%F %R"; /* date time format */
diff --git a/sfm.c b/sfm.c
index 9bb21a1..3b9875a 100644
--- a/sfm.c
+++ b/sfm.c
@@ -411,7 +411,13 @@ sort_name(const void *const A, const void *const B)
if (data1 < data2) {
return -1;
} else if (data1 == data2) {
- result = strncmp((*(Entry *)A).name, (*(Entry *)B).name, MAX_N);
+ char *a = basename((*(Entry *)A).name);
+ char *b = basename((*(Entry *)B).name);
+ if (*a == '.' && sort_ignore_dot)
+ a++;
+ if (*b == '.' && sort_ignore_dot)
+ b++;
+ result = strncmp(a, b, MAX_N);
return result;
} else {
return 1;
--
2.33.0