snibbets 2.0.10 → 2.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md.orig +19 -0
- data/Gemfile.lock +2 -1
- data/lib/snibbets/array.rb +8 -12
- data/lib/snibbets/config.rb +21 -24
- data/lib/snibbets/lexers.rb +34 -24
- data/lib/snibbets/string.rb +3 -3
- data/lib/snibbets/version.rb +1 -1
- data/lib/snibbets/which.rb +2 -2
- data/lib/snibbets.rb +8 -6
- data/snibbets.gemspec +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 730cb0a9e548f9d590fb8eb8088bf279e5848dc7822fd2f7022e0c2c472f31e9
|
4
|
+
data.tar.gz: 544dbd0f8de24623ad0c4c4ef56be8ba77bb7b55a2aa6355c39ceaa51fae9519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25175a8f43be5bf5793e1953d570314f558baaa2b2bdb6e7045f2f4e7ae4e081c86033b87f91d567c6f10c9a4ae9ea5e9ceb45117e4a6848a184a35d2e0bc4e9
|
7
|
+
data.tar.gz: fb643c8813e3fc6183a484395bc1326d44ebc994615d0b07f9cefc06b5099f40fdbc67b289e6108e54970c751e7f1fda603c3c228607862162d628f11bdd0c96
|
data/CHANGELOG.md.orig
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
### 2.0.12
|
2
|
+
|
3
|
+
2023-04-15 19:28
|
4
|
+
|
5
|
+
#### FIXED
|
6
|
+
|
7
|
+
- Lowered minimum ruby version to allow Ruby 2.6
|
8
|
+
- Failure to recognize snippet if title is on first line of file
|
9
|
+
- Errantly discarding first snippet in file with multiple snippets
|
10
|
+
|
11
|
+
### 2.0.11
|
12
|
+
|
13
|
+
2023-04-15 19:06
|
14
|
+
|
15
|
+
#### FIXED
|
16
|
+
|
17
|
+
- Overactive stripping of newlines within code blocks
|
18
|
+
- Syntax definition determination when adding new snippets
|
19
|
+
|
1
20
|
### 2.0.10
|
2
21
|
|
3
22
|
2023-04-15 16:28
|
data/Gemfile.lock
CHANGED
data/lib/snibbets/array.rb
CHANGED
@@ -15,25 +15,21 @@ module Snibbets
|
|
15
15
|
def remove_leading_empty_elements
|
16
16
|
output = []
|
17
17
|
|
18
|
+
in_leader = true
|
18
19
|
each do |line|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
if (line =~ /^\s*$/ || line.empty?) && in_leader
|
21
|
+
next
|
22
|
+
else
|
23
|
+
in_leader = false
|
24
|
+
output << line
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
output
|
25
29
|
end
|
26
30
|
|
27
31
|
def remove_trailing_empty_elements
|
28
|
-
|
29
|
-
|
30
|
-
reverse.each do |line|
|
31
|
-
next if line =~ /^\s*$/ || line.empty?
|
32
|
-
|
33
|
-
output << line
|
34
|
-
end
|
35
|
-
|
36
|
-
output.reverse
|
32
|
+
reverse.remove_leading_empty_elements.reverse
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
data/lib/snibbets/config.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Snibbets
|
4
4
|
class Config
|
5
|
-
attr_accessor :options
|
5
|
+
attr_accessor :options, :test_editor, :config_dir, :config_file
|
6
6
|
|
7
7
|
DEFAULT_OPTIONS = {
|
8
8
|
all: false,
|
@@ -19,61 +19,58 @@ module Snibbets
|
|
19
19
|
}.freeze
|
20
20
|
|
21
21
|
def initialize
|
22
|
+
@config_dir = File.expand_path('~/.config/snibbets')
|
23
|
+
@config_file = File.join(@config_dir, 'snibbets.yml')
|
22
24
|
custom_config = read_config
|
23
25
|
@options = DEFAULT_OPTIONS.merge(custom_config)
|
24
26
|
@options[:editor] ||= best_editor
|
25
27
|
@options[:menus] ||= best_menu
|
28
|
+
@test_editor = nil
|
26
29
|
|
27
30
|
write_config unless @options.equal?(custom_config)
|
28
31
|
end
|
29
32
|
|
30
33
|
def best_menu
|
31
|
-
return 'fzf' if TTY::Which.exist?('fzf')
|
32
|
-
|
34
|
+
return 'fzf' if TTY::Which.exist?('fzf') && @test_editor == 'fzf'
|
35
|
+
|
36
|
+
return 'gum' if TTY::Which.exist?('gum') && @test_editor == 'gum'
|
37
|
+
|
33
38
|
'console'
|
34
39
|
end
|
35
40
|
|
36
41
|
def best_editor
|
37
|
-
if ENV['EDITOR']
|
42
|
+
if ENV['EDITOR'] && @test_editor == 'EDITOR'
|
38
43
|
ENV['EDITOR']
|
39
|
-
elsif ENV['GIT_EDITOR']
|
44
|
+
elsif ENV['GIT_EDITOR'] && @test_editor == 'GIT_EDITOR'
|
40
45
|
ENV['GIT_EDITOR']
|
41
46
|
else
|
42
|
-
return TTY::Which.which('code') if TTY::Which.exist?('code')
|
47
|
+
return TTY::Which.which('code') if TTY::Which.exist?('code') && @test_editor == 'code'
|
43
48
|
|
44
|
-
return TTY::Which.which('subl') if TTY::Which.exist?('subl')
|
49
|
+
return TTY::Which.which('subl') if TTY::Which.exist?('subl') && @test_editor == 'subl'
|
45
50
|
|
46
|
-
return TTY::Which.which('
|
51
|
+
return TTY::Which.which('nano') if TTY::Which.exist?('nano') && @test_editor == 'nano'
|
47
52
|
|
48
|
-
return TTY::Which.which('
|
49
|
-
|
50
|
-
return TTY::Which.which('vim') if TTY::Which.exist?('vim')
|
53
|
+
return TTY::Which.which('vim') if TTY::Which.exist?('vim') && @test_editor == 'vim'
|
51
54
|
|
52
55
|
'TextEdit'
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
|
-
def config_dir
|
57
|
-
File.expand_path('~/.config/snibbets')
|
58
|
-
end
|
59
|
-
|
60
|
-
def config_file
|
61
|
-
File.join(config_dir, 'snibbets.yml')
|
62
|
-
end
|
63
|
-
|
64
59
|
def read_config
|
65
|
-
if File.exist?(config_file)
|
66
|
-
YAML.safe_load(IO.read(config_file)).symbolize_keys
|
60
|
+
if File.exist?(@config_file)
|
61
|
+
YAML.safe_load(IO.read(@config_file)).symbolize_keys
|
67
62
|
else
|
68
63
|
{}
|
69
64
|
end
|
70
65
|
end
|
71
66
|
|
72
67
|
def write_config
|
73
|
-
raise 'Error creating config directory, file exists' if File.exist?(config_dir) && !File.directory?(config_dir)
|
68
|
+
raise 'Error creating config directory, file exists' if File.exist?(@config_dir) && !File.directory?(@config_dir)
|
69
|
+
|
70
|
+
FileUtils.mkdir_p(@config_dir) unless File.directory?(@config_dir)
|
71
|
+
File.open(@config_file, 'w') { |f| f.puts(YAML.dump(@options.stringify_keys)) }
|
74
72
|
|
75
|
-
|
76
|
-
File.open(config_file, 'w') { |f| f.puts(YAML.dump(@options.stringify_keys)) }
|
73
|
+
true
|
77
74
|
end
|
78
75
|
end
|
79
76
|
end
|
data/lib/snibbets/lexers.rb
CHANGED
@@ -1,34 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Snibbets
|
2
|
-
|
3
|
-
|
4
|
+
# Lexer definitions
|
5
|
+
module Lexers
|
6
|
+
class << self
|
7
|
+
def lexers
|
8
|
+
@lexers ||= build_lexers
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_lexers
|
12
|
+
lex = []
|
13
|
+
IO.read('lib/snibbets/lexers_db.txt').split(/\n/).each do |line|
|
14
|
+
key = line.match(/(?mi)^((, )?[^,]+?)+?(?=\[)/)[0]
|
15
|
+
keys = key.split(/,/).map(&:strip)
|
16
|
+
value = line.match(/\[(.*?)\]/)[1]
|
17
|
+
values = value.split(/,/).map(&:strip)
|
4
18
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
19
|
+
lex << {
|
20
|
+
lexer: keys.shift,
|
21
|
+
aliases: keys,
|
22
|
+
extensions: values
|
23
|
+
}
|
24
|
+
end
|
11
25
|
|
12
|
-
|
13
|
-
lexer: keys.shift,
|
14
|
-
aliases: keys,
|
15
|
-
extensions: values
|
16
|
-
}
|
26
|
+
lex
|
17
27
|
end
|
18
|
-
end
|
19
28
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
29
|
+
def ext_to_lang(ext)
|
30
|
+
matches = lexers.select { |lex| lex[:extensions].map(&:downcase).include?(ext.downcase) }
|
31
|
+
matches.map { |lex| lex[:lexer] }.first
|
32
|
+
end
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
def lang_to_ext(lexer)
|
35
|
+
matches = lexers.select { |lex| lex[:lexer] == lexer || lex[:aliases].map(&:downcase).include?(lexer.downcase) }
|
36
|
+
matches.map { |lex| lex[:extensions].first }.first
|
37
|
+
end
|
29
38
|
|
30
|
-
|
31
|
-
|
39
|
+
def syntax_from_extension(filename)
|
40
|
+
ext_to_lang(filename.split(/\./)[1])
|
41
|
+
end
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
data/lib/snibbets/string.rb
CHANGED
@@ -20,8 +20,8 @@ module Snibbets
|
|
20
20
|
input = dup
|
21
21
|
lines = input.split(/\n/)
|
22
22
|
loop do
|
23
|
-
line = lines
|
24
|
-
|
23
|
+
line = lines[0]
|
24
|
+
lines.shift if line =~ /^\s*[A-Z\s]+\w:\s*\S+/i || line =~ /^-{3,}\s*$/
|
25
25
|
|
26
26
|
break
|
27
27
|
end
|
@@ -133,7 +133,7 @@ module Snibbets
|
|
133
133
|
parts = sans_blocks.gsub(/\n{2,}/, "\n\n").split(/^#+/)
|
134
134
|
end
|
135
135
|
|
136
|
-
parts.shift if parts.count > 1
|
136
|
+
# parts.shift if parts.count > 1
|
137
137
|
|
138
138
|
parts.each do |part|
|
139
139
|
lines = part.split(/\n/).strip_empty
|
data/lib/snibbets/version.rb
CHANGED
data/lib/snibbets/which.rb
CHANGED
data/lib/snibbets.rb
CHANGED
@@ -34,6 +34,10 @@ end
|
|
34
34
|
|
35
35
|
module Snibbets
|
36
36
|
class << self
|
37
|
+
def change_query(query)
|
38
|
+
@query = query
|
39
|
+
end
|
40
|
+
|
37
41
|
# Search the snippets directory for query using find and grep
|
38
42
|
def search(try: 0)
|
39
43
|
folder = File.expand_path(Snibbets.options[:source])
|
@@ -139,8 +143,6 @@ module Snibbets
|
|
139
143
|
exit!
|
140
144
|
end
|
141
145
|
|
142
|
-
build_lexers
|
143
|
-
|
144
146
|
pb = OS.paste.outdent
|
145
147
|
|
146
148
|
printf 'What does this snippet do? '
|
@@ -150,10 +152,10 @@ module Snibbets
|
|
150
152
|
printf 'What language(s) does it use (separate with spaces, full names or file extensions will work)? '
|
151
153
|
input = $stdin.gets.chomp
|
152
154
|
langs = input.split(/ +/).map(&:strip) unless input.empty?
|
153
|
-
exts = langs.map { |lang|
|
154
|
-
tags = langs.map { |lang|
|
155
|
+
exts = langs.map { |lang| Lexers.lang_to_ext(lang) }
|
156
|
+
tags = langs.map { |lang| Lexers.ext_to_lang(lang) }.concat(langs).sort.uniq
|
155
157
|
|
156
|
-
filename ="#{title}.#{exts.join('.')}.#{Snibbets.options[:extension]}"
|
158
|
+
filename = "#{title}.#{exts.join('.')}.#{Snibbets.options[:extension]}"
|
157
159
|
|
158
160
|
File.open(File.join(File.expand_path(Snibbets.options[:source]), filename), 'w') do |f|
|
159
161
|
f.puts "tags: #{tags.join(', ')}
|
@@ -272,7 +274,7 @@ module Snibbets
|
|
272
274
|
else
|
273
275
|
snippets.push({ 'title' => 'All snippets', 'code' => '' })
|
274
276
|
|
275
|
-
answer =
|
277
|
+
answer = Menu.menu(snippets, filename: File.basename(filepath, '.md'), title: 'Select snippet', query: @query)
|
276
278
|
|
277
279
|
if answer['title'] == 'All snippets'
|
278
280
|
snippets.delete_if { |s| s['title'] == 'All snippets'}
|
data/snibbets.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = "A plain text code snippet manager"
|
13
13
|
spec.homepage = "https://github.com/ttscoff/snibbets"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">=
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snibbets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -174,22 +174,22 @@ dependencies:
|
|
174
174
|
name: tty-which
|
175
175
|
requirement: !ruby/object:Gem::Requirement
|
176
176
|
requirements:
|
177
|
-
- - "~>"
|
178
|
-
- !ruby/object:Gem::Version
|
179
|
-
version: '0.5'
|
180
177
|
- - ">="
|
181
178
|
- !ruby/object:Gem::Version
|
182
179
|
version: 0.5.0
|
180
|
+
- - "~>"
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0.5'
|
183
183
|
type: :runtime
|
184
184
|
prerelease: false
|
185
185
|
version_requirements: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
|
-
- - "~>"
|
188
|
-
- !ruby/object:Gem::Version
|
189
|
-
version: '0.5'
|
190
187
|
- - ">="
|
191
188
|
- !ruby/object:Gem::Version
|
192
189
|
version: 0.5.0
|
190
|
+
- - "~>"
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0.5'
|
193
193
|
description: A plain text code snippet manager
|
194
194
|
email: me@brettterpstra.com
|
195
195
|
executables:
|
@@ -230,7 +230,7 @@ metadata:
|
|
230
230
|
bug_tracker_uri: https://github.com/ttscoff/snibbets/issues
|
231
231
|
changelog_uri: https://github.com/ttscoff/snibbets/blob/main/CHANGELOG.md
|
232
232
|
github_repo: git@github.com:ttscoff/snibbets.git
|
233
|
-
post_install_message:
|
233
|
+
post_install_message:
|
234
234
|
rdoc_options:
|
235
235
|
- "--title"
|
236
236
|
- na
|
@@ -245,15 +245,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
245
|
requirements:
|
246
246
|
- - ">="
|
247
247
|
- !ruby/object:Gem::Version
|
248
|
-
version:
|
248
|
+
version: 2.6.0
|
249
249
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
250
|
requirements:
|
251
251
|
- - ">="
|
252
252
|
- !ruby/object:Gem::Version
|
253
253
|
version: '0'
|
254
254
|
requirements: []
|
255
|
-
rubygems_version: 3.
|
256
|
-
signing_key:
|
255
|
+
rubygems_version: 3.0.3.1
|
256
|
+
signing_key:
|
257
257
|
specification_version: 4
|
258
258
|
summary: Snibbets
|
259
259
|
test_files: []
|