cex

C/Curses file EXplorer
git clone git://git.wimdupont.com/cex.git
Log | Files | Refs | README | LICENSE

commit 8abcd06c301adae3d81cd9094c3b93d175174184
parent 327b543010dcfe399af2199dd5f231b7c33677cc
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sun, 25 Oct 2026 19:23:44 +0100

added bulk select

Diffstat:
Mcex.c | 61++++++++++++++++++++++++++++++++++++++++++-------------------
Mconfig.def.h | 1+
2 files changed, 43 insertions(+), 19 deletions(-)

diff --git a/cex.c b/cex.c @@ -65,6 +65,7 @@ static void print_content(void); static void print_error(size_t size, const char *fmt, ...); static void show_file_mime(void); static void select_file(const char *path); +static void select_files(void); static void exe_selection(SelAction action, const char *askn); static void clear_selected(void); static void clear_search(void); @@ -123,7 +124,7 @@ static mode_t get_st_mode(DirWin *dirwin, size_t index); static DirWin curwin, parwin, childwin; static char *userhome, *username, *editor, **selected, searchq[SEARCHLEN+1]; -static int maxy, maxx; +static int maxy, maxx, start_sel = -1; static size_t selc, searchc; static bool print_bot, hide = DEFAULT_HIDE, searchcs = DEFAULT_SEARCH_CASE_SENS; @@ -281,7 +282,7 @@ resize(void) void start(void) { - int c; + int c, sel_anchor; char chdname[PATH_MAX]; while ((c = getch()) != KEY_QUIT) { @@ -357,6 +358,13 @@ start(void) set_win_files(&curwin); update_child_win(); break; + case KEY_SEL_FILES: + select_files(); + sel_anchor = start_sel; + set_win_files(&curwin); + start_sel = sel_anchor; + update_child_win(); + break; case KEY_CLEAR_SEL: clear_selected(); set_win_files(&curwin); @@ -460,6 +468,9 @@ set_win_files(DirWin *dirwin) char linkpath[PATH_MAX]; DIR *dir; + if (dirwin->wintype == CURRENT) + start_sel = -1; + free_dirwin(dirwin); if (dirwin->wintype == PARENT && strcmp(curwin.path, "/") == 0) @@ -534,29 +545,19 @@ is_selected(DirWin *dirwin, size_t index) bool remove_selected(const char *sel) { - bool res = FALSE; - - if (selc == 0) - return res; - for (size_t i = 0; i < selc; i++) { if (strcmp(selected[i], sel) == 0) { free(selected[i]); selected[i] = selected[selc-1]; - res = TRUE; - break; + if (--(selc) == 0) { + free(selected); + selected = NULL; + } + return TRUE; } } - if (!res) - return res; - - if (--(selc) == 0) { - free(selected); - selected = NULL; - } - - return res; + return FALSE; } void @@ -1022,7 +1023,6 @@ change_dir(const char *chdname, Direction direction, bool abspath) break; } - set_win_files(&curwin); get_dirname(parwin.path, curwin.path); @@ -1767,6 +1767,28 @@ select_file(const char *path) } void +select_files(void) +{ + char pathbuf[PATH_MAX]; + + if (curwin.winfiles == NULL || curwin.filecount == 0){ + start_sel = -1; + return; + } + + if (start_sel == -1) { + start_sel = curwin.highlight; + return; + } + + for (int i = MIN(start_sel, curwin.highlight); i <= MAX(start_sel, curwin.highlight); i++) + select_file(get_fullpath(pathbuf, &curwin, i)); + + + start_sel = -1; +} + +void clear_selected(void) { if (selected != NULL) @@ -1776,6 +1798,7 @@ clear_selected(void) free(selected); selected = NULL; selc = 0; + start_sel = -1; } void diff --git a/config.def.h b/config.def.h @@ -25,6 +25,7 @@ #define KEY_PREV_SEARCH 'N' #define KEY_HIDE '.' #define KEY_SEL_FILE ' ' +#define KEY_SEL_FILES 0 //ctrl + space #define KEY_CLEAR_SEL 'c' #define KEY_CLEAR_SEARCH 'C' #define KEY_MAKE_FILE 'f'