sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

x2sel (1404B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Copy system clipboard newline-separated file list to selection
      4 #
      5 # Dependencies:
      6 #   - tr
      7 #   - xclip/xsel (Linux)
      8 #   - pbpaste (macOS)
      9 #   - termux-clipboard-get (Termux)
     10 #   - powershell (WSL)
     11 #   - cygwim's /dev/clipboard (Cygwin)
     12 #   - wl-paste (Wayland)
     13 #   - clipboard (Haiku)
     14 #
     15 # Note:
     16 #   - Limitation: breaks if a filename has newline in it
     17 #
     18 # Shell: POSIX compliant
     19 # Author: Léo Villeveygoux, after Arun Prakash Jana's .cbcp
     20 
     21 IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}" # protect trailing \n
     22 
     23 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
     24 
     25 getclip () {
     26 	if type xsel >/dev/null 2>&1; then
     27 		# Linux
     28 		xsel -bo
     29 	elif type xclip >/dev/null 2>&1; then
     30 		# Linux
     31 		xclip -sel clip -o
     32 	elif type pbpaste >/dev/null 2>&1; then
     33 		# macOS
     34 		pbpaste
     35 	elif type termux-clipboard-get >/dev/null 2>&1; then
     36 		# Termux
     37 		termux-clipboard-get
     38 	elif type powershell.exe >/dev/null 2>&1; then
     39 		# WSL
     40 		powershell.exe Get-Clipboard
     41 	elif [ -r /dev/clipboard ] ; then
     42 		# Cygwin
     43 		cat /dev/clipboard
     44 	elif type wl-paste >/dev/null 2>&1; then
     45 		# Wayland
     46 		wl-paste
     47 	elif type clipboard >/dev/null 2>&1; then
     48 		# Haiku
     49 		clipboard --print
     50 	fi
     51 }
     52 
     53 CLIPBOARD=$(getclip)
     54 
     55 # Check if clipboard actually contains a file list
     56 for file in $CLIPBOARD ; do
     57 	if [ ! -e "$file" ] ; then
     58 		exit 1;
     59 	fi
     60 done
     61 
     62 printf "%s" "$CLIPBOARD" | tr '\n' '\0' > "$selection"