mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-27 03:13:37 +08:00
99e87dded3
This is to make pasting literals easier. When a user pastes something, we normally take it as-is. The exception is when a single-quote is open, e.g. the current token is foo'bar When something is pasted here, we escape single-quotes (`'`) and backslashes (`\\`), so typing a `'` after it will turn it into a literal token. Fixes #967.
26 lines
932 B
Fish
26 lines
932 B
Fish
function fish_clipboard_paste
|
|
set -l data
|
|
if type -q pbpaste
|
|
set data (pbpaste)
|
|
else if type -q xsel
|
|
# Return if `xsel` failed.
|
|
# 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.
|
|
# Also require non-empty contents to not clear the buffer.
|
|
if not set data (xsel --clipboard)
|
|
return 1
|
|
end
|
|
end
|
|
# 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
|
|
end
|