README.md | 21 ++++++++++++++++++++- config.def.h | 2 ++ noice.c | 18 ++++++++++++++++++ diff --git a/README.md b/README.md index 775fd6d5b4f9a2e2b1cb181a6d8cbd31ba4e364a..5912a98284d0aa7b53b64f8d50de7f5638a4531e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ - [Usage](#usage) - [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 @@ - full name of currently selected file - 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 @@ | `!` | spawn a shell in current dir | | `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 | @@ -133,6 +136,22 @@ ### Help $ 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 diff --git a/config.def.h b/config.def.h index 9c6ae7e81f23eaac292afad8221a484977ca4052..7ec98effbdebcc153a02bb5613185975cdfc8b8e 100644 --- a/config.def.h +++ b/config.def.h @@ -71,6 +71,8 @@ { 's', SEL_FSIZE }, /* 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 08bca9ea4fc4cad417047026a5b0d45f31cb7d3a..6f64b5e821d801bfce6e4eacdf8bcb5f3f69f5bb 100644 --- a/noice.c +++ b/noice.c @@ -68,6 +68,7 @@ SEL_DETAIL, 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 @@ /* Save current */ 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(); @@ -949,6 +964,9 @@ opener = getenv("NOICE_OPENER"); /* 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);