Add quick-paste-sniplets

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-04-20 12:51:20 -04:00
parent 12409a1616
commit f8f3d97c44
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
2 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1 @@
![](https://memegenerator.net/img/instances/84336359/if-it-compiles-it-must-work.jpg)

56
bin/sniplet Executable file
View file

@ -0,0 +1,56 @@
#!/bin/bash
set -euo pipefail
sniplet_dir="${HOME}/.config/sniplet"
tmpdir=$(mktemp -d)
function cleanup() {
rm -rf ${tmpdir}
}
trap cleanup EXIT
# In case the directory does not exist create it
[ -d "${sniplet_dir}" ] || {
mkdir "${sniplet_dir}"
}
# Find sniplet files
names=$(find "${sniplet_dir}" -type f | sed "s|${sniplet_dir}||" | sort)
# Let the user select one of them
name=$(
zenity \
--list \
--title="Sniplet" \
--width=275 \
--height=400 \
--column=Sniplet \
${names}
)
sniplet="${sniplet_dir}/${name}"
# Check presence of the sniplet
[ -f "${sniplet}" ] || {
zenity --error --text="Sniplet has gone away"
exit 1
}
# Store clipboard away
xsel -b -o >"${tmpdir}/b"
xsel -p -o >"${tmpdir}/p"
# Render the sniplet using korvike for templating
korvike -i "${sniplet}" -o "${tmpdir}/s"
# Set clipboard with sniplet
xsel -b -i <"${tmpdir}/s"
xsel -p -i <"${tmpdir}/s"
# Do the paste magic
sleep 0.3
xdotool key shift+Insert
sleep 0.5
# Restore clipboard
xsel -b -i <"${tmpdir}/b"
xsel -p -i <"${tmpdir}/p"