cdown / clipmenu

Clipboard management using dmenu
MIT License
1.14k stars 91 forks source link

clipmenu: print selection to stdout #108

Closed jb55 closed 4 years ago

jb55 commented 5 years ago

This allows you to use clipmenu in desktop scripts. For example you could pipe the output of your narrowed selection to another command.

Signed-off-by: William Casarin jb55@jb55.com

cdown commented 5 years ago

This is fine, but we need to gate it, and we really don't have a good way of doing that right now.

Let me fix up the current options to get replaced by getopt. Then we can back this with -p or something. :-)

jb55 commented 5 years ago

ok, also it might be better to just cat the file and then printf a newline instead of buffering the whole file into memory here. probably not that big of deal, but for large selections it might be slow/use memory.

jb55 commented 5 years ago

I pushed an update, no need to do anything complicated with getopt (yet). what do you think?

jb55 commented 5 years ago

ah I just realized -p is a dmenu option, so this will break existing setups

jb55 commented 5 years ago

pushed a v3 that replaces the -p,--print option with --clipmenu-print which shouldn't overlap with $CM_LAUNCHER options

cdown commented 5 years ago

I'd rather properly support getopt as a separate piece of work, first. I'll take a look at that this week. Then we can just rebase and piggyback this PR off of it :-)

cdown commented 4 years ago

In the end we didn't use getopt, because I don't want to end up with mpdmenu-style arg mangling.

If this is gated behind something like CM_OUTPUT_CLIP, we should be good to go :-)

jb55 commented 4 years ago

done

cdown commented 4 years ago

Looks great! Let's make it accept 1 or 0 as with the other settings, though, by making the check (( CM_OUTPUT_CLIP )) :-)

You can take a look at how CM_DEBUG is implemented in clipmenud to see how that works and how it's set up.

jb55 commented 4 years ago

neat trick, will be using that in my scripts now. pushed an update

jb55 commented 4 years ago

tests are failing but I'm not sure why

cdown commented 4 years ago

(( CM_OUTPUT_CLIP )) rather than (( "$CM_OUTPUT_CLIP" )) -- there's no need to do that inside arithmetic expressions :-)

It fails because your command returns 1, which is the final command executed, so the script also returns 1. If you use an if guard, this won't happen.

You can also drop the exec -- this is the last thing we run anyway, so there's not much to be gained, especially if refactoring happens later.

jb55 commented 4 years ago

thanks, updated

edit: just need to add the if guard

jb55 commented 4 years ago

ok that should fix it...

jb55 commented 4 years ago

please match the indentation for the rest of the file :)

lol fair. sorry for the patch review DoS attack