mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +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)
|
||||
- [use cd .....](#use-cd-)
|
||||
- [cd on quit](#cd-on-quit)
|
||||
- [customize nlay](#customize-nlay)
|
||||
- [copy file path to clipboard](#copy-file-path-to-clipboard)
|
||||
- [file copy, move, delete](#file-copy-move-delete)
|
||||
- [boost chdir prompt](#boost-chdir-prompt)
|
||||
- [change text file association](#change-text-file-association)
|
||||
- [set idle timeout](#set-idle-timeout)
|
||||
- [Why fork?](#why-fork)
|
||||
- [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` 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...
|
||||
|
||||
|
@ -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
|
||||
- Mimes
|
||||
- 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
|
||||
- Basic and detail view
|
||||
- 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).
|
||||
|
||||
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.
|
||||
|
||||
|
@ -215,13 +214,10 @@ The following abbreviations are used in the detail view:
|
|||
|
||||
#### 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
|
||||
- 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
|
||||
export NNN_USE_EDITOR=1
|
||||
- To enable the desktop file manager key, set `NNN_DE_FILE_MANAGER`. E.g.:
|
||||
|
||||
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:
|
||||
|
||||
alias n='nnn -d'
|
||||
2. Set desktop opener as default:
|
||||
|
||||
export NNN_OPENER=1
|
||||
3. Set a desktop file manager to open directories with (if you need one). E.g.:
|
||||
2. Set a desktop file manager to open directories with (if you need one). E.g.:
|
||||
|
||||
export NNN_DE_FILE_MANAGER=thunar
|
||||
4. Start `nnn`.
|
||||
3. Start `nnn`.
|
||||
|
||||
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.
|
||||
|
||||
#### 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
|
||||
|
||||
`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).
|
||||
|
||||
#### 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
|
||||
|
||||
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.,
|
||||
# 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
|
||||
# my ongoing activity in nnn by blocking navigation.
|
||||
# background.
|
||||
#
|
||||
# Check (and TOGGLE as you wish) the default bg settings.
|
||||
#
|
||||
|
@ -53,7 +52,7 @@ ext="${ext,,}"
|
|||
ENABLE_FILE_TYPE_HANDLING
|
||||
|
||||
|
||||
#---------------- PLAINTEXT -----------------
|
||||
#------------ PLAINTEXT (UNUSED) ------------
|
||||
if [ "$2" == "text" ]; then
|
||||
app=("vim")
|
||||
|
||||
|
|
24
nnn.1
24
nnn.1
|
@ -15,7 +15,7 @@
|
|||
.Op Ar PATH
|
||||
.Sh DESCRIPTION
|
||||
.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
|
||||
.Nm
|
||||
defaults to the current directory if
|
||||
|
@ -119,12 +119,9 @@ supports the following options:
|
|||
.Sh CONFIGURATION
|
||||
.Nm
|
||||
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,
|
||||
.Nm
|
||||
invokes
|
||||
opener. It invokes
|
||||
.Pa nlay
|
||||
to view text files (recognized by extension) or run actions. It is a highly
|
||||
customizable bash shell script. Read more on
|
||||
to run desktop search utility or screensaver. Read more on
|
||||
.Pa nlay
|
||||
at:
|
||||
.br
|
||||
|
@ -161,13 +158,16 @@ allowing continuous navigation. Works best with the \fBarrow keys\fR.
|
|||
The SHELL, EDITOR and PAGER environment variables take precedence
|
||||
when dealing with the !, e and p commands respectively.
|
||||
.Pp
|
||||
\fBNNN_DE_FILE_MANAGER:\fR set to a desktop file manager to open the current
|
||||
directory with.
|
||||
.Pp
|
||||
\fBNNN_OPENER:\fR set \fIxdg-open\fR (on Linux) or \fIopen(1)\fR desktop opener
|
||||
to handle all file types.
|
||||
\fBNNN_USE_EDITOR:\fR use EDITOR (preferably CLI, fallback vi) to handle text
|
||||
files.
|
||||
.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
|
||||
.Pp
|
||||
\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 int ndents, cur, total_dents;
|
||||
static int idle;
|
||||
static int opener;
|
||||
static char *player;
|
||||
static char *copier;
|
||||
static char *editor;
|
||||
static char *desktop_manager;
|
||||
static off_t blk_size;
|
||||
static size_t fs_free;
|
||||
|
@ -1664,32 +1664,27 @@ nochange:
|
|||
goto begin;
|
||||
case S_IFREG:
|
||||
{
|
||||
/* If NNN_OPENER is set, use it */
|
||||
if (opener) {
|
||||
spawn(utils[0], newpath, NULL, NULL, 4);
|
||||
continue;
|
||||
}
|
||||
/* If NNN_USE_EDITOR is set, open text in EDITOR */
|
||||
if (editor) {
|
||||
mime = getmime(dents[cur].name);
|
||||
if (mime) {
|
||||
exitcurses();
|
||||
spawn(editor, newpath, NULL, NULL, 0);
|
||||
initcurses();
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Play text-based files with nlay */
|
||||
mime = getmime(dents[cur].name);
|
||||
if (mime) {
|
||||
exitcurses();
|
||||
spawn(player, newpath, mime, NULL, 0);
|
||||
initcurses();
|
||||
continue;
|
||||
}
|
||||
/* Recognize and open plain text files with vi */
|
||||
if (get_output(g_buf, MAX_CMD_LEN, "file", "-bi",
|
||||
newpath, 0) == NULL)
|
||||
continue;
|
||||
|
||||
/* Recognize and open plain text files with vi */
|
||||
if (get_output(g_buf, MAX_CMD_LEN, "file", "-bi",
|
||||
newpath, 0) == NULL)
|
||||
continue;
|
||||
|
||||
if (strstr(g_buf, "text/") == g_buf) {
|
||||
exitcurses();
|
||||
run = xgetenv("EDITOR", "vi");
|
||||
spawn(run, newpath, NULL, NULL, 0);
|
||||
initcurses();
|
||||
continue;
|
||||
if (strstr(g_buf, "text/") == g_buf) {
|
||||
exitcurses();
|
||||
spawn(editor, newpath, NULL, NULL, 0);
|
||||
initcurses();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* Invoke desktop opener as last resort */
|
||||
|
@ -2169,9 +2164,9 @@ main(int argc, char *argv[])
|
|||
showhidden = 1;
|
||||
initfilter(showhidden, &ifilter);
|
||||
|
||||
/* Always use desktop opener, if opted */
|
||||
if (getenv("NNN_OPENER"))
|
||||
opener = 1;
|
||||
/* Edit text in EDITOR, if opted */
|
||||
if (getenv("NNN_USE_EDITOR"))
|
||||
editor = xgetenv("EDITOR", "vi");
|
||||
|
||||
/* Set player if not set already */
|
||||
if (!player)
|
||||
|
|
Loading…
Reference in a new issue