1
1
mirror of https://github.com/jarun/nnn.git synced 2024-11-05 01:20:18 +03:00
nnn/plugins/.cbcp

51 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env sh
# Description: Copy selection to system clipboard as newline-separated entries
2020-05-06 08:29:57 +03:00
# Dependencies:
# - tr
# - xclip/xsel (Linux)
# - pbcopy (macOS)
# - termux-clipboard-set (Termux)
# - clip.exe (WSL)
# - clip (Cygwin)
# - wl-copy (Wayland)
# - clipboard (Haiku)
#
2020-05-06 08:29:57 +03:00
# Limitation: breaks if a filename has newline in it
#
# Note: For a space-separated list:
# xargs -0 < "$SELECTION"
#
# Shell: POSIX compliant
# Author: Arun Prakash Jana
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
2020-04-24 07:42:24 +03:00
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
if type xsel >/dev/null 2>&1; then
# Linux
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | xsel -bi
elif type xclip >/dev/null 2>&1; then
# Linux
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | xclip -sel clip
elif type pbcopy >/dev/null 2>&1; then
# macOS
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | pbcopy
elif type termux-clipboard-set >/dev/null 2>&1; then
# Termux
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | termux-clipboard-set
elif type clip.exe >/dev/null 2>&1; then
# WSL
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | clip.exe
elif type clip >/dev/null 2>&1; then
# Cygwin
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | clip
elif type wl-copy >/dev/null 2>&1; then
# Wayland
2020-04-24 07:42:24 +03:00
tr '\0' '\n' < "$selection" | wl-copy
elif type clipboard >/dev/null 2>&1; then
# Haiku
tr '\0' '\n' < "$selection" | clipboard --stdin
fi