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 option to copy to clipboard #110

Closed
firecat53 opened this issue Mar 10, 2022 · 20 comments
Closed

Add option to copy to clipboard #110

firecat53 opened this issue Mar 10, 2022 · 20 comments
Labels
enhancement New feature or request

Comments

@firecat53
Copy link
Owner

Consider adding a feature to switch to clipboard instead of typing. Some
websites lose focus on the input field as soon as keepmenu is opened.

  • Preferably switch on the fly instead of globally
  • Support xsel/xclip/wl-clipboard
@firecat53 firecat53 added the enhancement New feature or request label Mar 10, 2022
@vaygr
Copy link
Contributor

vaygr commented Sep 4, 2022

I second this. It's especially valuable on multi-screen setups when you're having a video call and need to login into the website you're showing discreetly without exposing your database.

firecat53 added a commit that referenced this issue Aug 25, 2023
@firecat53
Copy link
Owner Author

@vaygr - I pushed an initial stab at this to the clipboard branch. Would you
be able to test and give any feedback (including documentation)?

  • Toggle in the menu or with the -C cli argument.
  • If View/Type Individual entries isn't initially selected, the password will
    be copied to the clipboard if it exists. Otherwise, an error will pop up. The
    other option could be to only display the view/type invidual entries menu if
    the clipboard option is active. I figured most people would likely want the
    password copied of any of the fields.
  • xsel or wl-copy should be automatically selected depending on the
    environment.

Thanks!

@vaygr
Copy link
Contributor

vaygr commented Aug 30, 2023

Excellent, thanks for implementing this. I tested this both in regular and TOTP mode: works perfectly.

One request though: maybe add xclip as a fallback if xsel is not available?

@firecat53
Copy link
Owner Author

Thanks for testing! I appreciate the second set of eyes.

Yeah, I can add xsel. I didn't at first because of course it uses different CLI
options than xsel and wl-copy 😄

@vaygr
Copy link
Contributor

vaygr commented Sep 1, 2023

@firecat53 I think you meant "I can add xclip" :)

@firecat53
Copy link
Owner Author

Heh, oops 🤭 I'm mostly done adding xclip actually.

@firecat53
Copy link
Owner Author

Added xclip support to develop branch. Test for me?

@vaygr
Copy link
Contributor

vaygr commented Sep 2, 2023

Tried it, copy/paste works as expected. The commit changed clear behavior though?

I use -C flag, several minutes later I can access secret data via both xsel and xclip -o.

@firecat53
Copy link
Owner Author

Are you sure you pulled down the most recent changes? I force-pushed some this morning (sorry). The diff you posted is right, but that should be the correct behavior. I tested in Sway and Gnome(Xorg).

@vaygr
Copy link
Contributor

vaygr commented Sep 2, 2023

Yeah, I cloned the fresh repo right before I posted this comment.

@firecat53
Copy link
Owner Author

Hmmm. The symptom you described was what I fixed this morning. I've tested that block of code from type.py with wl-copy, xsel and xclip and it all clears the clipboard appropriately.

  1. Humor me and check that you reinstalled the newest develop branch.
  2. Try this in a keepmenu dev environment (either nix develop or hatch shell)
❯ python
Python 3.10.12 (main, Jun  6 2023, 22:43:10) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import keepmenu
>>> from shlex import split
>>> from threading import Timer
>>> from subprocess import run
>>> keepmenu.reload_config()
>>> def type_clipboard(text):
...     """Copy text to clipboard and clear clipboard after 30 seconds
... 
...     Args: text - str
... 
...     """
...     text = text or ""  # Handle None type
...     run(split(keepmenu.CLIPBOARD_CMD), check=True, input=text.encode(keepmenu.ENC))
...     clear = Timer(30, lambda: run(split(keepmenu.CLIPBOARD_CMD), check=False, input=""))
...     clear.start()
... 
>>> type_clipboard("HELP")
  1. Paste your clipboard, then wait the 30 seconds. All it's doing is piping an empty string into the clipboard command to clear it. I don't have any idea why that wouldn't work for you.
  2. Window manager, distro? How did you install keepmenu?

@vaygr
Copy link
Contributor

vaygr commented Sep 3, 2023

OK, steps to reproduce:

  1. git clone git@github.com:firecat53/keepmenu.git
  2. cd keepmenu
  3. git checkout develop
  4. make
  5. . venv/bin/activate
  6. keepmenu -C
  7. Select an entry
  8. Test somewhere Ctrl+v works as expected
  9. Wait 30 seconds
  10. Repeat 8. and make sure clipboard is empty
  11. Open a separate terminal window
  12. Run xsel

Same result with xclip -o.

This is latest bspwm on Manjaro.

@firecat53
Copy link
Owner Author

Do you have a small utility that synchronizes your clipboard with the primary selection? I'm only clearing the clipboard because that's where the information is copied to, not to the primary selection. wl-copy defaults to clipboard and I use xsel -b and xclip -sel clip.

@vaygr
Copy link
Contributor

vaygr commented Sep 7, 2023

I know what was happening: while testing copy-paste in the browser I was accidentally selecting the whole entry with the mouse to delete it in the input field, which was copying it to primary. Sorry for the confusion, this is good to go.

@vaygr
Copy link
Contributor

vaygr commented Sep 8, 2023

Hmm, strange. Tried to use totp mode today: it seems it stopped working with the latest clipboard changes.

@firecat53
Copy link
Owner Author

firecat53 commented Sep 8, 2023

You're gonna have to be more specific :) Seems to still be working here, both typing and typing to clipboard.

Edit: I'm running from the develop branch, FYI

@vaygr
Copy link
Contributor

vaygr commented Sep 8, 2023

Yeah, it works on one machine and doesn't on another. I'll be able to provide more info soon.

@vaygr
Copy link
Contributor

vaygr commented Sep 10, 2023

The problem disappeared on its own after updating to the latest commit. I think it's safe to mark it as resolved.

@firecat53
Copy link
Owner Author

Thanks for spending the time to troubleshoot!

@treeshateorcs
Copy link
Contributor

i have a suggestion.

xclip (as opposed to xsel) allows for the same paste once option as wl-copy on wayland

(from man xclip)

       -l, -loops
              number of X selection requests (pastes into X applications) to wait for
              before exiting, with a value of 0 (default) causing xclip to  wait  for
              an unlimited number of requests until another application (possibly an‐
              other invocation of xclip) takes ownership of the selection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants