New snippy features !
* copy script content when selection is selected by CTRL+Return * icons ! Icon name is set from first dir name
This commit is contained in:
parent
4439676c5a
commit
8613b99c4e
37
snippy
37
snippy
@ -12,13 +12,20 @@
|
||||
# . ##richsnippet header in snippet to use paste buffer in rich mode (To copy html content in gui)
|
||||
# . execute command begining by $
|
||||
# . execute bash script in $snippets_directory/scripts
|
||||
# . copy script content when selection is selected by CTRL+Return
|
||||
# . icons ! Icon name is set from first dir name. If you have the following snippets, the terminal icon will be displayed in rofi
|
||||
# terminal/
|
||||
# ├── other
|
||||
# │ └── date
|
||||
# └── script
|
||||
# └── test
|
||||
#
|
||||
# augmented by "opennomad": https://gist.github.com/opennomad/15c4d624dce99066a82d
|
||||
# originally written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2
|
||||
# Based on "snippy" by "sessy"
|
||||
# (https://bbs.archlinux.org/viewtopic.php?id=71938)
|
||||
#
|
||||
# You will also need "dmenu", "zenity", "xsel", "sponge" and "xdotool". Get them from your linux
|
||||
# You will also need "rofi", "xsel", "xclip", "sponge" and "xdotool". Get them from your linux
|
||||
# distro in the usual way.
|
||||
#
|
||||
# To use:
|
||||
@ -31,6 +38,8 @@
|
||||
# TIP: If you have a lot of snippets, you can organise them into
|
||||
# subdirectories under ~/.snippy.
|
||||
#
|
||||
# TIP: The name of the subdirectory will be passed to rofi as an icon name
|
||||
#
|
||||
# TIP: The contents of the file will be pasted asis, so if you
|
||||
# don't want a newline at the end when the text is pasted, don't
|
||||
# put one in the file.
|
||||
@ -40,22 +49,25 @@
|
||||
# TIP: If you're using XMonad, add something like this to xmonad.hs
|
||||
# ((mod4Mask, xK_s), spawn "/path/to/snippy")
|
||||
#
|
||||
set -o errexit -o pipefail -o nounset
|
||||
|
||||
readonly snippets_directory=${HOME}/.snippy
|
||||
readonly MENU_ENGINE="rofi"
|
||||
readonly DMENU_ARGS='-dmenu -i -sort'
|
||||
readonly DMENU_ARGS=(-dmenu -i -sort -async-pre-read 20 -theme-str 'element-icon { size: 2.35ch;}' -kb-accept-custom "" -kb-custom-1 "Ctrl+Return")
|
||||
|
||||
# if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v"
|
||||
readonly GUIPASTE="xdotool key ctrl+v"
|
||||
readonly CLIPASTE="xdotool key ctrl+shift+v"
|
||||
|
||||
readonly MENU_ARGS=${DMENU_ARGS}
|
||||
# Placeholders
|
||||
readonly cursor_placeholder="{cursor}"
|
||||
readonly clipboard_placeholder="{clipboard}"
|
||||
|
||||
readonly tmpfile=$(mktemp)
|
||||
trap 'rm -f $tmpfile' EXIT HUP INT TRAP TERM
|
||||
|
||||
script_content=false
|
||||
|
||||
# smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.)
|
||||
# @link http://github.com/coderofsalvation/bashdown
|
||||
# @dependancies: sed cat
|
||||
@ -133,11 +145,18 @@ run() {
|
||||
# Use the filenames in the snippy directory as menu entries.
|
||||
# Get the menu selection from the user.
|
||||
# shellcheck disable=SC2086
|
||||
set +o errexit
|
||||
|
||||
snippet=$( find -L . -type f \
|
||||
| grep -v '^\.$' \
|
||||
| sed 's!\.\/!!' \
|
||||
| grep -vE '\.git/|\.gitconfig|\.gitkeep' \
|
||||
| ${MENU_ENGINE} ${MENU_ARGS} -p '❯ ')
|
||||
| grep -vE '^\.$|\.git/|\.gitconfig|\.gitkeep|\.gitignore' \
|
||||
| sed -e 's!\.\/!!' -re 's_^([^/]*)/(.*)_&\x0icon\x1f\1_' \
|
||||
| ${MENU_ENGINE} "${DMENU_ARGS[@]}" -p '❯ ')
|
||||
|
||||
if [ $? -eq 10 ]; then
|
||||
script_content=true
|
||||
fi
|
||||
|
||||
set -o errexit
|
||||
|
||||
# just return if nothing was selected
|
||||
[[ -z "${snippet}" ]] && return 1
|
||||
@ -149,6 +168,10 @@ run() {
|
||||
if [ ! -s "${snippets_directory}/${snippet}" ]; then
|
||||
content="$(basename "${snippet}")"
|
||||
|
||||
# Custom selection, copy the script content without parsing
|
||||
elif [ "$script_content" = true ]; then
|
||||
content="$( cat "${snippets_directory}/${snippet}" )"
|
||||
|
||||
# don't parse file with the ##noparse header
|
||||
elif grep -qE "^##noparse" "${snippets_directory}/${snippet}"; then
|
||||
content="$( tail -n +2 "${snippets_directory}/${snippet}" )"
|
||||
|
Loading…
Reference in New Issue
Block a user