2020-03-14 04:45:56 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
|
|
|
# Description: Copy system clipboard newline-separated file list to selection
|
2021-05-15 17:32:01 +00:00
|
|
|
#
|
2020-05-06 05:29:57 +00:00
|
|
|
# Dependencies:
|
2021-05-15 17:32:01 +00:00
|
|
|
# - tr
|
|
|
|
# - xclip/xsel (Linux)
|
|
|
|
# - pbpaste (macOS)
|
|
|
|
# - termux-clipboard-get (Termux)
|
|
|
|
# - powershell (WSL)
|
|
|
|
# - cygwim's /dev/clipboard (Cygwin)
|
|
|
|
# - wl-paste (Wayland)
|
|
|
|
# - clipboard (Haiku)
|
2020-03-14 04:45:56 +00:00
|
|
|
#
|
2021-05-15 17:32:01 +00:00
|
|
|
# Note:
|
|
|
|
# - Limitation: breaks if a filename has newline in it
|
2020-03-14 04:45:56 +00:00
|
|
|
#
|
|
|
|
# Shell: POSIX compliant
|
|
|
|
# Author: Léo Villeveygoux, after Arun Prakash Jana's .cbcp
|
|
|
|
|
|
|
|
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
|
|
|
|
|
2020-04-24 04:42:24 +00:00
|
|
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
2020-03-14 04:45:56 +00:00
|
|
|
|
|
|
|
getclip () {
|
2021-05-14 12:03:28 +00:00
|
|
|
if type xsel >/dev/null 2>&1; then
|
2020-03-14 04:45:56 +00:00
|
|
|
# Linux
|
|
|
|
xsel -bo
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type xclip >/dev/null 2>&1; then
|
2020-03-14 04:45:56 +00:00
|
|
|
# Linux
|
|
|
|
xclip -sel clip -o
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type pbpaste >/dev/null 2>&1; then
|
2020-03-14 04:45:56 +00:00
|
|
|
# macOS
|
|
|
|
pbpaste
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type termux-clipboard-get >/dev/null 2>&1; then
|
2020-03-14 04:45:56 +00:00
|
|
|
# Termux
|
|
|
|
termux-clipboard-get
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type powershell.exe >/dev/null 2>&1; then
|
2020-03-14 04:45:56 +00:00
|
|
|
# WSL
|
|
|
|
powershell.exe Get-Clipboard
|
|
|
|
elif [ -r /dev/clipboard ] ; then
|
|
|
|
# Cygwin
|
|
|
|
cat /dev/clipboard
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type wl-paste >/dev/null 2>&1; then
|
2020-03-14 04:45:56 +00:00
|
|
|
# Wayland
|
|
|
|
wl-paste
|
2021-05-14 12:03:28 +00:00
|
|
|
elif type clipboard >/dev/null 2>&1; then
|
2020-08-09 21:44:11 +00:00
|
|
|
# Haiku
|
|
|
|
clipboard --print
|
2020-03-14 04:45:56 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
CLIPBOARD=$(getclip)
|
|
|
|
|
|
|
|
# Check if clipboard actually contains a file list
|
|
|
|
for file in $CLIPBOARD ; do
|
|
|
|
if [ ! -e "$file" ] ; then
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-04-24 04:42:24 +00:00
|
|
|
printf "%s" "$CLIPBOARD" | tr '\n' '\0' > "$selection"
|