1

Using nnn (which is a terminal-based file manager), how can you copy the text of a file or folder's name to the clipboard?

For your convenience, this will install and launch nnn in Debian (if you'd like to help me figure it out):

sudo apt install nnn ; nnn
Lonnie Best
  • 4,895
  • 6
  • 27
  • 42
  • 1
    One way, that I just discovered, is to press the `f` key. This displays the path, where I can then copy using my mouse. Is there a quicker way than this? – Lonnie Best Jul 27 '22 at 14:13

3 Answers3

2

The best way would be to use the nnn plugin functionality and pipe the name to xclip, for example:

export NNN_PLUG='s:! echo $nnn|xclip*'

and then hit ;s to pipe the currently selected name to xclip

Note: Debian stable has a rather old version of nnn with which this solution won't work. I suggest to build nnn yourself or backport it from testing

ijoseph
  • 154
  • 1
  • 9
Harry
  • 194
  • 4
  • In Debian 11, I added `deb http://deb.debian.org/debian bullseye-backports main` to the file `/etc/apt/sources.list`. Then, at a command prompt, I entered `sudo apt update ; sudo apt install nnn/bullseye-backports`. I received this error `E: Release 'bullseye-backports' for 'nnn' was not found`. – Lonnie Best Jul 28 '22 at 00:02
  • 1
    Yes, unfortunately there is no package in bullseye-backports for nnn. You have to backport it yourself or just build it yourself or use the packages provided at https://github.com/jarun/nnn/releases – Harry Jul 28 '22 at 06:55
  • If you want user-confirmation afterwards, omit the final `*` in the above command. – ijoseph Nov 21 '22 at 05:09
  • notice this copies only the filename, not the full path – robertspierre Nov 25 '22 at 12:56
1

To copy the full path, not just the name, in Wayland, use:

NNN_PLUG=s:-!echo $PWD/$nnn|wl-copy*
robertspierre
  • 271
  • 2
  • 10
1

There is a nnn plugin that allows you to copy absolute and relative paths here.

robertspierre
  • 271
  • 2
  • 10