scripts

scripts
git clone git://git.wimdupont.com/scripts.git
Log | Files | Refs | README | LICENSE

pclip (1033B)


      1 #!/bin/bash
      2 
      3 source ~/.config/scripts/properties
      4 
      5 shopt -s nullglob globstar
      6 
      7 shift $((OPTIND-1))
      8 
      9 if [[ -n $WAYLAND_DISPLAY ]]; then
     10 	dmenu=dmenu-wl
     11 	xdotool="ydotool type --file -"
     12 elif [[ -n $DISPLAY ]]; then
     13 	dmenu=dmenu
     14 	xdotool="xdotool type --clearmodifiers --file -"
     15 else
     16 	echo "Error: No Wayland or X11 display detected" >&2
     17 	exit 1
     18 fi
     19 
     20 primary=$(xclip -selection primary -o)
     21 secondary=$(xclip -selection secondary -o)
     22 clipboard=$(xclip -selection clipboard -o)
     23 
     24 clipboards=()
     25 clipboards[0]=$(echo -n "Primary: ${primary}" | tr -d '\n')
     26 clipboards[1]=$(echo -n "Secondary: ${secondary}" | tr -d '\n')
     27 clipboards[2]=$(echo -n "Clipboard: ${clipboard}" | tr -d '\n')
     28 
     29 selected=$(printf '%s\n' "${clipboards[@]}" | "$dmenu" -fn "$dmenu_font" -i -l 10 "$@" )
     30 
     31 [[ -n "${selected}" ]] || exit
     32 
     33 case "${selected}" in
     34 	Primary*)
     35 		echo -n "${primary}" | $xdotool
     36 		;;
     37 	Secondary*)
     38 		echo -n "${secondary}" | $xdotool
     39 		;;
     40 	Clipboard*)
     41 		echo -n "${clipboard}" | $xdotool
     42 		;;
     43 	*)
     44 		echo -n "Unknown selection" | $xdotool
     45 		;;
     46 esac
     47