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

Wayland: Global hook to yank operations with wl-copy waits command to finish forever #2818

Closed
3ynm opened this issue Mar 27, 2019 · 5 comments

Comments

@3ynm
Copy link
Contributor

3ynm commented Mar 27, 2019

Steps

Copy the following to your kakrc:

# Use system's clipboard
hook global NormalKey y|d|c %{ nop %sh{
  printf %s "$kak_main_reg_dquote" | wl-copy
}}

reload the kakoune config and yank something

Outcome

kakoune says waiting for shell command to finish until you press Ctrl+C

Expected

Should not expect command to finish, because it contains the copied contents.

Related to #2325

@3ynm 3ynm changed the title Global hook to yank operations with wl-copy waits command to finish forever Wayland: Global hook to yank operations with wl-copy waits command to finish forever Mar 27, 2019
@sam-willis
Copy link

I think this is related to wl-copy actually continuing to run in the background. On yanking kakoune freezes, and the buffer is copied to the system clipboard, but if you C-c (ending the process and unfeezing kakoune) the system clipboard clears.

@3ynm
Copy link
Contributor Author

3ynm commented Mar 30, 2019

Yes, it is because of that. As I said my expected result is "Should not expect command to finish, because it contains the copied contents." I don't know how to do that, or if even it is feasible.

@laelath
Copy link
Contributor

laelath commented Mar 30, 2019

I don't have a wayland compositor installed to test, but I think this would work?

# Use system's clipboard
hook global NormalKey y|d|c %{ nop %sh{
  printf %s "$kak_main_reg_dquote" | wl-copy > /dev/null 2>&1 &
}}

@3ynm
Copy link
Contributor Author

3ynm commented Apr 2, 2019

Yes it does :D!! Posted it in the wiki, thanks!

Would be great if you explain why this works... I've tried running the process in background, but not with redirecting outputs, I don't grok it really.

@3ynm 3ynm closed this as completed Apr 2, 2019
@Screwtapello
Copy link
Contributor

The %sh{} expansion runs a shell-script and collects its output, then waits for the script to exit. To prevent Kakoune from waiting for a long-running process, you need to:

  • redirect stdout with > /dev/null so that the long-running process does not inherit the shell's stdout, and therefore the stdout Kakoune reads will be closed immediately when the shell exits
  • redirect stderr with 2> /dev/null (or if stdout is already redirected, 2>&1) for the same reason
  • run the process in the background with & so the shell exits 0 immediately instead of waiting for the long-running process to exit

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

No branches or pull requests

4 participants