aboutsummaryrefslogtreecommitdiff
path: root/sdn.cpp
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2025-11-20 20:49:14 +0100
committerPřemysl Eric Janouch <p@janouch.name>2025-11-20 21:16:30 +0100
commit3e39cc5660e58ea868608ed396abe2db25611b78 (patch)
tree77d3ba093b43bc245aae6e4710f74de8382ed8f1 /sdn.cpp
parent977d1a7120ae66ba40abb770bb00e99bc23d6b0b (diff)
downloadsdn-3e39cc5660e58ea868608ed396abe2db25611b78.tar.gz
sdn-3e39cc5660e58ea868608ed396abe2db25611b78.tar.xz
sdn-3e39cc5660e58ea868608ed396abe2db25611b78.zip
Add and integrate sdn-open
Originally I thought that not supporting %cd would be an issue, making this kind of utility unclean. It turns out the desire to launch xdg-open quickly is stronger.
Diffstat (limited to 'sdn.cpp')
-rw-r--r--sdn.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/sdn.cpp b/sdn.cpp
index 624047a..c5ea7af 100644
--- a/sdn.cpp
+++ b/sdn.cpp
@@ -1,7 +1,7 @@
//
// sdn: simple directory navigator
//
-// Copyright (c) 2017 - 2024, Přemysl Eric Janouch <p@janouch.name>
+// Copyright (c) 2017 - 2025, Přemysl Eric Janouch <p@janouch.name>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted.
@@ -430,8 +430,8 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
#define CTRL(char) ((char) == '?' ? 0x7f : (char) & 0x1f)
#define ACTIONS(XX) XX(NONE) XX(HELP) XX(QUIT) XX(QUIT_NO_CHDIR) \
- XX(ENTER) XX(CHOOSE) XX(CHOOSE_FULL) XX(VIEW_RAW) XX(VIEW) XX(EDIT) \
- XX(SORT_LEFT) XX(SORT_RIGHT) \
+ XX(ENTER) XX(OPEN) XX(CHOOSE) XX(CHOOSE_FULL) \
+ XX(VIEW_RAW) XX(VIEW) XX(EDIT) XX(SORT_LEFT) XX(SORT_RIGHT) \
XX(SELECT) XX(DESELECT) XX(SELECT_TOGGLE) XX(SELECT_ABORT) \
XX(UP) XX(DOWN) XX(TOP) XX(BOTTOM) XX(HIGH) XX(MIDDLE) XX(LOW) \
XX(PAGE_PREVIOUS) XX(PAGE_NEXT) XX(SCROLL_UP) XX(SCROLL_DOWN) XX(CENTER) \
@@ -453,7 +453,7 @@ static const char *g_action_names[] = {ACTIONS(XX)};
static map<wint_t, action> g_normal_actions {
{'\r', ACTION_ENTER}, {KEY (ENTER), ACTION_ENTER},
- {ALT | '\r', ACTION_CHOOSE}, {ALT | KEY (ENTER), ACTION_CHOOSE},
+ {ALT | '\r', ACTION_OPEN}, {ALT | KEY (ENTER), ACTION_OPEN},
{'t', ACTION_CHOOSE}, {'T', ACTION_CHOOSE_FULL},
{KEY (F (1)), ACTION_HELP}, {'h', ACTION_HELP},
{KEY (F (3)), ACTION_VIEW}, {KEY (F (13)), ACTION_VIEW_RAW},
@@ -1056,13 +1056,18 @@ fun run_program (initializer_list<const char *> list, const string &filename) {
update ();
}
+fun sdn_open (const string &filename) {
+ run_program ({(const char *) getenv ("SDN_OPENER"), "sdn-open", "xdg-open"},
+ filename);
+}
+
fun view_raw (const string &filename) {
// XXX: we cannot realistically detect that the pager hasn't made a pause
// at the end of the file, so we can't ensure all contents have been seen
run_program ({(const char *) getenv ("PAGER"), "less", "cat"}, filename);
}
-fun view (const string &filename) {
+fun sdn_view (const string &filename) {
run_program ({(const char *) getenv ("SDN_VIEWER"), "sdn-view",
(const char *) getenv ("PAGER"), "less", "cat"}, filename);
}
@@ -1525,12 +1530,15 @@ fun handle (wint_t c) -> bool {
case ACTION_ENTER:
enter (current);
break;
+ case ACTION_OPEN:
+ sdn_open (current.filename);
+ break;
case ACTION_VIEW_RAW:
// Mimic mc, it does not seem sensible to page directories
(is_directory ? change_dir : view_raw) (current.filename);
break;
case ACTION_VIEW:
- (is_directory ? change_dir : view) (current.filename);
+ (is_directory ? change_dir : sdn_view) (current.filename);
break;
case ACTION_EDIT:
edit (current.filename);