2016-05-24 11:17:03 +00:00
|
|
|
function fish_clipboard_paste
|
2017-03-09 15:52:38 +00:00
|
|
|
set -l data
|
2016-11-28 05:27:22 +00:00
|
|
|
if type -q pbpaste
|
2017-03-09 15:52:38 +00:00
|
|
|
set data (pbpaste)
|
2016-05-24 11:17:03 +00:00
|
|
|
else if type -q xsel
|
2017-03-09 15:52:38 +00:00
|
|
|
# Return if `xsel` failed.
|
2016-11-28 09:09:58 +00: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-10 20:26:51 +00:00
|
|
|
# Also require non-empty contents to not clear the buffer.
|
2017-03-09 15:52:38 +00:00
|
|
|
if not set data (xsel --clipboard)
|
|
|
|
return 1
|
2016-11-28 09:09:58 +00:00
|
|
|
end
|
2016-05-24 11:17:03 +00:00
|
|
|
end
|
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
|
|
|
|
set data (string replace -ra "(['\\\])" '\\\\\\\$1' -- $data)
|
|
|
|
end
|
|
|
|
if test -n "$data"
|
|
|
|
commandline -i -- "$data"
|
|
|
|
end
|
2016-05-24 11:17:03 +00:00
|
|
|
end
|