cex

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

commit f86b88c00a16af75bdde3c11028b44cfd155f9c9
parent 5b2481886e8792d6c2d2a4b664c501e78decb66a
Author: Wim Dupont <wim@wimdupont.com>
Date:   Sat, 22 Mar 2025 12:28:35 +0100

added change default xdg-open

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

diff --git a/cex.c b/cex.c @@ -94,7 +94,9 @@ static int read_command(char *buf, size_t bufsize, const char *cmd); static int make_file(const char *path); static int make_dir(const char *path); static int make_mod(void); -static int make_access(void); +static void make_access(void); +static void make_open_default(void); +static void make_mime_default(const char *mime, const char *app); static int rm_file(const char *fname); static int rename_file(const char *fname); static char *prompt_answer(char *buf, size_t size, const char *question); @@ -756,10 +758,16 @@ print_content(void) void show_file_mime(void) { - char buf[MIME_MAX]; + int appsize = 256; + char mimebuf[MIME_MAX], appbuf[appsize], buf[MIME_MAX+appsize]; - if (get_mime(buf, MIME_MAX, curwin.winfiles[curwin.highlight].d_name) != 0) - cpstr(buf, "Can't retrieve mime."); + if (get_mime(mimebuf, MIME_MAX, curwin.winfiles[curwin.highlight].d_name) != 0) + cpstr(mimebuf, "Can't retrieve mime."); + + if (get_mime_default(appbuf, appsize, mimebuf) != 0) + cpstr(appbuf, "Can't retrieve default for mime."); + + snprintf(buf, MIME_MAX+appsize, "%s: %s", mimebuf, appbuf); move(1, 1); clrtoeol(); @@ -878,6 +886,9 @@ combo_make(int key) case KEY_COMBO_MAKE_ACCESS: make_access(); break; + case KEY_COMBO_MAKE_OPEN_DEFAULT: + make_open_default(); + break; default: break; } @@ -1383,7 +1394,7 @@ make_mod(void) return 0; } -int +void make_access(void) { char pathbuf[PATH_MAX], *cmdfmt = "ln -s \"%s\" \"%s\"", *pfmt = "Make access \"%s\"? (y/N) "; @@ -1394,6 +1405,32 @@ make_access(void) } void +make_open_default(void) +{ + int appsize = 256, qsize = MIME_MAX+25; + char mime[MIME_MAX], question[qsize], app[appsize]; + + if (get_mime(mime, MIME_MAX, curwin.winfiles[curwin.highlight].d_name) != 0) + cpstr(mime, "Can't retrieve mime."); + + snprintf(question, qsize, "Application for mime %s?", mime); + + prompt_answer(app, appsize, question); + + if (strlen(app) > 0) + make_mime_default(mime, app); +} + +void +make_mime_default(const char *mime, const char *app) +{ + char *cmdfmt = "xdg-mime default \"%s\" \"%s\""; + size_t cmdsize = MIME_MAX + 256 + strlen(cmdfmt); + + run_command(cmdsize, cmdfmt, app, mime); +} + +void exe_selection(SelAction action, const char *askn) { char *pfmt = "%s selection (%d files) ? (y/N) "; diff --git a/config.def.h b/config.def.h @@ -48,6 +48,7 @@ #define KEY_COMBO_MAKE_DIR 'd' #define KEY_COMBO_MAKE_MOD 'm' #define KEY_COMBO_MAKE_ACCESS 'a' +#define KEY_COMBO_MAKE_OPEN_DEFAULT 'o' #define DIR_COLOR COLOR_BLUE #define LN_COLOR COLOR_CYAN