snibbets 2.0.39 → 2.0.40
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +179 -37
- data/lib/snibbets/string.rb +18 -2
- data/lib/snibbets/version.rb +1 -1
- data/lib/snibbets.rb +141 -136
- data/mise.toml +2 -0
- data/src/_README.md +176 -36
- metadata +4 -8
- data/Gemfile.lock +0 -125
- data/lib/snibbets/todo_spec.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1f233a227990e104c69822136bf5ea926a0a7c04eba1d738f98264db47fc904
|
4
|
+
data.tar.gz: 7c637eee8f81ab8ff23da31e71011ed230c62d6cd9b4a63b82f33c90ce3dbef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd7514e9028c93d8ea5abce5a974684d67d7dc262ccdc7f4a8cba57731d80a658548bc34925c2972c3825fdc32d8fae87fcb649bf8e64944dbc6809712e606c
|
7
|
+
data.tar.gz: a5aca5fa814e6054d1968ea9282a20b5ec0cde7a9a8bac2d01fb54b1efeb3abd531df79f28192612a114638f44eb11ce1c846916e356de31532dedb92f63697e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -95,39 +95,117 @@ output: raw
|
|
95
95
|
source: "~/Dropbox/Snippets"
|
96
96
|
```
|
97
97
|
|
98
|
+
###### Configuration Options
|
99
|
+
|
100
|
+
| key | type | default | description |
|
101
|
+
| ------------------- | ------- | ---------- | ------------------------------------ |
|
102
|
+
| source | string | \*required | Path to snippet directory |
|
103
|
+
| all | boolean | false | Always display all snippets |
|
104
|
+
| all_notes | boolean | false | Show full content, including notes |
|
105
|
+
| copy | boolean | false | always copy output to clipboard |
|
106
|
+
| editor | string | $EDITOR | command or app to use with --edit |
|
107
|
+
| extension | string | md | Snippet extension to search |
|
108
|
+
| highlight | boolean | true | Syntax highlight code |
|
109
|
+
| highlight_theme | string | | Highlighter theme to use |
|
110
|
+
| highlighter | string | | Can be skylight or pygments |
|
111
|
+
| include_blockquotes | boolean | false | include blockquotes in output |
|
112
|
+
| interactive | boolean | true | display a menu when multiple options |
|
113
|
+
| launchbar | boolean | false | Output for LaunchBar |
|
114
|
+
| menus | string | fzf | menu utility: fzf, gum, console |
|
115
|
+
| name_only | boolean | false | Always search by filename |
|
116
|
+
| output | string | raw | Output format json, launchbar, raw |
|
117
|
+
|
118
|
+
|
98
119
|
#### Snippet Location
|
99
120
|
|
100
121
|
Set the `source` key to the folder where you keep your Markdown snippets. Optionally adjust the `extension` setting if you use an extension other than `md` (e.g. `markdown` or `txt`).
|
101
122
|
|
102
123
|
#### Other Options
|
103
124
|
|
104
|
-
The `all` setting determines how Snibbets handles files
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
125
|
+
The `all` setting determines how Snibbets handles files
|
126
|
+
containing multiple snippets. If `all` is true, then it will
|
127
|
+
always display every snippet in the selected file. If false,
|
128
|
+
it will offer a menu and let you choose which snippet to
|
129
|
+
display. You can use `--all` on the command line to just
|
130
|
+
enable this once.
|
131
|
+
|
132
|
+
By default, Snibbets displays only the code from each
|
133
|
+
snippet (and optionally block quotes, see below). If you set
|
134
|
+
`all_notes` to true, then the full content of each snippet
|
135
|
+
containing a code block will be returned, allowing you to
|
136
|
+
see additional notes on the command line. This can be
|
137
|
+
toggled at runtime with `--notes` or `--no-notes`.
|
138
|
+
|
139
|
+
The `copy` setting determines whether the output is copied
|
140
|
+
to the clipboard in addition to being displayed on STDOUT.
|
141
|
+
This is the equivalent of running `snibbets QUERY | pbcopy`
|
142
|
+
(macOS) or `snibbets QUERY | xclip` (Linux). This can be
|
143
|
+
enabled for just one run with `--copy` on the command line.
|
144
|
+
Setting it to true in the config will copy to the clipboard
|
145
|
+
every time a snippet is displayed. On Mac this will work
|
146
|
+
automatically, on Windows/Linux you may need to [install
|
147
|
+
`xclip` or `xsel`][xclip].
|
109
148
|
|
110
149
|
[xclip]: https://ostechnix.com/access-clipboard-contents-using-xclip-and-xsel-in-linux/
|
111
150
|
|
112
|
-
The `editor` setting is used to open the config file, and to
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
151
|
+
The `editor` setting is used to open the config file, and to
|
152
|
+
open snippets for editing when using the `--edit` flag. This
|
153
|
+
setting can be any command line utility (`code`, `subl`,
|
154
|
+
`vim`, `nano`, etc.), or on macOS it can be an application
|
155
|
+
name (`BBEdit`, `VS Code`, etc.) or a bundle identifier
|
156
|
+
(`com.sublimetext.4`, `com.microsoft.VSCode`, etc.). If no
|
157
|
+
editor is set, then the file will be opened by whatever the
|
158
|
+
system default is (using `open` on macOS, `start` on
|
159
|
+
Windows, or `xdg-open`on Linux).
|
160
|
+
|
161
|
+
The `include_blockquotes` setting determines whether
|
162
|
+
blockquotes are included in the output. By default, Snibbets
|
163
|
+
removes everything other than code blocks (indented or
|
164
|
+
fenced) from the output it displays. But if you want to
|
165
|
+
include a note that you'll see on the command line, you can
|
166
|
+
put it in a block quote by preceding each line you want to
|
167
|
+
preserve with a right angle bracket (`>`).
|
168
|
+
|
169
|
+
The `interactive` setting determines whether menus will be
|
170
|
+
displayed. This should generally be true, but if you want
|
171
|
+
silent operation that just displays the best match
|
172
|
+
automatically, set it to false.
|
173
|
+
|
174
|
+
The `menus` setting will determine what method is used for
|
175
|
+
displaying interactive menus. If this is not set, it will be
|
176
|
+
automatically determined in the order of `fzf`, `gum`, and
|
177
|
+
`console`. You can manually choose to use one of these
|
178
|
+
options over another by making it the `menus` setting.
|
179
|
+
|
180
|
+
The `name_only` key will permanently set Snibbets to only
|
181
|
+
search for snippets by their filename rather than examining
|
182
|
+
their contents. You can enable this at runtime using
|
183
|
+
`--name-only` in the command.
|
121
184
|
|
122
185
|
#### Syntax Highlighting
|
123
186
|
|
124
|
-
The `highlight` key turns on syntax highlighting. This
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
187
|
+
The `highlight` key turns on syntax highlighting. This
|
188
|
+
requires that either `pygmentize` or `skylighting` is
|
189
|
+
available on your system (both available via package
|
190
|
+
managers like Homebrew). This feature is still in
|
191
|
+
development and results may be mixed. You can also set
|
192
|
+
`highlighter` to `pygments` or `skylight` to force using one
|
193
|
+
highlighter over the other.
|
194
|
+
|
195
|
+
Highlighting using Skylighting requires that your snippets
|
196
|
+
be named with extra extensions defining the lexer to use.
|
197
|
+
The last extension before `.md` (or whatever your snippet
|
198
|
+
extension is set to) should be the one that the highlighter
|
199
|
+
will recognize as a valid lexer, e.g. `my code.jquery.js.md`.
|
200
|
+
|
201
|
+
You can also define languages in your fenced code blocks by
|
202
|
+
putting the lexer name right after the opening fence. When
|
203
|
+
defining multiple snippets in one file that are of different
|
204
|
+
languages, this method will ensure that each one is properly
|
205
|
+
highlighted.
|
206
|
+
|
207
|
+
If you don't use either extensions or fenced code labels
|
208
|
+
with Skylighting, code won't get highlighted.
|
131
209
|
|
132
210
|
To define a snippet as python code, for example:
|
133
211
|
|
@@ -140,15 +218,33 @@ To define a snippet as python code, for example:
|
|
140
218
|
f = open(filename, 'w')
|
141
219
|
```
|
142
220
|
|
143
|
-
You can also define a color scheme with `highlight_theme`.
|
221
|
+
You can also define a color scheme with `highlight_theme`.
|
222
|
+
If you're using Pygments, run `pygmentize -L styles` to see
|
223
|
+
available options. If you're using Skylighting, you can
|
224
|
+
reference any theme in the [KDE repository]. Skylighting
|
225
|
+
themes are included in Snibbets and can be referenced by
|
226
|
+
their filename without `.theme`, or you can install your own
|
227
|
+
themes and reference them with a full path. (I recommend
|
228
|
+
`nord` when using Sylighting.)
|
144
229
|
|
145
230
|
[KDE repository]: https://github.com/KDE/syntax-highlighting/tree/master/data/themes
|
146
231
|
|
147
|
-
You can turn highlighting on or off for a single run using
|
232
|
+
You can turn highlighting on or off for a single run using
|
233
|
+
`--highlight` or `--no-highlight`. Syntax highlighting
|
234
|
+
definitely affects copyable output, so it's automatically
|
235
|
+
disabled when piping/redirecting output. When using
|
236
|
+
`--copy`, the code sent to the clipboard is not highlighted.
|
148
237
|
|
149
238
|
##### Installing a Syntax Highlighter
|
150
239
|
|
151
|
-
Snibbet's implementation of Skylighting has limited but
|
240
|
+
Snibbet's implementation of Skylighting has limited but
|
241
|
+
better-looking themes, and has some lexers that Pygments
|
242
|
+
lacks. However, Pygments has _more_ lexers and a wider array
|
243
|
+
of themes. It also can determine the target syntax
|
244
|
+
automatically better than Skylighting (which requires the
|
245
|
+
syntax to be specified -- it's pulled from the extensions of
|
246
|
+
your snippets), which is why Pygments is the default if it's
|
247
|
+
installed and you don't configure it otherwise.
|
152
248
|
|
153
249
|
- Install [Skylighting] with [Homebrew] (`brew install skylighting`) or [apt-get].
|
154
250
|
- Install [Pygments] using [Homebrew] (`brew install pygments`) or `pip install pygments`.
|
@@ -160,7 +256,7 @@ Snibbet's implementation of Skylighting has limited but better-looking themes, a
|
|
160
256
|
### Usage
|
161
257
|
|
162
258
|
```
|
163
|
-
Snibbets v2.0.
|
259
|
+
Snibbets v2.0.40
|
164
260
|
|
165
261
|
Usage: snibbets [options] query
|
166
262
|
-a, --all If a file contains multiple snippets, output all of them (no menu)
|
@@ -184,37 +280,80 @@ Usage: snibbets [options] query
|
|
184
280
|
--changes Display the changelog (release notes)
|
185
281
|
```
|
186
282
|
|
187
|
-
If your Snippets folder is set in the config, simply running
|
283
|
+
If your Snippets folder is set in the config, simply running
|
284
|
+
`snibbets [search query]` will perform the search and output
|
285
|
+
the code blocks, presenting a menu if more than one match is
|
286
|
+
found or the target file contains more than one snippet.
|
287
|
+
Selected contents are output raw to STDOUT.
|
188
288
|
|
189
289
|
> If you have fzf or gum installed, snibbets will use those for menus, providing fuzzy filtering of options.
|
190
290
|
|
191
291
|
#### JSON output
|
192
292
|
|
193
|
-
An undocumented output option is `-o json`, which will
|
293
|
+
An undocumented output option is `-o json`, which will
|
294
|
+
output all of the matches and their code blocks as a JSON
|
295
|
+
string that can be incorporated into other scripts. It's
|
296
|
+
similar to the `-o launchbar` option, but doesn't contain
|
297
|
+
the extra keys required for the LaunchBar action.
|
194
298
|
|
195
299
|
#### Open snippets in your editor
|
196
300
|
|
197
|
-
Use the `--edit` flag on any search to open the found
|
301
|
+
Use the `--edit` flag on any search to open the found
|
302
|
+
snippet file in your editor. Configure your default editor
|
303
|
+
in the config file. `snibbets configure` will open that, but
|
304
|
+
if you don't have an editor set, it might have strange
|
305
|
+
results. To edit manually, open
|
306
|
+
`~/.config/snibbets/snibbets.yml` in your text editor of
|
307
|
+
choice.
|
198
308
|
|
199
309
|
#### Creating new snippets
|
200
310
|
|
201
311
|
##### From clipboard
|
202
312
|
|
203
|
-
I do most of my snippet editing in [nvUltra], but sometimes
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
313
|
+
I do most of my snippet editing in [nvUltra], but sometimes
|
314
|
+
I have a function in my clipboard that just needs quick
|
315
|
+
saving and there are so few moving parts to creating a
|
316
|
+
snippet that it just feels like they could be
|
317
|
+
automated/simplified. That's why I added the `--paste` flag.
|
318
|
+
If you have a code snippet in your clipboard, you can just
|
319
|
+
run `snibbets --paste` (or just `-p`) and you'll get a
|
320
|
+
prompt asking you to describe the snippet (used for
|
321
|
+
filename) and one asking what language(s) are represented.
|
322
|
+
|
323
|
+
You can input the languages as names, e.g. `rust`,
|
324
|
+
`typescript`, or `scala`, or you can just add file
|
325
|
+
extensions that represent the language. If I say `ts` to
|
326
|
+
that prompt, it will generate an extension of `.ts.md` and
|
327
|
+
then add a metadata tag of `typescript` to the file. The
|
328
|
+
code from the clipboard goes into a fenced code block in the
|
329
|
+
document. You can always go add notes to it later, but it's
|
330
|
+
a great way to save snippets as you come across them (or
|
331
|
+
solutions you figure out after a week of banging your head).
|
332
|
+
|
333
|
+
This command requires that a clipboard utility be available.
|
334
|
+
On macOS, you have `pbpaste` by default and don't need to do
|
335
|
+
anything. On Windows and Linux, you'll need to
|
336
|
+
[install either `xclip` or `xsel`][xclip].
|
208
337
|
|
209
338
|
[nvUltra]: https://nvultra.com "nvUltra for Mac"
|
210
339
|
|
211
340
|
##### With editor
|
212
341
|
|
213
|
-
You can also create new snippets by opening a skeleton file
|
342
|
+
You can also create new snippets by opening a skeleton file
|
343
|
+
in your editor with `--edit-new`. This will prompt for a
|
344
|
+
title and languages, create the new file, and open it in
|
345
|
+
your editor (or in nvUltra with the `--nvultra` flag). If
|
346
|
+
you use `--edit-new-titled TITLE`, the new snippet will get
|
347
|
+
a filename from `TITLE` and languages will be determined
|
348
|
+
from any extension added to the title, or prompted for if
|
349
|
+
none are found.
|
214
350
|
|
215
351
|
#### Saving Settings When Running
|
216
352
|
|
217
|
-
Any time you specify things like a source folder with the
|
353
|
+
Any time you specify things like a source folder with the
|
354
|
+
`--source` flag, or turn on highlighting or name-only
|
355
|
+
search, you can add the flag `--save` to write those to your
|
356
|
+
config and make them the default options.
|
218
357
|
|
219
358
|
## LaunchBar Action
|
220
359
|
|
@@ -222,9 +361,12 @@ _I'm currently reworking the LaunchBar action, and it doesn't function very well
|
|
222
361
|
|
223
362
|
<!-- ### Installation
|
224
363
|
|
225
|
-
The LaunchBar action can be installed simply by double clicking the
|
364
|
+
The LaunchBar action can be installed simply by double clicking the
|
365
|
+
`.lbaction` file in Finder. The CLI is not required for the LaunchBar
|
366
|
+
action to function.
|
226
367
|
|
227
|
-
Once installed, run the action (type `snib` and hit return on the result) to
|
368
|
+
Once installed, run the action (type `snib` and hit return on the result) to
|
369
|
+
select your Snippets folder.
|
228
370
|
|
229
371
|
### Usage
|
230
372
|
|
data/lib/snibbets/string.rb
CHANGED
@@ -78,7 +78,23 @@ module Snibbets
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def rx
|
81
|
-
".*#{gsub(/tags
|
81
|
+
".*#{gsub(/tags?:\S+/, '').gsub(/\s+/, '.*')}.*"
|
82
|
+
end
|
83
|
+
|
84
|
+
def tags
|
85
|
+
scan(/tags?:(\S+)/).flatten.map { |tag| tag.split(/,/) }.flatten
|
86
|
+
end
|
87
|
+
|
88
|
+
def content_tags
|
89
|
+
tags_line = match(/tags:(.*)/)
|
90
|
+
return [] if tags_line.nil?
|
91
|
+
|
92
|
+
tags_line[1].split(/[, ]+/).map(&:strip).delete_if(&:empty?)
|
93
|
+
end
|
94
|
+
|
95
|
+
def match_all_tags(search_tags)
|
96
|
+
search_tags = search_tags.tags if search_tags.is_a?(String)
|
97
|
+
search_tags.all? { |tag| content_tags.include?(tag) }
|
82
98
|
end
|
83
99
|
|
84
100
|
# remove outside comments, fences, and indentation
|
@@ -129,7 +145,7 @@ module Snibbets
|
|
129
145
|
if Snibbets.options[:include_blockquotes]
|
130
146
|
sans_blocks = sans_blocks.gsub(/(?mi)(^(>.*?)(\n|$))+/) do
|
131
147
|
counter += 1
|
132
|
-
code_blocks["block#{counter}"] = Regexp.last_match(0).gsub(/^>
|
148
|
+
code_blocks["block#{counter}"] = Regexp.last_match(0).gsub(/^> */, '# ')
|
133
149
|
"<block#{counter}>\n"
|
134
150
|
end
|
135
151
|
end
|
data/lib/snibbets/version.rb
CHANGED