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
|
2022-10-12 02:19:21 +08:00
|
|
|
set data (pbpaste 2>/dev/null | string collect -N)
|
2019-11-05 03:47:58 +08:00
|
|
|
else if set -q WAYLAND_DISPLAY; and type -q wl-paste
|
2022-10-12 02:19:21 +08:00
|
|
|
set data (wl-paste -n 2>/dev/null | string collect -N)
|
2021-07-24 02:50:04 +08:00
|
|
|
else if set -q DISPLAY; and type -q xsel
|
2022-10-12 02:19:21 +08:00
|
|
|
set data (xsel --clipboard | string collect -N)
|
2021-07-24 02:50:04 +08:00
|
|
|
else if set -q DISPLAY; and type -q xclip
|
2022-10-12 02:19:21 +08:00
|
|
|
set data (xclip -selection clipboard -o 2>/dev/null | string collect -N)
|
2020-11-06 20:11:56 +08:00
|
|
|
else if type -q powershell.exe
|
2022-10-12 02:19:21 +08:00
|
|
|
set data (powershell.exe Get-Clipboard | string trim -r -c \r | string collect -N)
|
2019-11-05 03:47:58 +08:00
|
|
|
end
|
2019-10-28 01:31:35 +08:00
|
|
|
|
|
|
|
# Issue 6254: Handle zero-length clipboard content
|
2022-10-12 02:19:21 +08:00
|
|
|
if not string length -q -- "$data"
|
2019-10-28 01:31:35 +08:00
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
2022-10-12 02:19:21 +08:00
|
|
|
if not isatty stdout
|
|
|
|
# If we're redirected, just write the data *as-is*.
|
|
|
|
printf %s $data
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2024-03-30 23:10:12 +08:00
|
|
|
__fish_paste $data
|
2016-05-24 19:17:03 +08:00
|
|
|
end
|