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)
|
# . ##richsnippet header in snippet to use paste buffer in rich mode (To copy html content in gui)
|
||||||
# . execute command begining by $
|
# . execute command begining by $
|
||||||
# . execute bash script in $snippets_directory/scripts
|
# . 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
|
# augmented by "opennomad": https://gist.github.com/opennomad/15c4d624dce99066a82d
|
||||||
# originally written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2
|
# originally written by "mhwombat": https://bbs.archlinux.org/viewtopic.php?id=71938&p=2
|
||||||
# Based on "snippy" by "sessy"
|
# Based on "snippy" by "sessy"
|
||||||
# (https://bbs.archlinux.org/viewtopic.php?id=71938)
|
# (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.
|
# distro in the usual way.
|
||||||
#
|
#
|
||||||
# To use:
|
# To use:
|
||||||
@ -31,6 +38,8 @@
|
|||||||
# TIP: If you have a lot of snippets, you can organise them into
|
# TIP: If you have a lot of snippets, you can organise them into
|
||||||
# subdirectories under ~/.snippy.
|
# 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
|
# 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
|
# don't want a newline at the end when the text is pasted, don't
|
||||||
# put one in the file.
|
# put one in the file.
|
||||||
@ -40,22 +49,25 @@
|
|||||||
# TIP: If you're using XMonad, add something like this to xmonad.hs
|
# TIP: If you're using XMonad, add something like this to xmonad.hs
|
||||||
# ((mod4Mask, xK_s), spawn "/path/to/snippy")
|
# ((mod4Mask, xK_s), spawn "/path/to/snippy")
|
||||||
#
|
#
|
||||||
|
set -o errexit -o pipefail -o nounset
|
||||||
|
|
||||||
readonly snippets_directory=${HOME}/.snippy
|
readonly snippets_directory=${HOME}/.snippy
|
||||||
readonly MENU_ENGINE="rofi"
|
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"
|
# if nothing happens, try "xdotool click 2", "xdotool key ctrl+v" or "xdotool key ctrl+shift+v"
|
||||||
readonly GUIPASTE="xdotool key ctrl+v"
|
readonly GUIPASTE="xdotool key ctrl+v"
|
||||||
readonly CLIPASTE="xdotool key ctrl+shift+v"
|
readonly CLIPASTE="xdotool key ctrl+shift+v"
|
||||||
|
|
||||||
readonly MENU_ARGS=${DMENU_ARGS}
|
# Placeholders
|
||||||
readonly cursor_placeholder="{cursor}"
|
readonly cursor_placeholder="{cursor}"
|
||||||
readonly clipboard_placeholder="{clipboard}"
|
readonly clipboard_placeholder="{clipboard}"
|
||||||
|
|
||||||
readonly tmpfile=$(mktemp)
|
readonly tmpfile=$(mktemp)
|
||||||
trap 'rm -f $tmpfile' EXIT HUP INT TRAP TERM
|
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.)
|
# smarty like template engine which executes inline bash in (bashdown) strings (replaces variables with values e.g.)
|
||||||
# @link http://github.com/coderofsalvation/bashdown
|
# @link http://github.com/coderofsalvation/bashdown
|
||||||
# @dependancies: sed cat
|
# @dependancies: sed cat
|
||||||
@ -133,11 +145,18 @@ run() {
|
|||||||
# Use the filenames in the snippy directory as menu entries.
|
# Use the filenames in the snippy directory as menu entries.
|
||||||
# Get the menu selection from the user.
|
# Get the menu selection from the user.
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
|
set +o errexit
|
||||||
|
|
||||||
snippet=$( find -L . -type f \
|
snippet=$( find -L . -type f \
|
||||||
| grep -v '^\.$' \
|
| grep -vE '^\.$|\.git/|\.gitconfig|\.gitkeep|\.gitignore' \
|
||||||
| sed 's!\.\/!!' \
|
| sed -e 's!\.\/!!' -re 's_^([^/]*)/(.*)_&\x0icon\x1f\1_' \
|
||||||
| grep -vE '\.git/|\.gitconfig|\.gitkeep' \
|
| ${MENU_ENGINE} "${DMENU_ARGS[@]}" -p '❯ ')
|
||||||
| ${MENU_ENGINE} ${MENU_ARGS} -p '❯ ')
|
|
||||||
|
if [ $? -eq 10 ]; then
|
||||||
|
script_content=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -o errexit
|
||||||
|
|
||||||
# just return if nothing was selected
|
# just return if nothing was selected
|
||||||
[[ -z "${snippet}" ]] && return 1
|
[[ -z "${snippet}" ]] && return 1
|
||||||
@ -149,6 +168,10 @@ run() {
|
|||||||
if [ ! -s "${snippets_directory}/${snippet}" ]; then
|
if [ ! -s "${snippets_directory}/${snippet}" ]; then
|
||||||
content="$(basename "${snippet}")"
|
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
|
# don't parse file with the ##noparse header
|
||||||
elif grep -qE "^##noparse" "${snippets_directory}/${snippet}"; then
|
elif grep -qE "^##noparse" "${snippets_directory}/${snippet}"; then
|
||||||
content="$( tail -n +2 "${snippets_directory}/${snippet}" )"
|
content="$( tail -n +2 "${snippets_directory}/${snippet}" )"
|
||||||
|
Loading…
Reference in New Issue
Block a user