2019-10-28 01:34:58 +08:00
|
|
|
function fish_clipboard_paste
|
2019-11-05 03:47:58 +08: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)
|
|
|
|
end
|
2019-10-28 01:31:35 +08:00
|
|
|
|
|
|
|
# Issue 6254: Handle zero-length clipboard content
|
|
|
|
if not string match -qr . -- "$data"
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2017-04-23 19:40:40 +08: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 23:52:38 +08: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 13:28:17 +08:00
|
|
|
if status test-feature regex-easyesc
|
2019-01-20 18:12:27 +08:00
|
|
|
set data (string replace -ra "(['\\\])" '\\\\$1' -- $data)
|
|
|
|
else
|
|
|
|
set data (string replace -ra "(['\\\])" '\\\\\\\$1' -- $data)
|
|
|
|
end
|
2017-03-09 23:52:38 +08:00
|
|
|
end
|
2019-03-13 19:15:45 +08: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 17:19:21 +08:00
|
|
|
set data[1] (string trim -l -- $data[1])
|
2019-03-13 19:15:45 +08:00
|
|
|
end
|
2017-03-09 23:52:38 +08:00
|
|
|
if test -n "$data"
|
2017-04-23 19:38:32 +08:00
|
|
|
commandline -i -- $data
|
2017-03-09 23:52:38 +08:00
|
|
|
end
|
2016-05-24 19:17:03 +08:00
|
|
|
end
|