Skip to content

Commit 79d0c3a

Browse files
committed
Fixed bug in clipboard function
Svelo was alerting users when the Wayland clipboard command failed, even if X11 was successful. This fix avoids needlessly alerting the user if one fails but not the other.
1 parent 404a925 commit 79d0c3a

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/svelo/cli.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,28 @@ def _suppress_ctrl_echo() -> None:
409409
def _copy_to_clipboard(text: str) -> bool:
410410
if not text:
411411
return False
412+
wayland_display = os.environ.get("WAYLAND_DISPLAY")
413+
session_type = os.environ.get("XDG_SESSION_TYPE", "").lower()
414+
is_wayland = bool(wayland_display) or session_type == "wayland"
412415
commands = []
413416
if sys.platform == "darwin" and shutil.which("pbcopy"):
414417
commands.append(["pbcopy"])
415-
if shutil.which("wl-copy"):
418+
if is_wayland and shutil.which("wl-copy"):
416419
commands.append(["wl-copy"])
417420
if shutil.which("xclip"):
418421
commands.append(["xclip", "-selection", "clipboard"])
419422
if shutil.which("clip"):
420423
commands.append(["clip"])
421424
for cmd in commands:
422425
try:
423-
subprocess.run(cmd, input=text, text=True, check=True)
426+
subprocess.run(
427+
cmd,
428+
input=text,
429+
text=True,
430+
check=True,
431+
stdout=subprocess.DEVNULL,
432+
stderr=subprocess.DEVNULL,
433+
)
424434
except (OSError, subprocess.CalledProcessError):
425435
continue
426436
return True

0 commit comments

Comments
 (0)