scripts

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

commit 642ba34e6edb64f4da7e58c033571087b5aa156f
parent 90116d9feb725dfdee1847fbb758c1c97aa6a336
Author: Wim Dupont <wim@wimdupont.com>
Date:   Thu, 16 Mar 2023 12:30:35 +0100

added pclip

Diffstat:
MREADME.adoc | 10++++++++++
Abin/pclip | 49+++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/README.adoc b/README.adoc @@ -96,3 +96,13 @@ The downloaded audio files also get tagged by id3 to make them easy to sort by o * https://github.com/yt-dlp/yt-dlp[yt-dlp] * https://git.ffmpeg.org/ffmpeg.git[ffmpeg] * https://github.com/squell/id3[id3] + +== link:bin/pclip[pclip] + +Used to show all clipboard contents in dmenu and allows you to select one which will be typed out. + +.Requires: + +* https://git.suckless.org/dmenu/[dmenu] +* https://github.com/astrand/xclip[xclip] +* https://github.com/jordansissel/xdotool[xdotool] diff --git a/bin/pclip b/bin/pclip @@ -0,0 +1,49 @@ +#!/bin/bash + +source ~/.config/scripts/properties + +shopt -s nullglob globstar + +font=$DMENU_FONT + +shift $((OPTIND-1)) + +if [[ -n $WAYLAND_DISPLAY ]]; then + dmenu=dmenu-wl + xdotool="ydotool type --file -" +elif [[ -n $DISPLAY ]]; then + dmenu=dmenu + xdotool="xdotool type --clearmodifiers --file -" +else + echo "Error: No Wayland or X11 display detected" >&2 + exit 1 +fi + +primary=$(xclip -selection primary -o) +secondary=$(xclip -selection secondary -o) +clipboard=$(xclip -selection clipboard -o) + +clipboards=() +clipboards[0]=$(echo -n "Primary: ${primary}" | tr -d '\n') +clipboards[1]=$(echo -n "Secondary: ${secondary}" | tr -d '\n') +clipboards[2]=$(echo -n "Clipboard: ${clipboard}" | tr -d '\n') + +selected=$(printf '%s\n' "${clipboards[@]}" | "$dmenu" -fn "$font" -i -l 10 "$@" ) + +[[ -n "${selected}" ]] || exit + +case "${selected}" in + Primary*) + echo "${primary}" | $xdotool + ;; + Secondary*) + echo "${secondary}" | $xdotool + ;; + Clipboard*) + echo "${clipboard}" | $xdotool + ;; + *) + echo "Unknown selection" | $xdotool + ;; +esac +