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