.cbcp (1479B)
1 #!/usr/bin/env sh 2 3 # Description: Copy selection to system clipboard as newline-separated entries 4 # Dependencies: 5 # - tr 6 # - xclip/xsel (Linux) 7 # - pbcopy (macOS) 8 # - termux-clipboard-set (Termux) 9 # - clip.exe (WSL) 10 # - clip (Cygwin) 11 # - wl-copy (Wayland) 12 # - clipboard (Haiku) 13 # 14 # Limitation: breaks if a filename has newline in it 15 # 16 # Note: For a space-separated list: 17 # xargs -0 < "$SELECTION" 18 # 19 # Shell: POSIX compliant 20 # Author: Arun Prakash Jana 21 22 IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n 23 24 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} 25 [ -s "$selection" ] || { echo "plugin .cbcp error: empty selection" >&2 ; exit 1; } 26 27 if [ "$XDG_SESSION_TYPE" = "wayland" ]; then 28 # Wayland 29 tr '\0' '\n' < "$selection" | wl-copy 30 elif type xsel >/dev/null 2>&1; then 31 # Linux 32 tr '\0' '\n' < "$selection" | xsel -bi 33 elif type xclip >/dev/null 2>&1; then 34 # Linux 35 tr '\0' '\n' < "$selection" | xclip -sel clip 36 elif type pbcopy >/dev/null 2>&1; then 37 # macOS 38 tr '\0' '\n' < "$selection" | pbcopy 39 elif type termux-clipboard-set >/dev/null 2>&1; then 40 # Termux 41 tr '\0' '\n' < "$selection" | termux-clipboard-set 42 elif type clip.exe >/dev/null 2>&1; then 43 # WSL 44 tr '\0' '\n' < "$selection" | clip.exe 45 elif type clip >/dev/null 2>&1; then 46 # Cygwin 47 tr '\0' '\n' < "$selection" | clip 48 elif type clipboard >/dev/null 2>&1; then 49 # Haiku 50 tr '\0' '\n' < "$selection" | clipboard --stdin 51 fi