Compare commits

..

No commits in common. "f3fffe4b25ed2a4d6ff2bcd5ffdff8d095a857fc" and "d6846e63276365ae554671621532a4f63a86cbf4" have entirely different histories.

2 changed files with 16 additions and 19 deletions

View File

@ -11,8 +11,8 @@ commands. It enables you to:
can be simply forwarded if it is to be edited. What's more, it will always
be obvious whether the navigator is running.
The only supported platform is Linux. I wanted to try a different, simpler
approach here, and the end result is very friendly to tinkering.
Development has just started and the only supported platform is Linux.
I wanted to try a different, simpler approach here.
Building
--------

31
sdn.cpp
View File

@ -38,7 +38,6 @@
#include <fcntl.h>
#include <pwd.h>
#include <grp.h>
#include <libgen.h>
#include <sys/inotify.h>
#include <sys/xattr.h>
@ -253,11 +252,9 @@ fun xdg_config_find (const string &suffix) -> unique_ptr<ifstream> {
fun xdg_config_write (const string &suffix) -> unique_ptr<fstream> {
auto dir = xdg_config_home ();
if (dir[0] == '/') {
auto path = dir + "/" PROJECT_NAME "/" + suffix;
if (!fork ())
_exit (-execlp ("mkdir", "mkdir", "-p",
dirname (strdup (path.c_str ())), NULL));
if (fstream fs {path, fstream::in | fstream::out | fstream::trunc})
// TODO: try to create the end directory
if (fstream fs {dir + "/" PROJECT_NAME "/" + suffix,
fstream::in | fstream::out | fstream::trunc})
return make_unique<fstream> (move (fs));
}
return nullptr;
@ -371,8 +368,7 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
#define KEY(name) (SYM | KEY_ ## name)
#define CTRL 31 &
#define ACTIONS(XX) XX(NONE) XX(HELP) XX(QUIT) XX(QUIT_NO_CHDIR) \
XX(CHOOSE) XX(CHOOSE_FULL) \
#define ACTIONS(XX) XX(NONE) XX(CHOOSE) XX(CHOOSE_FULL) XX(HELP) XX(QUIT) \
XX(UP) XX(DOWN) XX(TOP) XX(BOTTOM) XX(PAGE_PREVIOUS) XX(PAGE_NEXT) \
XX(SCROLL_UP) XX(SCROLL_DOWN) XX(CHDIR) XX(GO_START) XX(GO_HOME) \
XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) \
@ -390,9 +386,8 @@ static const char *g_action_names[] = {ACTIONS(XX)};
static map<wint_t, action> g_normal_actions {
{ALT | '\r', ACTION_CHOOSE_FULL}, {ALT | KEY (ENTER), ACTION_CHOOSE_FULL},
{'\r', ACTION_CHOOSE}, {KEY (ENTER), ACTION_CHOOSE}, {'h', ACTION_HELP},
{'q', ACTION_QUIT}, {ALT | 'q', ACTION_QUIT_NO_CHDIR},
// M-o ought to be the same shortcut the navigator is launched with
{ALT | 'o', ACTION_QUIT},
{ALT | 'o', ACTION_QUIT}, {'q', ACTION_QUIT},
{'k', ACTION_UP}, {CTRL 'p', ACTION_UP}, {KEY (UP), ACTION_UP},
{'j', ACTION_DOWN}, {CTRL 'n', ACTION_DOWN}, {KEY (DOWN), ACTION_DOWN},
{'g', ACTION_TOP}, {ALT | '<', ACTION_TOP}, {KEY (HOME), ACTION_TOP},
@ -470,7 +465,7 @@ static struct {
int message_ttl; ///< Time to live for the message
string chosen; ///< Chosen item for the command line
bool no_chdir; ///< Do not tell the shell to chdir
bool chosen_full; ///< Use the full path
int inotify_fd, inotify_wd = -1; ///< File watch
bool out_of_date; ///< Entries may be out of date
@ -901,8 +896,8 @@ fun handle (wint_t c) -> bool {
auto i = g_normal_actions.find (c);
switch (i == g_normal_actions.end () ? ACTION_NONE : i->second) {
case ACTION_CHOOSE_FULL:
g.chosen = g.cwd + "/" + current.filename;
g.no_chdir = true;
g.chosen_full = true;
g.chosen = current.filename;
return false;
case ACTION_CHOOSE:
if (choose (current))
@ -911,9 +906,6 @@ fun handle (wint_t c) -> bool {
case ACTION_HELP:
show_help ();
return true;
case ACTION_QUIT_NO_CHDIR:
g.no_chdir = true;
return false;
case ACTION_QUIT:
return false;
@ -1334,7 +1326,12 @@ int main (int argc, char *argv[]) {
// We can't portably create a standard stream from an FD, so modify the FD
dup2 (output_fd, STDOUT_FILENO);
if (g.cwd != g.start_dir && !g.no_chdir)
if (g.chosen_full) {
auto full_path = g.cwd + "/" + g.chosen;
cout << "local insert=" << shell_escape (full_path) << endl;
return 0;
}
if (g.cwd != g.start_dir)
cout << "local cd=" << shell_escape (g.cwd) << endl;
if (!g.chosen.empty ())
cout << "local insert=" << shell_escape (g.chosen) << endl;