Automatically paste at cursor, then restore previous clipboard
This commit is contained in:
parent
53873256f4
commit
6a82d574f5
|
@ -1,9 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
# Copy snippet to primary clipboard for middle-click pasting
|
||||
# Paste snippet to mouse location, then restore clipboard
|
||||
|
||||
# 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/')
|
||||
|
||||
cat $(find ./ -type f | sed -E 's/\.\///' | ${HOME}/.local/bin/tofi --prompt-text 'Snippets: ' --height $HEIGHT --config ${HOME}/.dotfiles/tofi/sidebar.toml) | wl-copy -p
|
||||
# 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
|
||||
|
|
Loading…
Reference in New Issue