Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit 5b1387d72128c17a91f07f95d93aae269781bf7e Author: Raniconduh <clagv.randomgames@gmail.com> Date: Sat Oct 23 12:50:04 2021 +0000 added file searching Update README.md diff --git a/README.md b/README.md index 580b713..4f6d5de 100644 --- a/README.md +++ b/README.md @@ -207 +207 @@ Files will be highlighted and shown with an identifier in correspondence to the  * Magenta, `=`: Unix socket  * White, No identifier: Regular file   -Files that are are executable but have another identifier will keep the identifier but be colored green. Symbolic links that point to directories will be suffixed with `@ => /` and may be entered as a normal directory. Otherwise, deletion of a symbolic link will not delete whatever the link points to; only the link itself and opening one will open what the link points to. +Files that are executable but have another identifier will keep the identifier but be colored green. Symbolic links that point to directories will be suffixed with `@ => /` and may be entered as a normal directory. Otherwise, deletion of a symbolic link will not delete whatever the link points to; only the link itself and opening one will open what the link points to.    ### Options   @@ -386 +387 @@ Files that are are executable but have another identifier will keep the identifi  * `d`: Delete the file the cursor is on (a prompt will be shown first)  * `m`: Mark the file the cursor is on  * `:`: Open a commands prompt ([see 'Command Prompt' section](#command-prompt)) +* `/`: Search for a file in the current directory using a POSIX regex  * `q`: Quit    #### Command Prompt diff --git a/include/commands.h b/include/commands.h index 2e9ed72..78d7810 100644 --- a/include/commands.h +++ b/include/commands.h @@ -34 +35 @@  #endif    void ext_open(char *); +long search_file(long, char *);   diff --git a/src/commands.c b/src/commands.c index 5a98c6a..1746ba5 100644 --- a/src/commands.c +++ b/src/commands.c @@ -26 +27 @@  #include <unistd.h>  #include <string.h>  #include <stdio.h> +#include <regex.h>  #include <sys/wait.h>    #include "dir.h" @@ -213 +2226 @@ void ext_open(char * file) {   free(f);  }   + +long search_file(long c, char * s) { + long ret = -1; + regex_t r; + regcomp(&r, s, REG_EXTENDED); + for (long i = c; i < (signed)n_dir_entries; i++) { + if (!regexec(&r, dir_entries[i]->name, 0, NULL, 0)) { + ret = i; + break; + } + } + + if (ret == -1 && c > 1) { + for (long i = 0; i < c; i++) + if (!regexec(&r, dir_entries[i]->name, 0, NULL, 0)) { + ret = i; + break; + } + } + regfree(&r); + return ret; +} + diff --git a/src/main.c b/src/main.c index 3d32222..e8228ac 100644 --- a/src/main.c +++ b/src/main.c @@ -1866 +18617 @@ int main(int argc, char ** argv) {   unmark_all();   free(inp);   break; + case '/':; + char * search_str = curses_getline("/"); + long c = search_file(cursor, search_str); + free(search_str); + + if (c == -1) break; + + cursor = c + 1; + last_f = n_dir_entries - cursor > (unsigned)LINES - 6 ? cursor + LINES - 6 : n_dir_entries; + first_f = cursor > (unsigned)LINES - 6 ? last_f - LINES + 6 : 0; + break;   case 'q':   goto done;   default: