4 ms·
I have a simple custom solution that works well for me. Snippets are just files in a directory. The filename is the snippet name. If the file is executable, it
by felixr 6y ago
I have a simple custom solution that works well for me. Snippets are just files in a directory. The filename is the snippet name. If the file is executable, it uses whatever is returned from running it. You can use zenity [0] to create forms or run rofi/dmenu to select "arguments" in those scripts.
It uses `rofi` and `xdotool`:
#!/bin/bash
SNIPPET_DIR="${HOME}/.config/snipex"
DMENU="rofi -dmenu -b -p Snippet:"
XSEL="/usr/bin/xsel --clipboard --input"
SNIPPET=$(ls -1 "${SNIPPET_DIR}" | ${DMENU})
FILE="${SNIPPET_DIR}/${SNIPPET}"
STRIP_NEWLINE="head -c -1"
if [ -x "${FILE}" ]; then
# snippet is executable -> run it and copy the result
${FILE} | ${STRIP_NEWLINE} | ${XSEL}
elif [ -f "${FILE}" ]; then
# copy the contents of the file
${STRIP_NEWLINE} ${FILE} | ${XSEL}
else
# clean clipboard
echo "" | ${XSEL}
fi
xdotool key --clearmodifiers "Shift+Insert"
edit: and I have an xbindkeys config to run this script when I press Meta+,
[0]: https://help.gnome.org/users/zenity/stable/forms.html.en https://help.gnome.org/users/zenity/stable/forms.html.en