From b3444ea12847217344ee926d2a0dc754b9cbc515 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 21 Apr 2024 14:18:44 +0200 Subject: [PATCH] Work around ctrl-c in VSCode killing wl-copy and clearing clipboard wl-copy is a daemon process that serves its stdin to any wl-paste processes. On Wayland, we launch it from fish_clipboard_copy. It then lives in the same process group as fish (see `ps -o pid,pgid,comm`). For some reason pressing ctrl-c inside the VSCode integrated terminal with fish as the default shell kills the wl-copy process, thus clearing the clipboard. On other terminals it works fine. This is also reproducible by running "echo foo | wl-copy" ctrl-v ctrl-c ctrl-v (the second ctrl-v does not paste because wl-copy was killed). Work around this for now by running wl-copy asynchronously, and disowning it. This seems to fix it though I really don't know why. Alternatively we could "setsid" but that's technically not available on BSD. For some reason this works in Bash. We should strace it to figure out why. --- CHANGELOG.rst | 3 ++- share/functions/fish_clipboard_copy.fish | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 50fa485fa..631af9495 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -114,7 +114,8 @@ Interactive improvements - Command abbreviations (those with ``--position command`` or without a ``--position``) now also expand after decorators like ``command`` (:issue:`10396`). - Abbreviations now expand after process separators like ``;`` and ``|``. This fixes a regression in version 3.6 (:issue:`9730`). - When exporting interactively defined functions (using ``type``, ``functions`` or ``funcsave``) the function body is now indented, same as in the interactive command line editor (:issue:`8603`). -- ``fish_clipboard_copy`` now copies indentation for multiline commands (:issue:`10437`). +- :kbd:`ctrl-x` (``fish_clipboard_copy``) on multiline commands now includes indentation (:issue:`10437`). +- When using :kbd:`ctrl-x` on Wayland in the VSCode terminal, the clipboard is no longer cleared on :kbd:`ctrl-c`. New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/share/functions/fish_clipboard_copy.fish b/share/functions/fish_clipboard_copy.fish index adfc2f54d..74985c48a 100644 --- a/share/functions/fish_clipboard_copy.fish +++ b/share/functions/fish_clipboard_copy.fish @@ -15,7 +15,8 @@ function fish_clipboard_copy if type -q pbcopy printf '%s' $cmdline | pbcopy else if set -q WAYLAND_DISPLAY; and type -q wl-copy - printf '%s' $cmdline | wl-copy + printf '%s' $cmdline | wl-copy & + disown else if set -q DISPLAY; and type -q xsel printf '%s' $cmdline | xsel --clipboard else if set -q DISPLAY; and type -q xclip