aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md21
-rw-r--r--config.def.h2
-rw-r--r--noice.c18
3 files changed, 40 insertions, 1 deletions
diff --git a/README.md b/README.md
index 775fd6d..5912a98 100644
--- a/README.md
+++ b/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)
- [File type abbreviations](#file-type-abbreviations)
- [Help](#help)
+- [Copy current file path to clipboard](#copy-current-file-path-to-clipboard)
- [Change file associations](#change-file-associations)
### Introduction
@@ -54,8 +55,9 @@ I chose to fork noice because:
- 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)
- Sort entries by file size (largest to smallest)
+ - Shortcut to invoke file name copier (set using environment variable `NOICE_COPIER`)
- 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=gnome-open
@@ -113,6 +115,7 @@ Start noice (default: current directory):
| `e` | edit entry in `vim` |
| `p` | open entry with `less` pager |
| `z` | run `top` |
+| `Ctrl-k` | invoke file name copier |
| `Ctrl-l` | redraw window |
| `q` | quit noice |
@@ -134,6 +137,22 @@ The following abbreviations are used in the detail view:
$ 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
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.
diff --git a/config.def.h b/config.def.h
index 9c6ae7e..7ec98ef 100644
--- a/config.def.h
+++ b/config.def.h
@@ -71,6 +71,8 @@ struct key bindings[] = {
/* Toggle sort by time */
{ 't', SEL_MTIME },
{ CONTROL('L'), SEL_REDRAW },
+ /* Copy currently selected file path */
+ { CONTROL('K'), SEL_COPY },
/* Run command */
{ 'z', SEL_RUN, "top" },
{ '!', SEL_RUN, "sh", "SHELL" },
diff --git a/noice.c b/noice.c
index 08bca9e..6f64b5e 100644
--- a/noice.c
+++ b/noice.c
@@ -68,6 +68,7 @@ enum action {
SEL_FSIZE,
SEL_MTIME,
SEL_REDRAW,
+ SEL_COPY,
SEL_RUN,
SEL_RUNARG,
};
@@ -94,6 +95,7 @@ int ndents, cur;
int idle;
char *opener = NULL;
char *fallback_opener = NULL;
+char *copier = NULL;
char size_buf[12]; /* Buffer to hold human readable size */
const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
@@ -884,6 +886,19 @@ nochange:
if (ndents > 0)
mkpath(path, dents[cur].name, oldpath, sizeof(oldpath));
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:
run = xgetenv(env, run);
exitcurses();
@@ -950,6 +965,9 @@ main(int argc, char *argv[])
/* Get the fallback desktop mime opener, if set */
fallback_opener = getenv("NOICE_FALLBACK_OPENER");
+ /* Get the default copier, if set */
+ copier = getenv("NOICE_COPIER");
+
signal(SIGINT, SIG_IGN);
/* Test initial path */