Skip to content

Commit 93bb80b

Browse files
authored
Merge pull request #32 from BarbUk/rofi_mode
rofi mode
2 parents 4986018 + b5b88c0 commit 93bb80b

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

README.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,24 @@ terminal/
287287
Usage:
288288
/usr/bin/snippy-snippet [OPTION] ACTION
289289
Snippy snippets manager
290+
291+
Snippet location
292+
~/.config/snippy
293+
290294
Options
291-
-h, --help: Show help
292-
-s, --sort: true or false Sort snippet in rofi (default)
293-
-m, --sorting-method: fzf (default) or levenshtein
295+
-h, --help Show help
296+
-s, --sort true|false Sort snippet in rofi
297+
-m, --sorting-method fzf (default) or levenshtein
298+
294299
Actions
295-
gui Browse snippet and paste it in the focused window (default)
296-
cli list snippet in cli mode, only copy snippet in the paste buffer
297-
edit Browse snippet and edit it
298-
add snippet_name Add a new snippet
299-
list list snippet
300-
cat list category
301-
completion bash completion
300+
gui Browse snippet and paste it in the focused window (default)
301+
cli list snippet in cli mode, only copy snippet in the paste buffer
302+
rofi list snippet in cli mode for rofi input. Accept an argument with the chosen snippet to paste it.
303+
edit Browse snippet and edit it
304+
add <name> Add a new snippet
305+
list list snippet
306+
cat list category
307+
completion bash completion. Use it with: eval "$(snippy completion)"
302308
```
303309

304310
### Examples
@@ -311,6 +317,14 @@ snippy
311317
snippy gui
312318
```
313319

320+
**Use it directly inside rofi:**
321+
322+
If you already have a keybinding for rofi, you can add snippy as a mod:
323+
324+
```bash
325+
rofi -theme-str 'element-icon { size: 3ch;}' -combi-modi 'snippets:snippy rofi' -show combi -modi combi
326+
```
327+
314328
**Browse snippets in terminal:**
315329

316330
```bash

snippy

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ ${bold}Options${normal}
247247
${bold}Actions${normal}
248248
${bold}gui${normal} \t\tBrowse snippet and paste it in the focused window ${underline}(default)${normal}
249249
${bold}cli${normal} \t\tlist snippet in cli mode, only copy snippet in the paste buffer
250+
${bold}rofi${normal} \t\tlist snippet in cli mode for rofi input. Accept an argument with the chosen snippet to paste it.
250251
${bold}edit${normal} \t\tBrowse snippet and edit it
251252
${bold}add${normal} <name> \tAdd a new snippet
252253
${bold}list${normal} \t\tlist snippet
@@ -315,10 +316,15 @@ cli() {
315316

316317
list() {
317318
local type="${1:-f}"
318-
319+
local filter=(cat)
320+
if [[ "$type" == "icon" ]]; then
321+
type='f'
322+
filter=(sed -re 's_^([^/]*)/(.*)_&\x0icon\x1f\1_')
323+
fi
319324
find -L . -type "$type" |
320325
grep -vE '^\.$|\.git|\.gitconfig|\.gitkeep|\.gitignore|\./\.pre-commit-config.yaml' |
321326
sed -e 's!\.\/!!' |
327+
"${filter[@]}" |
322328
sort
323329
}
324330

@@ -359,7 +365,7 @@ _snippy_completion() {
359365
prev="${COMP_WORDS[COMP_CWORD-1]}"
360366
361367
opts="-h --help -v --version -s --sort -m --sorting-method"
362-
actions="gui cli edit add list cat completion"
368+
actions="gui cli edit add list rofi cat completion"
363369
364370
# Complete option values
365371
case "${prev}" in
@@ -393,7 +399,7 @@ gui() {
393399
# shellcheck disable=SC2086
394400
set +o errexit
395401

396-
snippet=$(list | sed -re 's_^([^/]*)/(.*)_&\x0icon\x1f\1_' | rofi "${rofi_args[@]}" -p '')
402+
snippet=$(list 'icon' | rofi "${rofi_args[@]}" -p '')
397403

398404
if [ $? -eq 10 ]; then
399405
script_content=true
@@ -561,7 +567,6 @@ run() {
561567
xsel --clipboard --input <"$tmpfile"
562568
fi
563569
fi
564-
565570
if [ "$paste" = true ]; then
566571
# Paste into the current application.
567572
if is_gui; then
@@ -626,6 +631,15 @@ main() {
626631
cli
627632
run false
628633
;;
634+
'rofi')
635+
shift
636+
if (($# > 0)); then
637+
snippet="$*"
638+
coproc run >/dev/null 2>&1
639+
exit 0
640+
fi
641+
list 'icon'
642+
;;
629643
'list')
630644
list
631645
;;

0 commit comments

Comments
 (0)