2023-11-14 21:10:53 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-09-25 00:15:46 +00:00
|
|
|
# Paste snippet to mouse location, then restore clipboard
|
2023-11-14 21:10:53 +00:00
|
|
|
|
|
|
|
# Maintain list of snippets in private repository
|
|
|
|
cd ${HOME}/.private-scripts/snippets
|
|
|
|
|
|
|
|
HEIGHT=$(swaymsg -t get_outputs | tr '\n' ' ' | sed -e 's/ */ /g' | sed -e 's/\(.*"focused": [a-z]*\),/\1\n/' | less | grep '"focused": true' | sed -e 's/.*"rect": {[^}]*"height": \([0-9]*\).*/\1/')
|
|
|
|
|
2024-09-25 00:15:46 +00:00
|
|
|
# Back-up anything already in the clipboard
|
|
|
|
OLD="$(wl-paste -p)"
|
|
|
|
|
|
|
|
# Get input from Tofi
|
|
|
|
INPUT="$(find ./ -type f | sed -E 's/\.\///' | ${HOME}/.local/bin/tofi --prompt-text 'Snippets: ' --height $HEIGHT --config ${HOME}/.dotfiles/tofi/sidebar.toml)"
|
|
|
|
|
|
|
|
# Ignore if returned file does not exist
|
|
|
|
if [ -e "$INPUT" ]; then
|
|
|
|
|
|
|
|
# Copy file contents to clipboard and allow only one paste
|
|
|
|
wl-copy -p "$(cat $INPUT)"
|
|
|
|
|
|
|
|
# Paste at focus cursor
|
|
|
|
YDOTOOL_SOCKET=/tmp/.ydotool_socket ydotool click 0xC2
|
|
|
|
|
|
|
|
# Restored backed-up clipboard
|
|
|
|
echo "$OLD" | wl-copy -p
|
|
|
|
|
|
|
|
fi
|