From ae6bdfa37c7cf9462f9ffd53de91a70644c18570 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 27 Oct 2019 12:31:35 -0500 Subject: [PATCH] Handle empty clipboard for all providers Closes #6254 --- share/functions/fish_clipboard_paste.fish | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/share/functions/fish_clipboard_paste.fish b/share/functions/fish_clipboard_paste.fish index 0ed27abce..08c0402b5 100644 --- a/share/functions/fish_clipboard_paste.fish +++ b/share/functions/fish_clipboard_paste.fish @@ -1,21 +1,20 @@ function fish_clipboard_paste set -l data if type -q pbpaste - set data (pbpaste) + set data (pbpaste 2>/dev/null) else if set -q WAYLAND_DISPLAY; and type -q wl-paste - set data (wl-paste) + set data (wl-paste 2>/dev/null) else if type -q xsel - # Return if `xsel` failed. - # That way we don't print the redundant (and overly verbose for this) commandline error. - # Also require non-empty contents to not clear the buffer. - if not set data (xsel --clipboard 2>/dev/null) - return 1 - end + set data (xsel --clipboard 2>/dev/null) else if type -q xclip - if not set data (xclip -selection clipboard -o 2>/dev/null) - return 1 - end + set data (xclip -selection clipboard -o 2>/dev/null) end + + # Issue 6254: Handle zero-length clipboard content + if not string match -qr . -- "$data" + return 1 + end + # Also split on \r to turn it into a newline, # otherwise the output looks really confusing. set data (string split \r -- $data)