mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 20:01:27 +00:00
Support file name copier
Add keybind 'Ctrl-k' to copy the absolute path of the file under the cursor if environment variable NOICE_COPIER is set.
This commit is contained in:
parent
6b169bbd86
commit
c42790aa18
21
README.md
21
README.md
|
@ -13,6 +13,7 @@ A fork of the [noice](http://git.2f30.org/noice/) file browser to make it more f
|
||||||
- [Keyboard shortcuts](#keyboard-shortcuts)
|
- [Keyboard shortcuts](#keyboard-shortcuts)
|
||||||
- [File type abbreviations](#file-type-abbreviations)
|
- [File type abbreviations](#file-type-abbreviations)
|
||||||
- [Help](#help)
|
- [Help](#help)
|
||||||
|
- [Copy current file path to clipboard](#copy-current-file-path-to-clipboard)
|
||||||
- [Change file associations](#change-file-associations)
|
- [Change file associations](#change-file-associations)
|
||||||
|
|
||||||
### Introduction
|
### Introduction
|
||||||
|
@ -54,8 +55,9 @@ I chose to fork noice because:
|
||||||
- Case-insensitive alphabetic content listing instead of upper case first
|
- Case-insensitive alphabetic content listing instead of upper case first
|
||||||
- Roll over at the first and last entries of a directory (with Up/Down keys)
|
- Roll over at the first and last entries of a directory (with Up/Down keys)
|
||||||
- Sort entries by file size (largest to smallest)
|
- Sort entries by file size (largest to smallest)
|
||||||
|
- Shortcut to invoke file name copier (set using environment variable `NOICE_COPIER`)
|
||||||
- File associations
|
- File associations
|
||||||
- Environment variable `NOICE_OPENER` to override all associations and open all files with your desktop environments default file opener. Examples:
|
- Environment variable `NOICE_OPENER` to override all associations and open all files with your desktop environment's default file opener. Examples:
|
||||||
|
|
||||||
export NOICE_OPENER=xdg-open
|
export NOICE_OPENER=xdg-open
|
||||||
export NOICE_OPENER=gnome-open
|
export NOICE_OPENER=gnome-open
|
||||||
|
@ -113,6 +115,7 @@ Start noice (default: current directory):
|
||||||
| `e` | edit entry in `vim` |
|
| `e` | edit entry in `vim` |
|
||||||
| `p` | open entry with `less` pager |
|
| `p` | open entry with `less` pager |
|
||||||
| `z` | run `top` |
|
| `z` | run `top` |
|
||||||
|
| `Ctrl-k` | invoke file name copier |
|
||||||
| `Ctrl-l` | redraw window |
|
| `Ctrl-l` | redraw window |
|
||||||
| `q` | quit noice |
|
| `q` | quit noice |
|
||||||
|
|
||||||
|
@ -134,6 +137,22 @@ The following abbreviations are used in the detail view:
|
||||||
|
|
||||||
$ man noice
|
$ man noice
|
||||||
|
|
||||||
|
### Copy current file path to clipboard
|
||||||
|
|
||||||
|
noice 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.
|
||||||
|
|
||||||
|
Sample Linux copier script:
|
||||||
|
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo -n $1 | xsel --clipboard --input
|
||||||
|
|
||||||
|
export `NOICE_OPENER`:
|
||||||
|
|
||||||
|
export NOICE_COPIER="/home/vaio/copier.sh"
|
||||||
|
|
||||||
|
Start noice and use `Ctrl-k` to copy the absolute path (from `/`) of the file under the cursor to clipboard.
|
||||||
|
|
||||||
### Change file associations
|
### Change file associations
|
||||||
|
|
||||||
If you want to set custom applications for certain mime types, or change the ones set already (e.g. vim, fmedia, zathura), modify the `assocs` structure in [config.def.h](https://github.com/jarun/noice/blob/master/config.def.h) (it's easy). Then re-compile and install.
|
If you want to set custom applications for certain mime types, or change the ones set already (e.g. vim, fmedia, zathura), modify the `assocs` structure in [config.def.h](https://github.com/jarun/noice/blob/master/config.def.h) (it's easy). Then re-compile and install.
|
||||||
|
|
|
@ -71,6 +71,8 @@ struct key bindings[] = {
|
||||||
/* Toggle sort by time */
|
/* Toggle sort by time */
|
||||||
{ 't', SEL_MTIME },
|
{ 't', SEL_MTIME },
|
||||||
{ CONTROL('L'), SEL_REDRAW },
|
{ CONTROL('L'), SEL_REDRAW },
|
||||||
|
/* Copy currently selected file path */
|
||||||
|
{ CONTROL('K'), SEL_COPY },
|
||||||
/* Run command */
|
/* Run command */
|
||||||
{ 'z', SEL_RUN, "top" },
|
{ 'z', SEL_RUN, "top" },
|
||||||
{ '!', SEL_RUN, "sh", "SHELL" },
|
{ '!', SEL_RUN, "sh", "SHELL" },
|
||||||
|
|
18
noice.c
18
noice.c
|
@ -68,6 +68,7 @@ enum action {
|
||||||
SEL_FSIZE,
|
SEL_FSIZE,
|
||||||
SEL_MTIME,
|
SEL_MTIME,
|
||||||
SEL_REDRAW,
|
SEL_REDRAW,
|
||||||
|
SEL_COPY,
|
||||||
SEL_RUN,
|
SEL_RUN,
|
||||||
SEL_RUNARG,
|
SEL_RUNARG,
|
||||||
};
|
};
|
||||||
|
@ -94,6 +95,7 @@ int ndents, cur;
|
||||||
int idle;
|
int idle;
|
||||||
char *opener = NULL;
|
char *opener = NULL;
|
||||||
char *fallback_opener = NULL;
|
char *fallback_opener = NULL;
|
||||||
|
char *copier = NULL;
|
||||||
char size_buf[12]; /* Buffer to hold human readable size */
|
char size_buf[12]; /* Buffer to hold human readable size */
|
||||||
const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
|
const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||||
|
|
||||||
|
@ -884,6 +886,19 @@ nochange:
|
||||||
if (ndents > 0)
|
if (ndents > 0)
|
||||||
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
|
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
|
||||||
goto begin;
|
goto begin;
|
||||||
|
case SEL_COPY:
|
||||||
|
if (copier && ndents) {
|
||||||
|
char abspath[PATH_MAX];
|
||||||
|
|
||||||
|
if (strcmp(path, "/") == 0)
|
||||||
|
snprintf(abspath, PATH_MAX, "/%s", dents[cur].name);
|
||||||
|
else
|
||||||
|
snprintf(abspath, PATH_MAX, "%s/%s", path, dents[cur].name);
|
||||||
|
spawn(copier, abspath, NULL);
|
||||||
|
printmsg(abspath);
|
||||||
|
} else if (!copier)
|
||||||
|
printmsg("NOICE_COPIER is not set");
|
||||||
|
goto nochange;
|
||||||
case SEL_RUN:
|
case SEL_RUN:
|
||||||
run = xgetenv(env, run);
|
run = xgetenv(env, run);
|
||||||
exitcurses();
|
exitcurses();
|
||||||
|
@ -950,6 +965,9 @@ main(int argc, char *argv[])
|
||||||
/* Get the fallback desktop mime opener, if set */
|
/* Get the fallback desktop mime opener, if set */
|
||||||
fallback_opener = getenv("NOICE_FALLBACK_OPENER");
|
fallback_opener = getenv("NOICE_FALLBACK_OPENER");
|
||||||
|
|
||||||
|
/* Get the default copier, if set */
|
||||||
|
copier = getenv("NOICE_COPIER");
|
||||||
|
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
|
|
||||||
/* Test initial path */
|
/* Test initial path */
|
||||||
|
|
Loading…
Reference in a new issue