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.
|
2018-04-25 21:10:58 +00:00
|
|
|
# That way 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.
|
2018-04-25 21:10:58 +00:00
|
|
|
if not set data (xsel --clipboard 2>/dev/null)
|
2017-03-09 15:52:38 +00:00
|
|
|
return 1
|
2016-11-28 09:09:58 +00:00
|
|
|
end
|
2018-06-02 20:53:02 +00:00
|
|
|
else if type -q xclip
|
|
|
|
if not set data (xclip -selection clipboard -o 2>/dev/null)
|
|
|
|
return 1
|
|
|
|
end
|
2016-05-24 11:17:03 +00:00
|
|
|
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
|
|
|
|
set data (string replace -ra "(['\\\])" '\\\\\\\$1' -- $data)
|
|
|
|
end
|
|
|
|
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
|