2019-10-27 17:34:58 +00:00
|
|
|
function fish_clipboard_paste
|
2019-11-04 19:47:58 +00:00
|
|
|
set -l data
|
|
|
|
if type -q pbpaste
|
|
|
|
set data (pbpaste 2>/dev/null)
|
|
|
|
else if set -q WAYLAND_DISPLAY; and type -q wl-paste
|
|
|
|
set data (wl-paste 2>/dev/null)
|
|
|
|
else if type -q xsel
|
|
|
|
set data (xsel --clipboard 2>/dev/null)
|
|
|
|
else if type -q xclip
|
|
|
|
set data (xclip -selection clipboard -o 2>/dev/null)
|
2020-11-06 12:11:56 +00:00
|
|
|
else if type -q powershell.exe
|
|
|
|
set data (powershell.exe Get-Clipboard | string trim -r -c \r)
|
2019-11-04 19:47:58 +00:00
|
|
|
end
|
2019-10-27 17:31:35 +00:00
|
|
|
|
|
|
|
# Issue 6254: Handle zero-length clipboard content
|
|
|
|
if not string match -qr . -- "$data"
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2017-04-23 11:40:40 +00:00
|
|
|
# Also split on \r to turn it into a newline,
|
|
|
|
# otherwise the output looks really confusing.
|
|
|
|
set data (string split \r -- $data)
|
|
|
|
|
2017-03-09 15:52:38 +00:00
|
|
|
# If the current token has an unmatched single-quote,
|
|
|
|
# escape all single-quotes (and backslashes) in the paste,
|
|
|
|
# in order to turn it into a single literal token.
|
|
|
|
#
|
|
|
|
# This eases pasting non-code (e.g. markdown or git commitishes).
|
|
|
|
if __fish_commandline_is_singlequoted
|
2019-08-14 05:28:17 +00:00
|
|
|
if status test-feature regex-easyesc
|
2019-01-20 10:12:27 +00:00
|
|
|
set data (string replace -ra "(['\\\])" '\\\\$1' -- $data)
|
|
|
|
else
|
|
|
|
set data (string replace -ra "(['\\\])" '\\\\\\\$1' -- $data)
|
|
|
|
end
|
2017-03-09 15:52:38 +00:00
|
|
|
end
|
2019-03-13 11:15:45 +00:00
|
|
|
if not string length -q -- (commandline -c)
|
|
|
|
# If we're at the beginning of the first line, trim whitespace from the start,
|
|
|
|
# so we don't trigger ignoring history.
|
2019-05-11 09:19:21 +00:00
|
|
|
set data[1] (string trim -l -- $data[1])
|
2019-03-13 11:15:45 +00:00
|
|
|
end
|
2017-03-09 15:52:38 +00:00
|
|
|
if test -n "$data"
|
2017-04-23 11:38:32 +00:00
|
|
|
commandline -i -- $data
|
2017-03-09 15:52:38 +00:00
|
|
|
end
|
2016-05-24 11:17:03 +00:00
|
|
|
end
|