mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Optionally use EDITOR (fallback vi) for text files
This commit is contained in:
parent
fe775ccf1f
commit
da9499b138
37
README.md
37
README.md
|
@ -33,11 +33,9 @@ Noice is Not Noice, a noicer fork...
|
||||||
- [How to](#how-to)
|
- [How to](#how-to)
|
||||||
- [use cd .....](#use-cd-)
|
- [use cd .....](#use-cd-)
|
||||||
- [cd on quit](#cd-on-quit)
|
- [cd on quit](#cd-on-quit)
|
||||||
- [customize nlay](#customize-nlay)
|
|
||||||
- [copy file path to clipboard](#copy-file-path-to-clipboard)
|
- [copy file path to clipboard](#copy-file-path-to-clipboard)
|
||||||
- [file copy, move, delete](#file-copy-move-delete)
|
- [file copy, move, delete](#file-copy-move-delete)
|
||||||
- [boost chdir prompt](#boost-chdir-prompt)
|
- [boost chdir prompt](#boost-chdir-prompt)
|
||||||
- [change text file association](#change-text-file-association)
|
|
||||||
- [set idle timeout](#set-idle-timeout)
|
- [set idle timeout](#set-idle-timeout)
|
||||||
- [Why fork?](#why-fork)
|
- [Why fork?](#why-fork)
|
||||||
- [Mentions](#mentions)
|
- [Mentions](#mentions)
|
||||||
|
@ -47,7 +45,7 @@ Noice is Not Noice, a noicer fork...
|
||||||
|
|
||||||
`nnn` is a fork of [noice](http://git.2f30.org/noice/), a blazing-fast lightweight terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed considering terminal based systems. There is no config file and mime associations are hard-coded. However, the incredible user-friendliness and speed make it a perfect utility on modern distros.
|
`nnn` is a fork of [noice](http://git.2f30.org/noice/), a blazing-fast lightweight terminal file browser with easy keyboard shortcuts for navigation, opening files and running tasks. noice is developed considering terminal based systems. There is no config file and mime associations are hard-coded. However, the incredible user-friendliness and speed make it a perfect utility on modern distros.
|
||||||
|
|
||||||
`nnn` can use the desktop opener at runtime and handle text files or actions with [nlay](https://github.com/jarun/nnn/wiki/all-about-nlay), a customizable bash script. `nnn` adds new navigation options, [navigate-as-you-type](#navigate-as-you-type-mode) mode, enhanced DE integration, a disk usage analyzer mode, comprehensive file details and much more. Add to that a huge [performance](#performance) boost. For a detailed comparison, visit [nnn vs. noice](https://github.com/jarun/nnn/wiki/nnn-vs.-noice).
|
`nnn` invokes the desktop opener at runtime, adds new navigation options, [navigate-as-you-type](#navigate-as-you-type-mode) mode, enhanced DE integration, a disk usage analyzer mode, comprehensive file details and much more. Add to that a huge [performance](#performance) boost. For a detailed comparison, visit [nnn vs. noice](https://github.com/jarun/nnn/wiki/nnn-vs.-noice).
|
||||||
|
|
||||||
If you want to edit a file in vim with some soothing music in the background while referring to a spec in your GUI PDF viewer, `nnn` got it! All from the same terminal session. Follow the instructions in the [quickstart](#quickstart) section and see how `nnn` simplifies those long desktop sessions...
|
If you want to edit a file in vim with some soothing music in the background while referring to a spec in your GUI PDF viewer, `nnn` got it! All from the same terminal session. Follow the instructions in the [quickstart](#quickstart) section and see how `nnn` simplifies those long desktop sessions...
|
||||||
|
|
||||||
|
@ -72,7 +70,8 @@ Have fun with it! PRs are welcome. Check out [#1](https://github.com/jarun/nnn/i
|
||||||
- Desktop search (default gnome-search-tool, customizable) integration
|
- Desktop search (default gnome-search-tool, customizable) integration
|
||||||
- Mimes
|
- Mimes
|
||||||
- Desktop opener integration
|
- Desktop opener integration
|
||||||
- Customizable bash script [nlay](https://github.com/jarun/nnn/wiki/all-about-nlay) to handle text files or actions
|
- Optionally open text files in EDITOR (fallback vi)
|
||||||
|
- Customizable bash script [nlay](https://github.com/jarun/nnn/wiki/all-about-nlay) to handle actions
|
||||||
- Information
|
- Information
|
||||||
- Basic and detail view
|
- Basic and detail view
|
||||||
- Detailed file information
|
- Detailed file information
|
||||||
|
@ -191,7 +190,7 @@ Filters support regexes to display only the matched entries in the current direc
|
||||||
|
|
||||||
Filters do not stack on top of each other. They are applied anew every time. There are 4 ways to reset a filter: <kbd>^L</kbd>, an empty filter expression, a search with no results or an extra backspace at the filter prompt (like vi).
|
Filters do not stack on top of each other. They are applied anew every time. There are 4 ways to reset a filter: <kbd>^L</kbd>, an empty filter expression, a search with no results or an extra backspace at the filter prompt (like vi).
|
||||||
|
|
||||||
If you want to list all matches starting with the filter expression (a common use case), start the expression with a `^` (caret) symbol.
|
Examples: If you want to list all matches starting with the filter expression (a common use case), start the expression with a `^` (caret) symbol. To list all MKV files type `\.mkv`.
|
||||||
|
|
||||||
If `nnn` is invoked as root the default filter will also match hidden files.
|
If `nnn` is invoked as root the default filter will also match hidden files.
|
||||||
|
|
||||||
|
@ -215,13 +214,10 @@ The following abbreviations are used in the detail view:
|
||||||
|
|
||||||
#### File handling
|
#### File handling
|
||||||
|
|
||||||
- `nnn` uses `xdg-open` on Linux and `open(1)` on OS X as the desktop opener. To let the desktop opener handle everything:
|
- `nnn` uses `xdg-open` on Linux and `open(1)` on OS X as the desktop opener.
|
||||||
|
- To edit all text files in EDITOR (preferably CLI, fallback vi):
|
||||||
|
|
||||||
export NNN_OPENER=1
|
export NNN_USE_EDITOR=1
|
||||||
- If `NNN_OPENER` is not set:
|
|
||||||
- If `nnn` recognizes a text file by extension, it invokes nlay, which in turn opens the file in vim.
|
|
||||||
- If a file without any extension is a plain text file, it is opened in EDITOR (fallback vi)
|
|
||||||
- All other files are handled by desktop opener
|
|
||||||
- To enable the desktop file manager key, set `NNN_DE_FILE_MANAGER`. E.g.:
|
- To enable the desktop file manager key, set `NNN_DE_FILE_MANAGER`. E.g.:
|
||||||
|
|
||||||
export NNN_DE_FILE_MANAGER=thunar
|
export NNN_DE_FILE_MANAGER=thunar
|
||||||
|
@ -240,13 +236,10 @@ Add the following to your shell's rc file for the best experience:
|
||||||
1. Always open `nnn` in detail mode:
|
1. Always open `nnn` in detail mode:
|
||||||
|
|
||||||
alias n='nnn -d'
|
alias n='nnn -d'
|
||||||
2. Set desktop opener as default:
|
2. Set a desktop file manager to open directories with (if you need one). E.g.:
|
||||||
|
|
||||||
export NNN_OPENER=1
|
|
||||||
3. Set a desktop file manager to open directories with (if you need one). E.g.:
|
|
||||||
|
|
||||||
export NNN_DE_FILE_MANAGER=thunar
|
export NNN_DE_FILE_MANAGER=thunar
|
||||||
4. Start `nnn`.
|
3. Start `nnn`.
|
||||||
|
|
||||||
n
|
n
|
||||||
|
|
||||||
|
@ -262,10 +255,6 @@ Pick the appropriate file for your shell from [misc/quitcd](https://github.com/j
|
||||||
|
|
||||||
As you might notice, `nnn` uses the environment variable `NNN_TMPFILE` to write the last visited directory path. You can change it.
|
As you might notice, `nnn` uses the environment variable `NNN_TMPFILE` to write the last visited directory path. You can change it.
|
||||||
|
|
||||||
#### customize nlay
|
|
||||||
|
|
||||||
nlay is a tiny standalone text file and action handler. To know how to customize or extend its functionality, please visit [nlay on wiki](https://github.com/jarun/nnn/wiki/all-about-nlay).
|
|
||||||
|
|
||||||
#### copy file path to clipboard
|
#### copy file path to clipboard
|
||||||
|
|
||||||
`nnn` can pipe the absolute path of the current file to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X.
|
`nnn` can pipe the absolute path of the current file to a copier script. For example, you can use `xsel` on Linux or `pbcopy` on OS X.
|
||||||
|
@ -294,14 +283,6 @@ Start `nnn` and use <kbd>^K</kbd> to copy the absolute path (from `/`) of the fi
|
||||||
|
|
||||||
`nnn` uses libreadline for the chdir prompt input. So all the fantastic features of readline (e.g. case insensitive tab completion, history, reverse-i-search) is available to you based on your readline [configuration](https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC9).
|
`nnn` uses libreadline for the chdir prompt input. So all the fantastic features of readline (e.g. case insensitive tab completion, history, reverse-i-search) is available to you based on your readline [configuration](https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC9).
|
||||||
|
|
||||||
#### change text file association
|
|
||||||
|
|
||||||
If `NNN_OPENER` is not set, `nnn` tries to recognize text files by extension and invokes nlay. To add a new extension mainline, please raise a bug. Without it `nnn` will not invoke nlay.
|
|
||||||
|
|
||||||
Text files are opened in vim by default. You can easily change it in nlay.
|
|
||||||
|
|
||||||
nlay has provisions (disabled by default) to handle a specific file extension too. However, the extension should be recognized by `nnn` first.
|
|
||||||
|
|
||||||
#### set idle timeout
|
#### set idle timeout
|
||||||
|
|
||||||
The terminal screensaver is disabled by default. To set the wait time in seconds, use environment variable `NNN_IDLE_TIMEOUT`.
|
The terminal screensaver is disabled by default. To set the wait time in seconds, use environment variable `NNN_IDLE_TIMEOUT`.
|
||||||
|
|
5
nlay
5
nlay
|
@ -14,8 +14,7 @@
|
||||||
#
|
#
|
||||||
# The bg setting depends on personal preference and type of app, e.g.,
|
# The bg setting depends on personal preference and type of app, e.g.,
|
||||||
# I would start vim (CLI) in the foreground but Sublime Text (GUI) in the
|
# I would start vim (CLI) in the foreground but Sublime Text (GUI) in the
|
||||||
# background. I also prefer mpv running in the background without disturbing
|
# background.
|
||||||
# my ongoing activity in nnn by blocking navigation.
|
|
||||||
#
|
#
|
||||||
# Check (and TOGGLE as you wish) the default bg settings.
|
# Check (and TOGGLE as you wish) the default bg settings.
|
||||||
#
|
#
|
||||||
|
@ -53,7 +52,7 @@ ext="${ext,,}"
|
||||||
ENABLE_FILE_TYPE_HANDLING
|
ENABLE_FILE_TYPE_HANDLING
|
||||||
|
|
||||||
|
|
||||||
#---------------- PLAINTEXT -----------------
|
#------------ PLAINTEXT (UNUSED) ------------
|
||||||
if [ "$2" == "text" ]; then
|
if [ "$2" == "text" ]; then
|
||||||
app=("vim")
|
app=("vim")
|
||||||
|
|
||||||
|
|
24
nnn.1
24
nnn.1
|
@ -15,7 +15,7 @@
|
||||||
.Op Ar PATH
|
.Op Ar PATH
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
(Noice is Not Noice) is a performance-optimized fork of the noice terminal file browser with extensive desktop integration, customizable text file or action handler, simplified navigation, navigate-as-you-type mode, disk usage analyzer mode, comprehensive file details and much more. It remains a simple and efficient file browser that stays out of your way.
|
(Noice is Not Noice) is a performance-optimized fork of the noice terminal file browser with extensive desktop integration, simplified navigation, \fInavigate-as-you-type\fR mode, disk usage analyzer mode, comprehensive file details and much more. It remains a simple and efficient file browser that stays out of your way.
|
||||||
.Pp
|
.Pp
|
||||||
.Nm
|
.Nm
|
||||||
defaults to the current directory if
|
defaults to the current directory if
|
||||||
|
@ -119,12 +119,9 @@ supports the following options:
|
||||||
.Sh CONFIGURATION
|
.Sh CONFIGURATION
|
||||||
.Nm
|
.Nm
|
||||||
uses \fIxdg-open\fR (on Linux) and \fIopen(1)\fR (on OS X) as the desktop
|
uses \fIxdg-open\fR (on Linux) and \fIopen(1)\fR (on OS X) as the desktop
|
||||||
opener. If \fBNNN_OPENER\fR (see ENVIRONMENT section below) is not set,
|
opener. It invokes
|
||||||
.Nm
|
|
||||||
invokes
|
|
||||||
.Pa nlay
|
.Pa nlay
|
||||||
to view text files (recognized by extension) or run actions. It is a highly
|
to run desktop search utility or screensaver. Read more on
|
||||||
customizable bash shell script. Read more on
|
|
||||||
.Pa nlay
|
.Pa nlay
|
||||||
at:
|
at:
|
||||||
.br
|
.br
|
||||||
|
@ -161,13 +158,16 @@ allowing continuous navigation. Works best with the \fBarrow keys\fR.
|
||||||
The SHELL, EDITOR and PAGER environment variables take precedence
|
The SHELL, EDITOR and PAGER environment variables take precedence
|
||||||
when dealing with the !, e and p commands respectively.
|
when dealing with the !, e and p commands respectively.
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_DE_FILE_MANAGER:\fR set to a desktop file manager to open the current
|
\fBNNN_USE_EDITOR:\fR use EDITOR (preferably CLI, fallback vi) to handle text
|
||||||
directory with.
|
files.
|
||||||
.Pp
|
|
||||||
\fBNNN_OPENER:\fR set \fIxdg-open\fR (on Linux) or \fIopen(1)\fR desktop opener
|
|
||||||
to handle all file types.
|
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
export NNN_OPENER=1
|
export NNN_USE_EDITOR=1
|
||||||
|
.Ed
|
||||||
|
.Pp
|
||||||
|
\fBNNN_DE_FILE_MANAGER:\fR set to a desktop file manager to open the current
|
||||||
|
directory with. E.g.:
|
||||||
|
.Bd -literal
|
||||||
|
export NNN_DE_FILE_MANAGER=thunar
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal
|
\fBNNN_IDLE_TIMEOUT:\fR set idle timeout (in seconds) to invoke terminal
|
||||||
|
|
51
nnn.c
51
nnn.c
|
@ -151,9 +151,9 @@ extern int wget_wch(WINDOW *, wint_t *);
|
||||||
static struct entry *dents;
|
static struct entry *dents;
|
||||||
static int ndents, cur, total_dents;
|
static int ndents, cur, total_dents;
|
||||||
static int idle;
|
static int idle;
|
||||||
static int opener;
|
|
||||||
static char *player;
|
static char *player;
|
||||||
static char *copier;
|
static char *copier;
|
||||||
|
static char *editor;
|
||||||
static char *desktop_manager;
|
static char *desktop_manager;
|
||||||
static off_t blk_size;
|
static off_t blk_size;
|
||||||
static size_t fs_free;
|
static size_t fs_free;
|
||||||
|
@ -1664,32 +1664,27 @@ nochange:
|
||||||
goto begin;
|
goto begin;
|
||||||
case S_IFREG:
|
case S_IFREG:
|
||||||
{
|
{
|
||||||
/* If NNN_OPENER is set, use it */
|
/* If NNN_USE_EDITOR is set, open text in EDITOR */
|
||||||
if (opener) {
|
if (editor) {
|
||||||
spawn(utils[0], newpath, NULL, NULL, 4);
|
mime = getmime(dents[cur].name);
|
||||||
continue;
|
if (mime) {
|
||||||
}
|
exitcurses();
|
||||||
|
spawn(editor, newpath, NULL, NULL, 0);
|
||||||
|
initcurses();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* Play text-based files with nlay */
|
/* Recognize and open plain text files with vi */
|
||||||
mime = getmime(dents[cur].name);
|
if (get_output(g_buf, MAX_CMD_LEN, "file", "-bi",
|
||||||
if (mime) {
|
newpath, 0) == NULL)
|
||||||
exitcurses();
|
continue;
|
||||||
spawn(player, newpath, mime, NULL, 0);
|
|
||||||
initcurses();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Recognize and open plain text files with vi */
|
if (strstr(g_buf, "text/") == g_buf) {
|
||||||
if (get_output(g_buf, MAX_CMD_LEN, "file", "-bi",
|
exitcurses();
|
||||||
newpath, 0) == NULL)
|
spawn(editor, newpath, NULL, NULL, 0);
|
||||||
continue;
|
initcurses();
|
||||||
|
continue;
|
||||||
if (strstr(g_buf, "text/") == g_buf) {
|
}
|
||||||
exitcurses();
|
|
||||||
run = xgetenv("EDITOR", "vi");
|
|
||||||
spawn(run, newpath, NULL, NULL, 0);
|
|
||||||
initcurses();
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Invoke desktop opener as last resort */
|
/* Invoke desktop opener as last resort */
|
||||||
|
@ -2169,9 +2164,9 @@ main(int argc, char *argv[])
|
||||||
showhidden = 1;
|
showhidden = 1;
|
||||||
initfilter(showhidden, &ifilter);
|
initfilter(showhidden, &ifilter);
|
||||||
|
|
||||||
/* Always use desktop opener, if opted */
|
/* Edit text in EDITOR, if opted */
|
||||||
if (getenv("NNN_OPENER"))
|
if (getenv("NNN_USE_EDITOR"))
|
||||||
opener = 1;
|
editor = xgetenv("EDITOR", "vi");
|
||||||
|
|
||||||
/* Set player if not set already */
|
/* Set player if not set already */
|
||||||
if (!player)
|
if (!player)
|
||||||
|
|
Loading…
Reference in a new issue