Copy the path of a file from within the ranger file manager
So it says vim-like bindings, so naturally a first try will be to type ‘y’ (for yank, Vim’s copy command). And indeed, it brings up a list of further options, and the command to copy the filename, directory, or full path with the name and directory is right there… but you would need to understand how to write the command already to know what it does:
p shell -f echo -n %d/%f | xsel -i; xsel -o | xsel -i -b
I needed to get answers from support list archives to figure it out. The Ranger users’ list on GNU.org and the Arch bulletin board had the same solution.
Roman Z put it most succinctly and completely:
If you got xsel, you can use one of the “yp”, “yn”, “yd” keys depending on what exactly you want
yd - copy directory name only
yn - copy file name only
yp - copy full path
And now i was able to paste the path of the graphic i was considering – /home/mlncn/Cloud/Agaric/graphics/Brand Assets/icons/blue/icon-coop.png
– in my note about funding cooperatives on Kiva.
I’ve gone ahead and added a note to Ranger’s official user guide:
(To copy only the directory, filename, or file path with name as text to your clipboard, use “yd”, “yn”, and “yp” respectively. Copying actual files remains internal to ranger.)
I hope other operating systems have as nice an integration where the clipboard does indeed receive the various flavors of file path. Update: Presumably not, since the command uses xsel, and even GNU/Linux might not have that. The commands do show how you could build your own, as long as you have some command that can push text to your clipboard. I edited my answer to reference xsel:
(To copy only the directory, filename, or file path with name as text to your clipboard — requires that xsel is installed — use “yd”, “yn”, and “yp” respectively. Copying actual files remains internal to ranger.)