]> Sergey Matveev's repositories - nnn.git/commitdiff
Force undetachable edits in EDITOR
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 23 Nov 2019 20:24:06 +0000 (01:54 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 23 Nov 2019 20:24:06 +0000 (01:54 +0530)
README.md
plugins/nmount
src/nnn.c

index 8f1de98709eb6ad02e0a2018cebbcb4c2f8a58de..4bd556207b2157a5965e8106090d871e8ff24605 100644 (file)
--- a/README.md
+++ b/README.md
@@ -172,6 +172,7 @@ optional args:
  -c      cli-only opener
  -d      detail mode
  -e name load session by name
+ -E      EDITOR for undetached edits
  -f      run filter as cmd on prompt key
  -H      show hidden files
  -i      nav-as-you-type mode
index 3f638bf45ed9ce1dad283dc4c38f030e290baee7..566119ec6037cdd1a18face4dd3211fe07052ed7 100755 (executable)
@@ -20,7 +20,7 @@ prompt="device name ['l' lists]: "
 
 lsblk
 
-printf "\nMake sure you aren't still in the mounted device."
+printf "\nEnsure you aren't still in the mounted device.\n"
 printf "%s" "$prompt"
 read -r dev
 
index 018ada3382a44ac9884b47ac932258efbd6ee0c0..089bbeb155523e1e95c0b28cc90385acea5bbfa3 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -226,7 +226,7 @@ typedef struct {
        uint selmode    : 1;  /* Set when selecting files */
        uint showdetail : 1;  /* Clear to show fewer file info */
        uint ctxactive  : 1;  /* Context active or not */
-       uint reserved   : 5;
+       uint reserved   : 4;
        /* The following settings are global */
        uint curctx     : 2;  /* Current context number */
        uint dircolor   : 1;  /* Current status of dir color */
@@ -243,6 +243,7 @@ typedef struct {
        uint trash      : 1;  /* Move removed files to trash */
        uint mtime      : 1;  /* Use modification time (else access time) */
        uint cliopener  : 1;  /* All-CLI app opener */
+       uint waitedit   : 1;  /* For ops that can't be detached, used EDITOR */
 } settings;
 
 /* Contexts or workspaces */
@@ -293,6 +294,7 @@ static settings cfg = {
        0, /* trash */
        1, /* mtime */
        0, /* cliopener */
+       0, /* waitedit */
 };
 
 static context g_ctx[CTX_MAX] __attribute__ ((aligned));
@@ -307,6 +309,7 @@ static char *pluginstr;
 static char *opener;
 static char *copier;
 static char *editor;
+static char *enveditor;
 static char *pager;
 static char *shell;
 static char *home;
@@ -1025,7 +1028,7 @@ static bool editselection(void)
        seltofile(fd, NULL);
        close(fd);
 
-       spawn(editor, g_tmpfpath, NULL, NULL, F_CLI);
+       spawn((cfg.waitedit ? enveditor : editor), g_tmpfpath, NULL, NULL, F_CLI);
 
        fd = open(g_tmpfpath, O_RDONLY);
        if (fd == -1) {
@@ -1405,7 +1408,7 @@ static bool cpmv_rename(int choice, const char *path)
        snprintf(buf, sizeof(buf), cpmvformatcmd, g_tmpfpath);
        spawn(utils[UTIL_SH_EXEC], buf, NULL, path, F_CLI);
 
-       spawn(editor, g_tmpfpath, NULL, path, F_CLI);
+       spawn((cfg.waitedit ? enveditor : editor), g_tmpfpath, NULL, path, F_CLI);
 
        fd = open(g_tmpfpath, O_RDONLY);
        if (fd == -1)
@@ -1523,7 +1526,7 @@ static bool batch_rename(const char *path)
        if (dir) /* Don't retain dir entries in selection */
                selbufpos = 0;
 
-       spawn(editor, g_tmpfpath, NULL, path, F_CLI);
+       spawn((cfg.waitedit ? enveditor : editor), g_tmpfpath, NULL, path, F_CLI);
 
        /* Reopen file descriptor to get updated contents */
        fd2 = open(g_tmpfpath, O_RDONLY);
@@ -5308,6 +5311,7 @@ static void usage(void)
                " -c      cli-only opener\n"
                " -d      detail mode\n"
                " -e name load session by name\n"
+               " -E      EDITOR for undetached edits\n"
                " -f      run filter as cmd on prompt key\n"
                " -H      show hidden files\n"
                " -i      nav-as-you-type mode\n"
@@ -5462,7 +5466,7 @@ int main(int argc, char *argv[])
        bool progress = FALSE;
 #endif
 
-       while ((opt = getopt(argc, argv, "HSKiab:cde:fnop:rstvh")) != -1) {
+       while ((opt = getopt(argc, argv, "HSKiab:cde:Efnop:rstvh")) != -1) {
                switch (opt) {
                case 'S':
                        cfg.blkorder = 1;
@@ -5487,6 +5491,9 @@ int main(int argc, char *argv[])
                case 'e':
                        session = optarg;
                        break;
+               case 'E':
+                       cfg.waitedit = 1;
+                       break;
                case 'f':
                        cfg.filtercmd = 1;
                        break;
@@ -5645,7 +5652,8 @@ int main(int argc, char *argv[])
                cfg.useeditor = 1;
 
        /* Get VISUAL/EDITOR */
-       editor = xgetenv(envs[ENV_VISUAL], xgetenv(envs[ENV_EDITOR], "vi"));
+       enveditor = xgetenv(envs[ENV_EDITOR], "vi");
+       editor = xgetenv(envs[ENV_VISUAL], enveditor);
        DPRINTF_S(getenv(envs[ENV_VISUAL]));
        DPRINTF_S(getenv(envs[ENV_EDITOR]));
        DPRINTF_S(editor);