Sxhkd global clipboard

I’m running dwm + sxhkd. I ran into some flakiness with qui-clipboard in my setup (my fault I’m sure) so I hacked together a little workaround in my sxhkdrc. Submitted for critique & improvements. The only caveat being I wanted to inline this rather than calling out to an external script, which limits comprehensive error handling.

super + c
        qube=$(xprop -id "$(xdotool getwindowfocus)" _QUBES_VMNAME | cut -f2 -d\" | xargs) && \
        [ "$qube" != "_QUBES_VMNAME:  not found." ] && \
        clip=$(qvm-run --pass-io "$qube" 'xclip -o' | tee /tmp/clipbuffer) && \
        bytes=$(echo "$clip" | wc -c) && \
        notify-send " Copied $bytes bytes from $qube to clipboard"

super + v
        qube=$(xprop -id "$(xdotool getwindowfocus)" _QUBES_VMNAME | cut -f2 -d\" | xargs) && \
        touch /tmp/clipbuffer && \
        clip=$(cat /tmp/clipbuffer) && \
        bytes=$(echo "$clip" | wc -c) && \
        [ "$bytes" -gt 0 ] && \
        qvm-run "$qube" "echo '$clip' | xclip -selection clipboard" && \
        rm -f /tmp/clipbuffer && \
        notify-send "Wrote $bytes bytes to $qube. Clipboard cleared"
1 Like