sistema_progs

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

x2sel (1410B)


      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 [ "$XDG_SESSION_TYPE" = "wayland" ]; then
     27 		# Wayland
     28 		wl-paste
     29 	elif type xsel >/dev/null 2>&1; then
     30 		# Linux
     31 		xsel -bo
     32 	elif type xclip >/dev/null 2>&1; then
     33 		# Linux
     34 		xclip -sel clip -o
     35 	elif type pbpaste >/dev/null 2>&1; then
     36 		# macOS
     37 		pbpaste
     38 	elif type termux-clipboard-get >/dev/null 2>&1; then
     39 		# Termux
     40 		termux-clipboard-get
     41 	elif type powershell.exe >/dev/null 2>&1; then
     42 		# WSL
     43 		powershell.exe Get-Clipboard
     44 	elif [ -r /dev/clipboard ] ; then
     45 		# Cygwin
     46 		cat /dev/clipboard
     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"