mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-11-26 17:28:46 -05:00
51 lines
1.4 KiB
Plaintext
51 lines
1.4 KiB
Plaintext
|
#!/usr/bin/env sh
|
||
|
|
||
|
# Description: Copy selection to system clipboard as newline-separated entries
|
||
|
# Dependencies:
|
||
|
# - tr
|
||
|
# - xclip/xsel (Linux)
|
||
|
# - pbcopy (macOS)
|
||
|
# - termux-clipboard-set (Termux)
|
||
|
# - clip.exe (WSL)
|
||
|
# - clip (Cygwin)
|
||
|
# - wl-copy (Wayland)
|
||
|
# - clipboard (Haiku)
|
||
|
#
|
||
|
# 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
|
||
|
|
||
|
selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
|
||
|
|
||
|
if which xsel >/dev/null 2>&1; then
|
||
|
# Linux
|
||
|
tr '\0' '\n' < "$selection" | xsel -bi
|
||
|
elif which xclip >/dev/null 2>&1; then
|
||
|
# Linux
|
||
|
tr '\0' '\n' < "$selection" | xclip -sel clip
|
||
|
elif which pbcopy >/dev/null 2>&1; then
|
||
|
# macOS
|
||
|
tr '\0' '\n' < "$selection" | pbcopy
|
||
|
elif which termux-clipboard-set >/dev/null 2>&1; then
|
||
|
# Termux
|
||
|
tr '\0' '\n' < "$selection" | termux-clipboard-set
|
||
|
elif which clip.exe >/dev/null 2>&1; then
|
||
|
# WSL
|
||
|
tr '\0' '\n' < "$selection" | clip.exe
|
||
|
elif which clip >/dev/null 2>&1; then
|
||
|
# Cygwin
|
||
|
tr '\0' '\n' < "$selection" | clip
|
||
|
elif which wl-copy >/dev/null 2>&1; then
|
||
|
# Wayland
|
||
|
tr '\0' '\n' < "$selection" | wl-copy
|
||
|
elif which clipboard >/dev/null 2>&1; then
|
||
|
# Haiku
|
||
|
tr '\0' '\n' < "$selection" | clipboard --stdin
|
||
|
fi
|