commit a8a01707246d7949a5744668cf39a3dd399b73a7
parent 7a60f15a107452cbe409b478b690ab3f78cc8b0c
Author: Wim Dupont <wim@wimdupont.com>
Date: Mon, 5 Aug 2024 14:11:31 +0200
open exec
Diffstat:
M | cex.c | | | 47 | +++++++++++++++++++++++++++++------------------ |
M | cex.h | | | 3 | ++- |
2 files changed, 31 insertions(+), 19 deletions(-)
diff --git a/cex.c b/cex.c
@@ -202,7 +202,7 @@ start()
change_dir(get_fullpath(chdname, &curwin, curwin.highlight),
RIGHT, c == KEY_VRIGHT_ABS);
else
- open_child();
+ open_child(FALSE);
break;
case KEY_LEFT:
case KEY_VLEFT:
@@ -757,6 +757,12 @@ combo_open(int key)
else
open_nohup_xdg();
break;
+ case KEY_COMBO_OPEN_EXEC:
+ if (is_dir(&curwin, curwin.highlight))
+ change_dir(get_fullpath(chdname, &curwin, curwin.highlight), RIGHT, FALSE);
+ else
+ open_child(TRUE);
+ break;
default:
break;
}
@@ -841,7 +847,7 @@ change_parent_dir(Direction direction)
}
static void
-open_child()
+open_child(bool exec)
{
sigset_t set;
char mime[MIME_MAX], mimedefault[MIME_APP_MAX], pathbuf[PATH_MAX];
@@ -850,20 +856,22 @@ open_child()
if (curwin.message != NULL)
return;
- if (get_mime(mime, MIME_MAX, curwin.winfiles[curwin.highlight].d_name) != 0) {
- move(1, 1);
- clrtoeol();
- printw("Can\'t open %s", curwin.winfiles[curwin.highlight].d_name);
- return;
- }
+ if (!exec) {
+ if (get_mime(mime, MIME_MAX, curwin.winfiles[curwin.highlight].d_name) != 0) {
+ move(1, 1);
+ clrtoeol();
+ printw("Can\'t open %s", curwin.winfiles[curwin.highlight].d_name);
+ return;
+ }
- istext = strncmp(mime, "text/", 5) == 0;
+ istext = strncmp(mime, "text/", 5) == 0;
- if (!istext && get_mime_default(mimedefault, MIME_APP_MAX, mime) != 0) {
- move(1, 1);
- clrtoeol();
- printw("Can\'t open for mime %s", mime);
- return;
+ if (!istext && get_mime_default(mimedefault, MIME_APP_MAX, mime) != 0) {
+ move(1, 1);
+ clrtoeol();
+ printw("Can\'t open for mime %s", mime);
+ return;
+ }
}
endwin();
@@ -875,8 +883,11 @@ open_child()
if (sigprocmask(SIG_BLOCK, &set, NULL) != 0)
fatal("Blocking sigprocmask failed.");
- run_command(PATH_MAX + 12, "%s \"%s\"", istext ? editor : "xdg-open",
- get_fullpath(pathbuf, &curwin, curwin.highlight));
+ if (exec)
+ run_command(PATH_MAX + 4, "\"./%s\"", curwin.winfiles[curwin.highlight].d_name);
+ else
+ run_command(PATH_MAX + 12, "%s \"%s\"", istext ? editor : "xdg-open",
+ get_fullpath(pathbuf, &curwin, curwin.highlight));
if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0)
fatal("Unblocking sigprocmask failed.");
@@ -1296,12 +1307,12 @@ static void
exe_selection(SelAction action, const char *askn)
{
char *pfmt = "%s selection (%d files) ? (y/N) ";
- size_t cmdsize = PATH_MAX*2 + 20, psize = strlen(pfmt) + strlen(askn) + 5;
+ size_t cmdsize = PATH_MAX*2 + 20;
if (selected == NULL || selc == 0)
return;
- if (askn != NULL && !prompt_confirm(psize, pfmt, askn, selc))
+ if (askn != NULL && !prompt_confirm(strlen(pfmt) + strlen(askn) + 5, pfmt, askn, selc))
return;
switch (action) {
diff --git a/cex.h b/cex.h
@@ -40,6 +40,7 @@
#define KEY_COMBO_INF_OPEN 'o'
#define KEY_COMBO_OPEN 'o'
+#define KEY_COMBO_OPEN_EXEC 'x'
#define KEY_COMBO_OPEN_NOHUP_XDG 'o'
#define KEY_COMBO_MAKE 'm'
@@ -112,7 +113,7 @@ static void combo_open(int keypress);
static void combo_make(int keypress);
static void change_dir(const char *chdname, Direction direction, bool abspath);
static void change_parent_dir(Direction direction);
-static void open_child();
+static void open_child(bool exec);
static void open_nohup_xdg();
static void search();
static void move_top(DirWin *dirwin);