Feature request: Add Option to copy file to clipboard
Closed this issue · 5 comments
Not sure if this is possible but I think it would be really useful to have an option to copy and paste/drag the file(just like ctrl+c ctrl+v/drag n drop) from a file explorer
Hi, I'd like to try to implement this feature as this would be helpful for me.
@winiciuscota what exact functionality do you have in mind? I thought about reserving ctrl + Return to copy the path.
@marvinkreis do you have any pointers where you would implement this? I just started digging through the code and my C is a littly rusty ;)
Hi @pianoslum. First of all, thanks for contributing. I appreciate it :)
Since I haven't responded to this issue yet: Unfortunately, drag and drop isn't possible with rofi's custom mode API.
The way to implement this would be to assign one of rofi's available keys to a copy (or paste) action.
From what I've gathered, kb-custom-*
and kb-accept-alt
are keys that can be used for custom modes.
(Maybe others are available now, I haven't checked this in a while.)
Anyways, the key bindings are defined here:
rofi-file-browser-extended/include/types.h
Lines 83 to 102 in 2564874
(
rofi -show keys
will show your current bindings, which is very helpful for troubleshooting.)
To implement the actual copying part, you'd check for the key press somewhere here:
rofi-file-browser-extended/src/filebrowser.c
Lines 206 to 211 in 2564874
Pretty much just create another else case and check if the configured key is pressed.
Then copy (or paste) the file there.
Finally, to make it configurable, add it as an option here:
rofi-file-browser-extended/src/options.c
Lines 158 to 165 in 2564874
And extend the key binding validation here (shouldn't be much more that adding it to the arrays and changing the 3s to the new number of key bindings, I think):
rofi-file-browser-extended/src/keys.c
Lines 59 to 104 in 2564874
Thanks a lot.
After digging around a bit, I think that integrating copying to clipboard in the C-code is much too cumbersome.
I found a little workaround to achieve the same basic functionality:
Create a small bash script copyFilePath
basically consisting of echo "$1" | xclip -r
and put it somewhere in the path.
The you can either override the standard command (if you only want to copy) or use this command in the open-custom-list.
A little bit more elegant solution would be to offer a 2nd open-command that can be freely configured like the primary one (and set to aforementioned script for the path-copy-functionality).
I could update the Readme about my workaround and/or provide the patch for a second open-command.
What do you think?
Hmm, yeah. I googled a bit, and clipboard manipulation in C indeed seems very cumbersome.
I like the open-custom workaround though. If you already have an idea about what to write in the README, I'd be happy to use it. Otherwise, I'll just write 1 or 2 sentences about it.
As for the 2nd open-command: I already have plans to change the key bindings to map commands to keys instead of the other way around. This would make it possible, to map different open-commands to keys, e.g.:
kb-custom-1
-> toggle hidden fileskb-accept-entry
-> open with xdg-openkb-accept-alt
-> open with copyFilePath
But I don't know when I'll get around to implementing this, so might as well change the README for now.
wow, I forgot I had created this issue. Really sorry about that.
I managed to create exactly the solution I wanted shortly after by integrating rofi-file-browser-extended to Dragon-drag-and-drop
The gist with the scripts to copy-n-paste and drag-n-drop: https://gist.github.com/winiciuscota/5790f7b6134518555d7d6b1426298abe