marvinkreis / rofi-file-browser-extended

Use rofi to quickly open files
MIT License
240 stars 15 forks source link

Feature request: Add Option to copy file to clipboard #37

Closed winiciuscota closed 2 years ago

winiciuscota commented 3 years ago

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

pianoslum commented 2 years ago

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 ;)

marvinkreis commented 2 years ago

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: https://github.com/marvinkreis/rofi-file-browser-extended/blob/256487470ef7e5006bacdf29a7b8593e3148e7ff/include/types.h#L83-L102 (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: https://github.com/marvinkreis/rofi-file-browser-extended/blob/256487470ef7e5006bacdf29a7b8593e3148e7ff/src/filebrowser.c#L206-L211 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: https://github.com/marvinkreis/rofi-file-browser-extended/blob/256487470ef7e5006bacdf29a7b8593e3148e7ff/src/options.c#L158-L165 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): https://github.com/marvinkreis/rofi-file-browser-extended/blob/256487470ef7e5006bacdf29a7b8593e3148e7ff/src/keys.c#L59-L104

pianoslum commented 2 years ago

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?

marvinkreis commented 2 years ago

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

But I don't know when I'll get around to implementing this, so might as well change the README for now.

winiciuscota commented 2 years ago

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

Drag and Drop drag-n-drop

Copy and Paste(Tested on dolphin only) copy-n-paste-2