aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-01-17 19:06:42 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-01-17 19:37:57 +0530
commit64667b377d132cd915d128d91c2ab7b38c1ba683 (patch)
tree97a51406471052e9d91969fc9dfcfce6533b3283
parent94a233b808e039d1a17aab4e12f1b1fb13302d54 (diff)
downloadnnn-64667b377d132cd915d128d91c2ab7b38c1ba683.tar.gz
Options -e and -t
Replaces the following environment variables: - NNN_USE_EDITOR - NNN_IDLE_TIMEOUT
-rw-r--r--README.md4
-rw-r--r--misc/auto-completion/bash/nnn-completion.bash4
-rw-r--r--misc/auto-completion/fish/nnn.fish2
-rw-r--r--misc/auto-completion/zsh/_nnn2
-rw-r--r--nnn.124
-rwxr-xr-xplugins/nuke2
-rw-r--r--src/nnn.c35
7 files changed, 39 insertions, 34 deletions
diff --git a/README.md b/README.md
index 23609de..d0442d6 100644
--- 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.
diff --git a/misc/auto-completion/bash/nnn-completion.bash b/misc/auto-completion/bash/nnn-completion.bash
index 74349e6..b6e370d 100644
--- a/misc/auto-completion/bash/nnn-completion.bash
+++ b/misc/auto-completion/bash/nnn-completion.bash
@@ -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
diff --git a/misc/auto-completion/fish/nnn.fish b/misc/auto-completion/fish/nnn.fish
index 9358882..99c857a 100644
--- a/misc/auto-completion/fish/nnn.fish
+++ b/misc/auto-completion/fish/nnn.fish
@@ -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'
diff --git a/misc/auto-completion/zsh/_nnn b/misc/auto-completion/zsh/_nnn
index d36d6ee..bd6e926 100644
--- a/misc/auto-completion/zsh/_nnn
+++ b/misc/auto-completion/zsh/_nnn
@@ -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 7d8e9de..b171561 100644
--- 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
diff --git a/plugins/nuke b/plugins/nuke
index 5fbf509..d0223c3 100755
--- a/plugins/nuke
+++ b/plugins/nuke
@@ -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:
diff --git a/src/nnn.c b/src/nnn.c
index 0cd723b..6bf40b8 100644
--- 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;