commit e3f4f0a72cd184554b594310bad17410ef5d5a7b
parent 8134d11eb5ca81c69357a327e8898c992e099442
Author: Wim Dupont <wim@wimdupont.com>
Date: Fri, 3 Oct 2025 20:52:53 +0200
allow case insensitive search
Diffstat:
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/cex.c b/cex.c
@@ -117,7 +117,7 @@ static DirWin curwin, parwin, childwin;
static char *userhome, *username, *editor, **selected, searchq[SEARCHLEN];
static int maxy, maxx;
static size_t selc, searchc;
-static bool print_bot, hide = DEFAULT_HIDE;
+static bool print_bot, hide = DEFAULT_HIDE, searchcs = DEFAULT_SEARCH_CASE_SENS;
int
main(int argc, char **argv)
@@ -310,6 +310,12 @@ start(void)
search();
update_child_win();
break;
+ case KEY_SEARCH_CASE:
+ searchcs = searchcs ? FALSE : TRUE;
+ set_win_files(&curwin);
+ set_win_files(&parwin);
+ update_child_win();
+ break;
case KEY_NEXT_SEARCH:
next_search();
update_child_win();
@@ -589,7 +595,8 @@ print_win(DirWin *dirwin)
} else
mvwaddstr(dirwin->window, y, x, name);
if (dirwin->wintype == CURRENT && searchc > 0
- && ((subs = strstr(name, searchq)) != NULL)) {
+ && (((!searchcs && ((subs = strcasestr(name, searchq)) != NULL)))
+ || (((subs = strstr(name, searchq)) != NULL)))) {
sindex = (int) (subs - name);
wattron(dirwin->window, COLOR_PAIR(SEARCH_MATCH_COLOR));
if (dirwin->usehighlight && dirwin->highlight == i)
@@ -1132,7 +1139,8 @@ next_search(void)
return;
for (int i = curwin.highlight; i < MAX(curwin.filecount-1, 0); i++) {
- if ((strstr(curwin.winfiles[i+1].d_name, searchq) != NULL)) {
+ if ((!searchcs && ((strcasestr(curwin.winfiles[i+1].d_name, searchq) != NULL)))
+ || ((strstr(curwin.winfiles[i+1].d_name, searchq) != NULL))) {
curwin.highlight = i+1;
return;
}
@@ -1146,7 +1154,8 @@ prev_search(void)
return;
for (int i = curwin.highlight; i > 0; i--) {
- if ((strstr(curwin.winfiles[i-1].d_name, searchq) != NULL)) {
+ if ((!searchcs && ((strcasestr(curwin.winfiles[i-1].d_name, searchq) != NULL)))
+ || ((strstr(curwin.winfiles[i-1].d_name, searchq) != NULL))) {
curwin.highlight = i-1;
return;
}
diff --git a/config.def.h b/config.def.h
@@ -2,6 +2,7 @@
#define CONFIG_H
#define DEFAULT_HIDE TRUE
+#define DEFAULT_SEARCH_CASE_SENS FALSE
#define SIZE_DECIMAL_FORMAT FALSE
#define MIME_MAX 255
#define MIME_APP_MAX 255
@@ -31,6 +32,7 @@
#define KEY_CP_SEL 'p'
#define KEY_RM_SEL 'd'
#define KEY_MV_SEL 'M'
+#define KEY_SEARCH_CASE 's'
#define KEY_SEARCH '/'
#define KEY_COMBO_GO 'g'