]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix #334: Detect session type
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 2 Oct 2019 21:08:06 +0000 (02:38 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 2 Oct 2019 21:08:26 +0000 (02:38 +0530)
README.md
nnn.1
src/nnn.c

index ae6dfbc020d40773aa728c1369bd3926c82fcf04..f5e5d3dbb6f27e5410fce791a53b72bfa95a1662 100644 (file)
--- a/README.md
+++ b/README.md
@@ -168,7 +168,6 @@ positional args:
 optional args:
  -a      use access time
  -b key  open bookmark key
- -c      cli-only opener
  -d      detail mode
  -f      run filter as cmd on prompt key
  -H      show hidden files
diff --git a/nnn.1 b/nnn.1
index 577243ff93dd3075ec83077f5d2c18c4c306862b..3ff179556a9522e2465972dd3268eb7334df85ea 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -44,9 +44,6 @@ supports the following options:
 .Fl "b key"
         specify bookmark key to open
 .Pp
-.Fl c
-        opener opens files in cli utilities only
-.Pp
 .Fl d
         detail mode
 .Pp
index 85004e121ad7328453af76e0dafe3ae76763c56b..ab536bd08f53219b0dea6099b65ca33f06ce7d44 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -212,7 +212,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   : 6;
        /* The following settings are global */
        uint curctx     : 2;  /* Current context number */
        uint dircolor   : 1;  /* Current status of dir color */
@@ -228,7 +228,6 @@ typedef struct {
        uint filtercmd  : 1;  /* Run filter as command on no match */
        uint trash      : 1;  /* Move removed files to trash */
        uint mtime      : 1;  /* Use modification time (else access time) */
-       uint cliopener  : 1;  /* All-CLI app opener */
 } settings;
 
 /* Contexts or workspaces */
@@ -270,7 +269,6 @@ static settings cfg = {
        0, /* filtercmd */
        0, /* trash */
        1, /* mtime */
-       0, /* cliopener */
 };
 
 static context g_ctx[CTX_MAX] __attribute__ ((aligned));
@@ -3358,17 +3356,20 @@ static void browse(char *ipath)
        char mark[PATH_MAX] __attribute__ ((aligned));
        char rundir[PATH_MAX] __attribute__ ((aligned));
        char runfile[NAME_MAX + 1] __attribute__ ((aligned));
-       uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
+       uchar opener_flags = F_NOTRACE | F_NOWAIT;
        int r = -1, fd, presel, selstartid = 0, selendid = 0, onscreen;
        ino_t inode = 0;
        enum action sel;
        bool dir_changed = FALSE, rangesel = FALSE;
        struct stat sb;
-       char *path, *lastdir, *lastname, *dir, *tmp;
+       char *path, *lastdir, *lastname, *dir, *tmp = getenv("XDG_SESSION_TYPE");
        MEVENT event;
 
        atexit(dentfree);
 
+       if (tmp && !xstrcmp(tmp, "tty"))
+               opener_flags = F_CLI;
+
        /* setup first context */
        xstrlcpy(g_ctx[0].c_path, ipath, PATH_MAX); /* current directory */
        path = g_ctx[0].c_path;
@@ -4566,7 +4567,6 @@ static void usage(void)
                "optional args:\n"
                " -a      use access time\n"
                " -b key  open bookmark key\n"
-               " -c      cli-only opener\n"
                " -d      detail mode\n"
                " -f      run filter as cmd on prompt key\n"
                " -H      show hidden files\n"
@@ -4713,7 +4713,7 @@ int main(int argc, char *argv[])
        bool progress = FALSE;
 #endif
 
-       while ((opt = getopt(argc, argv, "HSiab:cdfnop:rstvh")) != -1) {
+       while ((opt = getopt(argc, argv, "HSiab:dfnop:rstvh")) != -1) {
                switch (opt) {
                case 'S':
                        cfg.blkorder = 1;
@@ -4732,9 +4732,6 @@ int main(int argc, char *argv[])
                case 'b':
                        arg = optarg;
                        break;
-               case 'c':
-                       cfg.cliopener = 1;
-                       break;
                case 'f':
                        cfg.filtercmd = 1;
                        break;
@@ -4882,8 +4879,8 @@ int main(int argc, char *argv[])
                }
        }
 
-       /* Edit text in EDITOR if opted (and opener is not all-CLI) */
-       if (!cfg.cliopener && xgetenv_set(env_cfg[NNN_USE_EDITOR]))
+       /* Edit text in EDITOR if opted */
+       if (xgetenv_set(env_cfg[NNN_USE_EDITOR]))
                cfg.useeditor = 1;
 
        /* Get VISUAL/EDITOR */