2016-05-24 19:17:03 +08:00
|
|
|
function fish_clipboard_paste
|
2017-03-09 23:52:38 +08:00
|
|
|
set -l data
|
2016-11-28 13:27:22 +08:00
|
|
|
if type -q pbpaste
|
2017-03-09 23:52:38 +08:00
|
|
|
set data (pbpaste)
|
2016-05-24 19:17:03 +08:00
|
|
|
else if type -q xsel
|
2017-03-09 23:52:38 +08:00
|
|
|
# Return if `xsel` failed.
|
2016-11-28 17:09:58 +08:00
|
|
|
# That way any xsel error is printed (to show e.g. a non-functioning X connection),
|
|
|
|
# but we don't print the redundant (and overly verbose for this) commandline error.
|
2016-12-11 04:26:51 +08:00
|
|
|
# Also require non-empty contents to not clear the buffer.
|
2017-03-09 23:52:38 +08:00
|
|
|
if not set data (xsel --clipboard)
|
|
|
|
return 1
|
2016-11-28 17:09:58 +08:00
|
|
|
end
|
2016-05-24 19:17:03 +08:00
|
|
|
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
|
|
|
|
set data (string replace -ra "(['\\\])" '\\\\\\\$1' -- $data)
|
|
|
|
end
|
|
|
|
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
|