From 9702abdd81774854540368600ea324af4829941d Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Wed, 12 Apr 2017 22:18:03 +0530 Subject: [PATCH] Support open current dir in desktop file manager --- README.md | 8 ++++++-- config.def.h | 2 ++ nnn.1 | 17 ++++++----------- nnn.c | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 4494281c..199be91b 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,10 @@ I chose to fork because: - Sort entries by file size (largest to smallest) - Shortcut to invoke file name copier (set using environment variable `NNN_COPIER`) #### File associations - - Environment variable `NNN_OPENER` to let desktop opener handle it all. E.g.: + - To open the current directory in a desktop file manager, set `NNN_DE_FILE_MANAGER`. E.g.: + + export NNN_DE_FILE_MANAGER=thunar + - Set `NNN_OPENER` to let a desktop opener handle it all. E.g.: export NNN_OPENER=xdg-open export NNN_OPENER=gnome-open @@ -90,7 +93,7 @@ I chose to fork because: - Associate PDF files with [zathura](https://pwmt.org/projects/zathura/) - Removed `less` as default file opener (there is no universal standalone opener utility) - You can customize further (see [how to change file associations](#change-file-associations)) - - Environment variable `NNN_FALLBACK_OPENER` is the last line of defense: + - `NNN_FALLBACK_OPENER` is the last line of defense: - If the executable in static file association is missing - If a file type was not handled in static file association - This may be the best option to set your desktop opener to @@ -145,6 +148,7 @@ Start nnn (default: current directory): | `Left`, `Backspace`, `h`, `^H` | Go to parent dir | | `~` | Jump to HOME dir | | `-` | Jump to last visited dir | +| `o` | Open dir in desktop file manager | | `/`, `&` | Filter dir contents | | `c` | Show change dir prompt | | `d` | Toggle detail view | diff --git a/config.def.h b/config.def.h index 2e516758..2acdae90 100644 --- a/config.def.h +++ b/config.def.h @@ -74,6 +74,8 @@ struct key bindings[] = { { 'd', SEL_DETAIL, "", "" }, /* File details */ { 'D', SEL_STATS, "", "" }, + /* Open dir in desktop file manager */ + { 'o', SEL_DFB, "", "" }, /* Toggle sort by size */ { 's', SEL_FSIZE, "", "" }, /* Sort by total block size including dir contents */ diff --git a/nnn.1 b/nnn.1 index 85acf117..bbaaab95 100644 --- a/nnn.1 +++ b/nnn.1 @@ -42,6 +42,8 @@ Back up one directory level Change to the HOME directory .It Ic - Change to the last visited directory +.It Ic o +Open directory in desktop file manager .It Ic /, & Change filter (more information below) .It Ic c @@ -90,17 +92,7 @@ is configured by modifying .Pa config.h and recompiling the code. .Pp -Environment variable -.Ar NNN_OPENER -overrides all hard-coded file associations. -.Pp -Hard-coded associations are specified by regexes matching on the currently selected filename. If a match is found the associated program is executed with the filename passed in as the argument. If no match is found the environment variable -.Ar NNN_FALLBACK_OPENER -is invoked, if set. -.Pp -No particular utility is set as the default opener as no standalone universal opener for all mime types exists. -.Pp -See the examples section below for more information. +See the environment and examples sections below for more options and information. .Sh FILTERS Filters support regexes to display only the matched entries in the current directory view. This effectively allows @@ -119,6 +111,9 @@ files. 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 to your desktop environment's default mime opener to override all custom mime associations. .br diff --git a/nnn.c b/nnn.c index 318fffe7..f676eb31 100644 --- a/nnn.c +++ b/nnn.c @@ -86,6 +86,7 @@ enum action { SEL_TOGGLEDOT, SEL_DETAIL, SEL_STATS, + SEL_DFB, SEL_FSIZE, SEL_BSIZE, SEL_MTIME, @@ -122,6 +123,7 @@ static int idle; static char *opener; static char *fallback_opener; static char *copier; +static char *desktop_manager; static off_t blk_size; static size_t fs_free; static int open_max; @@ -916,6 +918,7 @@ show_help(void) [Left], [Backspace], h, ^H Go to parent dir\n\ ~ Jump to HOME dir\n\ - Jump to last visited dir\n\ + o Open dir in desktop file manager\n\ /, & Filter dir contents\n\ c Show change dir prompt\n\ d Toggle detail view\n\ @@ -1485,6 +1488,14 @@ nochange: goto begin; } + case SEL_DFB: + if (!desktop_manager) + goto nochange; + + exitcurses(); + spawn(desktop_manager, path, path, 0); + initcurses(); + goto nochange; case SEL_FSIZE: sizeorder = !sizeorder; mtimeorder = 0; @@ -1623,6 +1634,9 @@ main(int argc, char *argv[]) /* Get the fallback desktop mime opener, if set */ fallback_opener = getenv("NNN_FALLBACK_OPENER"); + /* Get the desktop file browser, if set */ + desktop_manager = getenv("NNN_DE_FILE_MANAGER"); + /* Get the default copier, if set */ copier = getenv("NNN_COPIER");