diff options
| author | 2020-03-14 05:45:56 +0100 | |
|---|---|---|
| committer | 2020-03-14 10:15:56 +0530 | |
| commit | d4b0ffa75e31f58b283d044fdb66e75366fe5b41 (patch) | |
| tree | 2cce34e6bd1c160fa08930f680a40a1c3394d776 | |
| parent | 0ef2b61a170ae691f8e59466aa6b723cdc884d72 (diff) | |
| download | nnn-d4b0ffa75e31f58b283d044fdb66e75366fe5b41.tar.gz | |
Add x2sel plugin (reverse .cbcp) (#494)
This plugin is based on .cbcp and does basically the reverse operation.
It copies system clipboard newline-separated file list to selection.
| -rw-r--r-- | plugins/README.md | 1 | ||||
| -rwxr-xr-x | plugins/x2sel | 57 |
2 files changed, 58 insertions, 0 deletions
diff --git a/plugins/README.md b/plugins/README.md index dc6ec64..2e8aed6 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -68,6 +68,7 @@ Plugins are installed to `${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins`. | upload | Paste text to ix.io, upload binary to file.io | sh | curl, jq, tr | | vidthumb | Show video thumbnails in terminal | sh | [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer),<br>[lsix](https://github.com/hackerb9/lsix) | | wall | Set wallpaper or change colorscheme | sh | nitrogen/pywal | +| x2sel | Copy newline-separated file list from system clipboard to selection | sh | tr, xsel/xclip<br>pbpaste/wl-paste<br>termux-clipboard-get<br>powershell.exe/`/dev/clipboard`| ## Invoking a plugin diff --git a/plugins/x2sel b/plugins/x2sel new file mode 100755 index 0000000..3113773 --- /dev/null +++ b/plugins/x2sel @@ -0,0 +1,57 @@ +#!/usr/bin/env sh + +# Description: Copy system clipboard newline-separated file list to selection +# Requires: tr and +# xclip/xsel (Linux) +# pbpaste (macOS) +# termux-clipboard-get (Termux) +# powershell (WSL) +# cygwim's /dev/clipboard (Cygwin) +# wl-paste (Wayland) +# +# LIMITATION: breaks if a filename has newline in it +# +# Shell: POSIX compliant +# Author: Léo Villeveygoux, after Arun Prakash Jana's .cbcp + +IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n + +SELECTION=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection + +getclip () { + + if which xsel >/dev/null 2>&1; then + # Linux + xsel -bo + elif which xclip >/dev/null 2>&1; then + # Linux + xclip -sel clip -o + elif which pbpaste >/dev/null 2>&1; then + # macOS + pbpaste + elif which termux-clipboard-get >/dev/null 2>&1; then + # Termux + termux-clipboard-get + elif which powershell.exe >/dev/null 2>&1; then + # WSL + powershell.exe Get-Clipboard + elif [ -r /dev/clipboard ] ; then + # Cygwin + cat /dev/clipboard + elif which wl-paste >/dev/null 2>&1; then + # Wayland + wl-paste + fi + +} + +CLIPBOARD=$(getclip) + +# Check if clipboard actually contains a file list +for file in $CLIPBOARD ; do + if [ ! -e "$file" ] ; then + exit 1; + fi +done + +printf "%s" "$CLIPBOARD" | tr '\n' '\0' > "$SELECTION" |