Przeglądaj źródła

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.
master
Arun Prakash Jana 7 lat temu
rodzic
commit
c42790aa18
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: A75979F35C080412
3 zmienionych plików z 40 dodań i 1 usunięć
  1. +20
    -1
      README.md
  2. +2
    -0
      config.def.h
  3. +18
    -0
      noice.c

+ 20
- 1
README.md Wyświetl plik

@@ -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.

+ 2
- 0
config.def.h Wyświetl plik

@@ -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" },


+ 18
- 0
noice.c Wyświetl plik

@@ -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 */


Ładowanie…
Anuluj
Zapisz