]> Sergey Matveev's repositories - nnn.git/commitdiff
Options -e and -t
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 17 Jan 2020 13:36:42 +0000 (19:06 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 17 Jan 2020 14:07:57 +0000 (19:37 +0530)
Replaces the following environment variables:
- NNN_USE_EDITOR
- NNN_IDLE_TIMEOUT

README.md
misc/auto-completion/bash/nnn-completion.bash
misc/auto-completion/fish/nnn.fish
misc/auto-completion/zsh/_nnn
nnn.1
plugins/nuke
src/nnn.c

index 23609debb97a446643dda91f4438d673880a1d7a..d0442d69394fc5925ce5d8844d33a3537efd5ee7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -86,10 +86,10 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/watch?v=AbaauM7gUJw
 
 1. Install the [utilities you may need](https://github.com/jarun/nnn#utility-dependencies) based on your regular workflows.
 2. Configure [cd on quit](https://github.com/jarun/nnn/wiki/Basic-use-cases#configure-cd-on-quit).
-3. Optionally open all text files in `$VISUAL` (else `$EDITOR`, fallback vi): `export NNN_USE_EDITOR=1`.
+3. To open text files in `$VISUAL` (else `$EDITOR`, fallback vi) add program option `-e` in your alias.
 4. For additional functionality [install plugins](https://github.com/jarun/nnn/tree/master/plugins#installing-plugins).
 5. To copy selected file paths to system clipboard and show notis on cp, mv, rm completion use option `-x`.
-6. For a strictly CLI environment, see plugin `nuke`. It's a sample opener you can customize.
+6. For a strictly CLI environment, customize and use plugin [`nuke`](https://github.com/jarun/nnn/blob/master/plugins/nuke).
 
 Don't memorize! Arrows (or <kbd>h</kbd> <kbd>j</kbd> <kbd>k</kbd> <kbd>l</kbd>), <kbd>/</kbd>, <kbd>q</kbd> suffice. <kbd>Tab</kbd> creates, cycles contexts. <kbd>?</kbd> lists shortcuts.
 
index 74349e6a92808baa2e5200cf845983ce69f0e3f1..b6e370da932cb5c23f8a83ffb5c40763a635d3de 100644 (file)
@@ -17,6 +17,7 @@ _nnn ()
         -b
         -c
         -d
+        -e
         -E
         -g
         -H
@@ -29,6 +30,7 @@ _nnn ()
         -R
         -s
         -S
+        -t
         -v
         -V
         -x
@@ -42,6 +44,8 @@ _nnn ()
     elif [[ $prev == -s ]]; then
         local sessions_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions
         COMPREPLY=( $(cd "$sessions_dir" && compgen -f -d -- "$cur") )
+    elif [[ $prev == -t ]]; then
+        return 1
     elif [[ $cur == -* ]]; then
         COMPREPLY=( $(compgen -W "${opts[*]}" -- "$cur") )
     else
index 9358882d7a55d12852ac59d2dd8a15f248b6caaa..99c857aa22a911e7bf56de85b73c12c338ec1dda 100644 (file)
@@ -16,6 +16,7 @@ complete -c nnn -s A    -d 'disable dir auto-select'
 complete -c nnn -s b -r -d 'bookmark key to open' -x -a '(echo $NNN_BMS | awk -F: -v RS=\; \'{print $1"\t"$2}\')'
 complete -c nnn -s c    -d 'cli-only opener'
 complete -c nnn -s d    -d 'start in detail mode'
+complete -c nnn -s e    -d 'open text files in $VISUAL/$EDITOR/vi'
 complete -c nnn -s E    -d 'use EDITOR for undetached edits'
 complete -c nnn -s g    -d 'regex filters'
 complete -c nnn -s H    -d 'show hidden files'
@@ -28,6 +29,7 @@ complete -c nnn -s r    -d 'show cp, mv progress (Linux-only)'
 complete -c nnn -s R    -d 'disable rollover at edges'
 complete -c nnn -s s -r -d 'load session by name' -x -a '@\t"last session" (ls $sessions_dir)'
 complete -c nnn -s S    -d 'start in disk usage analyzer mode'
+complete -c nnn -s t -r -d 'timeout in seconds to lock'
 complete -c nnn -s v    -d 'use version compare to sort files'
 complete -c nnn -s V    -d 'show program version and exit'
 complete -c nnn -s x    -d 'notis, sel to system clipboard'
index d36d6ee374c71db15740ccab54a647c1f8fd7e88..bd6e926ec370db482f085dd5104a6f4728a3cd49 100644 (file)
@@ -14,6 +14,7 @@ args=(
     '(-b)-b[bookmark key to open]:key char'
     '(-c)-c[cli-only opener]'
     '(-d)-d[start in detail mode]'
+    '(-e)-e[open text files in $VISUAL/$EDITOR/vi]'
     '(-E)-E[use EDITOR for undetached edits]'
     '(-g)-g[regex filters]'
     '(-H)-H[show hidden files]'
@@ -26,6 +27,7 @@ args=(
     '(-R)-R[disable rollover at edges]'
     '(-s)-s[load session]:session name'
     '(-S)-S[start in disk usage analyzer mode]'
+    '(-t)-t[timeout to lock]:seconds'
     '(-v)-v[use version compare to sort files]'
     '(-V)-V[show program version and exit]'
     '(-x)-x[notis, sel to system clipboard]'
diff --git a/nnn.1 b/nnn.1
index 7d8e9dea6fa1cbb6ca36475ab0fc123138f690c3..b1715618e00e9c8f97e74bef92649f3744c8febe 100644 (file)
--- a/nnn.1
+++ b/nnn.1
@@ -11,6 +11,7 @@
 .Op Ar -b key
 .Op Ar -c
 .Op Ar -d
+.Op Ar -e
 .Op Ar -E
 .Op Ar -g
 .Op Ar -H
@@ -22,6 +23,7 @@
 .Op Ar -R
 .Op Ar -s name
 .Op Ar -S
+.Op Ar -t secs
 .Op Ar -v
 .Op Ar -V
 .Op Ar -x
@@ -60,11 +62,14 @@ supports the following options:
         specify bookmark key to open
 .Pp
 .Fl c
-        opener opens files in cli utilities only
+        opener opens files in cli utilities only (overrides -e)
 .Pp
 .Fl d
         detail mode
 .Pp
+.Fl e
+        open text files in $VISUAL (else $EDITOR, fallback vi) [preferably CLI]
+.Pp
 .Fl E
         use $EDITOR for internal undetached edits
 .Pp
@@ -102,6 +107,9 @@ supports the following options:
 .Fl S
         start in disk usage analyzer mode
 .Pp
+.Fl "t secs"
+        idle timeout in seconds to lock terminal
+.Pp
 .Fl v
         use case-insensitive version compare to sort files
 .Pp
@@ -229,9 +237,8 @@ to list the selection file.
 The minimum file size unit is byte (B). The rest are K, M, G, T, P, E, Z, Y
 (powers of 1024), same as the default units in \fIls\fR.
 .Sh ENVIRONMENT
-The SHELL, EDITOR (VISUAL, if defined) and PAGER environment variables take
-precedence when dealing with the !, e and p commands respectively. A single
-combination to arguments is supported for SHELL and PAGER.
+The SHELL, EDITOR (VISUAL, if defined) and PAGER environment variables are
+used. A single combination of arguments is supported for SHELL and PAGER.
 .Pp
 \fBNNN_OPENER:\fR specify a custom file opener.
 .Bd -literal
@@ -291,12 +298,6 @@ combination to arguments is supported for SHELL and PAGER.
     ----------------------------------- + -------------------------------------------------
 .Ed
 .Pp
-\fBNNN_USE_EDITOR:\fR use VISUAL (else EDITOR, preferably CLI, fallback vi)
-to handle text files.
-.Bd -literal
-    export NNN_USE_EDITOR=1
-.Ed
-.Pp
 \fBNNN_CONTEXT_COLORS:\fR string of color codes for each context, e.g.:
 .Bd -literal
     export NNN_CONTEXT_COLORS='1234'
@@ -318,9 +319,6 @@ to handle text files.
     NOTE: The options must be preceded by `rclone` and max 5 flags are supported.
 .Ed
 .Pp
-\fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal locker
-(default: disabled).
-.Pp
 \fBNNN_TRASH:\fR trash (instead of \fIdelete\fR) files to desktop Trash.
 .Bd -literal
     export NNN_TRASH=1
index 5fbf509d0e21b92ae825306bbc8dfb08e42035ae..d0223c37995a1e53f6b260f31253dbfdd27f73eb 100755 (executable)
@@ -13,7 +13,7 @@
 #         # export NNN_OPENER=nuke
 #   2. Run nnn with the program option to indicate a CLI opener
 #         nnn -c
-#         # The -c program option overrides config `NNN_USE_EDITOR`
+#         # The -c program option overrides option -e
 #   3. nuke can use nnn plugins (e.g. mocplay is used for audio), $PATH is updated.
 #
 # Details:
index 0cd723be4046f96b24ab2857cef4a7d4024c50ef..6bf40b8d10ae7c25007360bd0c83828ed6215dc7 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -521,22 +521,18 @@ static const char * const messages[] = {
 #define NNN_BMS 0
 #define NNN_OPENER 1
 #define NNN_CONTEXT_COLORS 2
-#define NNN_IDLE_TIMEOUT 3
-#define NNNLVL 4
-#define NNN_PIPE 5
-#define NNN_ARCHIVE 6 /* strings end here */
-#define NNN_USE_EDITOR 7 /* flags begin here */
-#define NNN_TRASH 8
+#define NNNLVL 3
+#define NNN_PIPE 4
+#define NNN_ARCHIVE 5 /* strings end here */
+#define NNN_TRASH 6 /* flags begin here */
 
 static const char * const env_cfg[] = {
        "NNN_BMS",
        "NNN_OPENER",
        "NNN_CONTEXT_COLORS",
-       "NNN_IDLE_TIMEOUT",
        "NNNLVL",
        "NNN_PIPE",
        "NNN_ARCHIVE",
-       "NNN_USE_EDITOR",
        "NNN_TRASH",
 };
 
@@ -4772,7 +4768,6 @@ nochange:
                                        }
                                }
 
-                               /* If NNN_USE_EDITOR is set, open text in EDITOR */
                                if (cfg.useeditor && (!sb.st_size ||
 #ifdef FILE_MIME_OPTS
                                    (get_output(g_buf, CMD_LEN_MAX, "file", FILE_MIME_OPTS, newpath, FALSE)
@@ -5739,8 +5734,9 @@ static void usage(void)
                " -a      use access time\n"
                " -A      no dir auto-select\n"
                " -b key  open bookmark key\n"
-               " -c      cli-only opener\n"
+               " -c      cli-only opener (overrides -e)\n"
                " -d      detail mode\n"
+               " -e      text in $VISUAL ($EDITOR/vi)\n"
                " -E      use EDITOR for undetached edits\n"
                " -g      regex filters [default: string]\n"
                " -H      show hidden files\n"
@@ -5753,6 +5749,7 @@ static void usage(void)
                " -R      no rollover at edges\n"
                " -s name load session by name\n"
                " -S      du mode\n"
+               " -t secs timeout to lock\n"
                " -v      version sort\n"
                " -V      show version\n"
                " -x      notis, sel to system clipboard\n"
@@ -5903,7 +5900,7 @@ int main(int argc, char *argv[])
        bool progress = FALSE;
 #endif
 
-       while ((opt = getopt(argc, argv, "HSKaAb:cdEgnop:QrRs:vVxh")) != -1) {
+       while ((opt = getopt(argc, argv, "HSKaAb:cdeEgnop:QrRs:t:vVxh")) != -1) {
                switch (opt) {
                case 'S':
                        cfg.blkorder = 1;
@@ -5925,6 +5922,9 @@ int main(int argc, char *argv[])
                case 'c':
                        cfg.cliopener = 1;
                        break;
+               case 'e':
+                       cfg.useeditor = 1;
+                       break;
                case 'E':
                        cfg.waitedit = 1;
                        break;
@@ -5972,6 +5972,9 @@ int main(int argc, char *argv[])
                case 's':
                        session = optarg;
                        break;
+               case 't':
+                       idletimeout = xatoi(optarg);
+                       break;
                case 'K':
                        check_key_collision();
                        return _SUCCESS;
@@ -6080,9 +6083,9 @@ int main(int argc, char *argv[])
                return _FAILURE;
        }
 
-       /* Edit text in EDITOR if opted (and opener is not all-CLI) */
-       if (!cfg.cliopener && xgetenv_set(env_cfg[NNN_USE_EDITOR]))
-               cfg.useeditor = 1;
+       /* An all-CLI opener overrides option -e) */
+       if (cfg.cliopener)
+               cfg.useeditor = 0;
 
        /* Get VISUAL/EDITOR */
        enveditor = xgetenv(envs[ENV_EDITOR], utils[UTIL_VI]);
@@ -6125,10 +6128,6 @@ int main(int argc, char *argv[])
        /* Set nnn nesting level */
        setenv(env_cfg[NNNLVL], xitoa(xatoi(getenv(env_cfg[NNNLVL])) + 1), 1);
 
-       /* Get locker wait time, if set */
-       idletimeout = xatoi(getenv(env_cfg[NNN_IDLE_TIMEOUT]));
-       DPRINTF_U(idletimeout);
-
        if (xgetenv_set(env_cfg[NNN_TRASH]))
                cfg.trash = 1;