Thumbnail

rani/cscroll.git

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

commit 16da0af8b6a88dc359265ae89f301af2a039579f Author: Raniconduh <clagv.randomgames@gmail.com> Date: Fri Oct 21 09:48:42 2022 +0000 add custom opener var diff --git a/include/opts.h b/include/opts.h index e9db966..daa6a70 100644 --- a/include/opts.h +++ b/include/opts.h @@ -106 +1011 @@    #define COLOR_DEFAULT 0xFFFFFFFF   +struct opener_t { + char * fpath; + size_t nlen; +}; +  #define ICONS_VAR "icons"  extern bool show_icons;  #define DOTS_VAR "dots" @@ -386 +438 @@ extern uint32_t exec_color;  extern uint32_t media_color;  #define ARCHIVE_COLOR_VAR "archive_color"  extern uint32_t archive_color; +#define OPENER_VAR "opener" +extern struct opener_t opener;    extern uint32_t custom_colors[11];   diff --git a/src/commands.c b/src/commands.c index 8712ac3..9c3ace7 100644 --- a/src/commands.c +++ b/src/commands.c @@ -2911 +2915 @@ void ext_open(char * file) {   endwin();   pid_t pid = fork();   if (!pid) { + if (!opener.fpath){  #if defined(__APPLE__) || defined(__MACH__) - execvp("open", (char*[3]){"open", f, NULL}); + execvp("open", (char*[3]){"open", f, NULL});  #else - execvp("xdg-open", (char*[3]){"xdg-open", f, NULL}); + execvp("xdg-open", (char*[3]){"xdg-open", f, NULL});  #endif + } else { + execvp(opener.fpath, (char*[3]){opener.fpath, f, NULL}); + }   exit(0);   }   wait(NULL); diff --git a/src/opts.c b/src/opts.c index d157d83..8c1f0ac 100644 --- a/src/opts.c +++ b/src/opts.c @@ -196 +197 @@ bool color = true;  bool p_long = false;  bool oneshot = false;  bool show_dot_dirs = false; +struct opener_t opener = {NULL, 0};    uint32_t custom_colors[11];   diff --git a/src/var.c b/src/var.c index 89988a3..2ff50ad 100644 --- a/src/var.c +++ b/src/var.c @@ -16 +17 @@  #include <stdbool.h>  #include <ncurses.h>  #include <stddef.h> +#include <stdlib.h>  #include <stdint.h>  #include <string.h>  #include <ctype.h> @@ -1388 +13931 @@ static void set_archive(void * p) {  }     +static void set_opener(void * p) { + char * s = (char*)p; + if (s && *s) { + size_t l = strlen(s); + if (l < opener.nlen) { + opener.nlen = l; + opener.fpath = realloc(opener.fpath, l + 1); + strcpy(opener.fpath, s); + } else if (l == opener.nlen) { + strcpy(opener.fpath, s); + } else { /* l > nlen */ + opener.nlen = l; + opener.fpath = realloc(opener.fpath, l + 1); + strcpy(opener.fpath, s); + } + } else { + if (opener.fpath) free(opener.fpath); + opener.fpath = NULL; + opener.nlen = 0; + } +} + +  void var_init(void) { - var_map = map_new(14); + var_map = map_new(15);     map_insert(var_map, ICONS_VAR, set_icons);   map_insert(var_map, COLOR_VAR, set_color_f); @@ -1566 +1808 @@ void var_init(void) {   map_insert(var_map, EXEC_COLOR_VAR, set_exec);   map_insert(var_map, MEDIA_COLOR_VAR, set_media);   map_insert(var_map, ARCHIVE_COLOR_VAR, set_archive); + + map_insert(var_map, OPENER_VAR, set_opener);  }     @@ -1704 +1965 @@ bool var_set(char * k, void * p) {    void terminate_var(void) {   map_nuke(var_map); + free(opener.fpath);  }