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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecbc8c54241157725b6bc023b6ae061efb7cea7e107589ecbac0ddbae684c771
4
- data.tar.gz: 44ca5362a8223dd32d175ed546734e1cfae050aeba9979727834013c80ddc8de
3
+ metadata.gz: f1f233a227990e104c69822136bf5ea926a0a7c04eba1d738f98264db47fc904
4
+ data.tar.gz: 7c637eee8f81ab8ff23da31e71011ed230c62d6cd9b4a63b82f33c90ce3dbef5
5
5
  SHA512:
6
- metadata.gz: f4f1e4fc2032763573c57a9d9f3ce7e3b1abda0a8436d66a5870a389de6bc8253f19bb0c9f1d1a3b5ef1530a34e50e836a52d16966863049a13cfac71afc1ff7
7
- data.tar.gz: a4f1e41a4bb8857b71e46f3825b666507aa485714f3eff66e4bc020448d804ceace6f5ab938dacade05a8c2b6b92e667facc75b6fac3e23e1bb650bec4a4092e
6
+ metadata.gz: ecd7514e9028c93d8ea5abce5a974684d67d7dc262ccdc7f4a8cba57731d80a658548bc34925c2972c3825fdc32d8fae87fcb649bf8e64944dbc6809712e606c
7
+ data.tar.gz: a5aca5fa814e6054d1968ea9282a20b5ec0cde7a9a8bac2d01fb54b1efeb3abd531df79f28192612a114638f44eb11ce1c846916e356de31532dedb92f63697e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 2.0.40
2
+
3
+ 2025-01-18 08:05
4
+
5
+ #### IMPROVED
6
+
7
+ - Concatenate all search type results instead of stopping after first result
8
+ - Comment out empty blockquote lines
9
+
1
10
  ### 2.0.38
2
11
 
3
12
  2024-08-21 08:54
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 containing multiple snippets. If `all` is true, then it will always display every snippet in the selected file. If false, it will offer a menu and let you choose which snippet to display. You can use `--all` on the command line to just enable this once.
105
-
106
- By default, Snibbets displays only the code from each snippet (and optionally block quotes, see below). If you set `all_notes` to true, then the full content of each snippet containing a code block will be returned, allowing you to see additional notes on the command line. This can be toggled at runtime with `--notes` or `--no-notes`.
107
-
108
- The `copy` setting determines whether the output is copied to the clipboard in addition to being displayed on STDOUT. This is the equivalent of running `snibbets QUERY | pbcopy` (macOS) or `snibbets QUERY | xclip` (Linux). This can be enabled for just one run with `--copy` on the command line. Setting it to true in the config will copy to the clipboard every time a snippet is displayed. On Mac this will work automatically, on Windows/Linux you may need to [install `xclip` or `xsel`][xclip].
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 open snippets for editing when using the `--edit` flag. This setting can be any command line utility (`code`, `subl`, `vim`, `nano`, etc.), or on macOS it can be an application name (`BBEdit`, `VS Code`, etc.) or a bundle identifier (`com.sublimetext.4`, `com.microsoft.VSCode`, etc.). If no editor is set, then the file will be opened by whatever the system default is (using `open` on macOS, `start` on Windows, or `xdg-open`on Linux).
113
-
114
- The `include_blockquotes` setting determines whether blockquotes are included in the output. By default, Snibbets removes everything other than code blocks (indented or fenced) from the output it displays. But if you want to include a note that you'll see on the command line, you can put it in a block quote by preceding each line you want to preserve with a right angle bracket (`>`).
115
-
116
- The `interactive` setting determines whether menus will be displayed. This should generally be true, but if you want silent operation that just displays the best match automatically, set it to false.
117
-
118
- The `menus` setting will determine what method is used for displaying interactive menus. If this is not set, it will be automatically determined in the order of `fzf`, `gum`, and `console`. You can manually choose to use one of these options over another by making it the `menus` setting.
119
-
120
- The `name_only` key will permanently set Snibbets to only search for snippets by their filename rather than examining their contents. You can enable this at runtime using `--name-only` in the command.
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 requires that either `pygmentize` or `skylighting` is available on your system (both available via package managers like Homebrew). This feature is still in development and results may be mixed. You can also set `highlighter` to `pygments` or `skylight` to force using one highlighter over the other.
125
-
126
- Highlighting using Skylighting requires that your snippets be named with extra extensions defining the lexer to use. The last extension before `.md` (or whatever your snippet extension is set to) should be the one that the highlighter will recognize as a valid lexer, e.g. `my code.jquery.js.md`.
127
-
128
- You can also define languages in your fenced code blocks by putting the lexer name right after the opening fence. When defining multiple snippets in one file that are of different languages, this method will ensure that each one is properly highlighted.
129
-
130
- If you don't use either extensions or fenced code labels with Skylighting, code won't get highlighted.
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`. If you're using Pygments, run `pygmentize -L styles` to see available options. If you're using Skylighting, you can reference any theme in the [KDE repository]. Skylighting themes are included in Snibbets and can be referenced by their filename without `.theme`, or you can install your own themes and reference them with a full path. (I recommend `nord` when using Sylighting.)
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 `--highlight` or `--no-highlight`. Syntax highlighting definitely affects copyable output, so it's automatically disabled when piping/redirecting output. When using `--copy`, the code sent to the clipboard is not highlighted.
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 better-looking themes, and has some lexers that Pygments lacks. However, Pygments has _more_ lexers and a wider array of themes. It also can determine the target syntax automatically better than Skylighting (which requires the syntax to be specified -- it's pulled from the extensions of your snippets), which is why Pygments is the default if it's installed and you don't configure it otherwise.
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.39
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 `snibbets [search query]` will perform the search and output the code blocks, presenting a menu if more than one match is found or the target file contains more than one snippet. Selected contents are output raw to STDOUT.
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 output all of the matches and their code blocks as a JSON string that can be incorporated into other scripts. It's similar to the `-o launchbar` option, but doesn't contain the extra keys required for the LaunchBar action.
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 snippet file in your editor. Configure your default editor in the config file. `snibbets configure` will open that, but if you don't have an editor set, it might have strange results. To edit manually, open `~/.config/snibbets/snibbets.yml` in your text editor of choice.
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 I have a function in my clipboard that just needs quick saving and there are so few moving parts to creating a snippet that it just feels like they could be automated/simplified. That's why I added the `--paste` flag. If you have a code snippet in your clipboard, you can just run `snibbets --paste` (or just `-p`) and you'll get a prompt asking you to describe the snippet (used for filename) and one asking what language(s) are represented.
204
-
205
- You can input the languages as names, e.g. `rust`, `typescript`, or `scala`, or you can just add file extensions that represent the language. If I say `ts` to that prompt, it will generate an extension of `.ts.md` and then add a metadata tag of `typescript` to the file. The code from the clipboard goes into a fenced code block in the document. You can always go add notes to it later, but it's a great way to save snippets as you come across them (or solutions you figure out after a week of banging your head).
206
-
207
- This command requires that a clipboard utility be available. On macOS, you have `pbpaste` by default and don't need to do anything. On Windows and Linux, you'll need to [install either `xclip` or `xsel`][xclip].
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 in your editor with `--edit-new`. This will prompt for a title and languages, create the new file, and open it in your editor (or in nvUltra with the `--nvultra` flag). If you use `--edit-new-titled TITLE`, the new snippet will get a filename from `TITLE` and languages will be determined from any extension added to the title, or prompted for if none are found.
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 `--source` flag, or turn on highlighting or name-only search, you can add the flag `--save` to write those to your config and make them the default options.
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 `.lbaction` file in Finder. The CLI is not required for the LaunchBar action to function.
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 select your Snippets folder.
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
 
@@ -78,7 +78,23 @@ module Snibbets
78
78
  end
79
79
 
80
80
  def rx
81
- ".*#{gsub(/tags?:/, '').gsub(/\s+/, '.*')}.*"
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(/^> *(?=\S)/, '# ')
148
+ code_blocks["block#{counter}"] = Regexp.last_match(0).gsub(/^> */, '# ')
133
149
  "<block#{counter}>\n"
134
150
  end
135
151
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.39'
4
+ VERSION = '2.0.40'
5
5
  end