Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add oneshot mode to sync clipboard #27

Closed
kaihendry opened this issue Nov 13, 2015 · 10 comments
Closed

Add oneshot mode to sync clipboard #27

kaihendry opened this issue Nov 13, 2015 · 10 comments
Assignees

Comments

@kaihendry
Copy link

When I copy from my terminal, I've noticed that sometimes the default sleep of 0.5 is not quick enough to synchronize, leaving my clipmenu-url to act on the wrong URL for example.

Clipmenud's loop needs to be refactored into a function so I can call clipmenu from st directly.

@cdown
Copy link
Owner

cdown commented Nov 13, 2015

Can you show me clipmenu-url? I didn't find it in your dotfiles.

Your solution doesn't make much sense. It doesn't sound like you want a function, it sounds like you want a oneshot mode.

@kaihendry
Copy link
Author

https://github.com/kaihendry/clipmenu/blob/url-shortcut/clipmenu-url

Yes, oneshot "request the clipboard manager to take over the ownership of the clipboard" as put on http://askubuntu.com/a/61328/676

@cdown cdown changed the title Trigger clipboard synchronisation Add oneshot mode to sync clipboard Nov 13, 2015
@cdown
Copy link
Owner

cdown commented Nov 13, 2015

Sounds reasonable enough.

@cdown cdown self-assigned this Nov 13, 2015
@AeliusSaionji
Copy link

@kaihendry do I understand correctly that you are trying to launch your browser from the selected text? You're trying to take a very roundabout approach to this. The better way is to use a more direct approach with xsel.

xsel -co | xargs -r xdg-open
This prints the currently selected text to stdout, which we pipe to xargs so that xdg-open can receive it as an argument.

Replace your clipmenu-url with this single line of code :)

@kaihendry
Copy link
Author

This is a very good suggestion, thank you! The only drawback is that I may want to use the script on the last URL after making another non-URL selection, if that makes sense?

@AeliusSaionji
Copy link

Sure. To accomplish that, I would combine your approach and mine.

Something like

#!/bin/bash

LC_COLLATE=C

if url=$(xsel -co > /tmp/sel && grep --only-matching --perl-regexp "http(s?):\/\/[^ \"\(\)\<\>\]]*" "/tmp/sel")
then
    xdg-open $url
else
    files=(/tmp/clipmenu/*)

    for (( i=${#files[@]}-1; i>=0; i-- )); do
        file=${files[$i]}
        if url=$(grep --only-matching --perl-regexp "http(s?):\/\/[^ \"\(\)\<\>\]]*" "$file")
        then
            xdg-open $url
            break
        fi
    done
fi

I have not tested this, you might have to make some adjustments.

@kaihendry
Copy link
Author

Weird, xsel -co doesn't output anything for me on Arch.

@AeliusSaionji
Copy link

For the past week or so, clipmenud has not worked for me, and actively prevents me from copying anything. I've been meaning to make an issue but haven't found the time to dig into what caused this. Does xsel -co work for you if clipmenud is not running?

@kaihendry
Copy link
Author

xsel -co is not working at all.

Reverted to using xclip again with

if url=$(xclip -o | grep --only-matching --perl-regexp "http(s?):\/\/[^ \"\(\)\<\>\]]*")

cdown added a commit that referenced this issue Feb 18, 2017
This is a prerequisite for adding oneshot mode, see #27.
@cdown cdown closed this as completed in db05c51 Feb 18, 2017
@cdown
Copy link
Owner

cdown commented Feb 18, 2017

Easy enough now that we have locking support, see db05c51 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants