snibbets 2.0.9 → 2.0.11

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: e721debb0d3122f59722537839a728cc81e532c8039edeca696b46f19c91d920
4
- data.tar.gz: ab7261e014473773db55aa1e56f392ba11dc2b423c2d281216d18b57bf51378e
3
+ metadata.gz: 5d69fb792808e08bf219cc435fda27458be565afb2b2d16dad8bcf40c4bc4386
4
+ data.tar.gz: b798ab66a6928be6d50e160ae8c9a1b6f30042a452ed06de798440f5e6e947c5
5
5
  SHA512:
6
- metadata.gz: 9f991baaab2bbe857bb1f2f0edb924ebc241faa58ffb20dec1084283a54d5e7c0163e1aac0368cb051b6b8bc3fe90d7db18517ff48176956e98b6889d7c918bb
7
- data.tar.gz: 01175aaaa465ae16bafff11a8a1d891b188c288042073f667f34a597e28bce105fd3e73e2a56683ed3780c12f7520d525694a1075af728f609e8a28803aad614
6
+ metadata.gz: 1b7b38a0b865c625feb8908a371b2ec76cc36765175abc68bf5956138ad4b60cb39b019aeec7775a4f89e51ce17c61c5b0df8d9b85c0752beb666c9153c9de0f
7
+ data.tar.gz: b5f7f8a20cb33d4828c012d35057b8af7adb0fe475d226b83af8b91cb5d2d9e18ef6fe5e3be42104ea7ded67cdf46d4e9f3ce679a1699053ca41467d32e9095a
data/CHANGELOG.md.orig ADDED
@@ -0,0 +1,65 @@
1
+ ### 2.0.11
2
+
3
+ 2023-04-15 19:06
4
+
5
+ #### FIXED
6
+
7
+ - Overactive stripping of newlines within code blocks
8
+ - Syntax definition determination when adding new snippets
9
+
10
+ ### 2.0.10
11
+
12
+ 2023-04-15 16:28
13
+
14
+ #### FIXED
15
+
16
+ - Update dependencies for security
17
+ - Incorporate fixes from @robjwells addressing #3 and #4
18
+ - Incorporate fixes from @robjwells addressing #3 and #4
19
+ - Best menu CLI determination missing modules
20
+
21
+ <<<<<<< HEAD
22
+ ### 2.0.7
23
+
24
+ 2023-04-15 12:02
25
+ =======
26
+ ### 2.0.9
27
+
28
+ 2023-04-15 15:44
29
+
30
+ #### IMPROVED
31
+
32
+ - Allow setting `menus` config key to force Snibbets to use fzf, gum, or console menus
33
+ - Allow setting `menus` config key to force Snibbets to use fzf, gum, or console menus
34
+
35
+ #### FIXED
36
+
37
+ - If a header section contains no code blocks, don't display it in menu
38
+ - Remove leading and trailing newlines without affecting indentation
39
+
40
+ ### 2.0.8
41
+
42
+ 2023-04-15 15:41
43
+
44
+ #### IMPROVED
45
+
46
+ - Allow setting `menus` config key to force Snibbets to use fzf, gum, or console menus
47
+ - Allow setting `menus` config key to force Snibbets to use fzf, gum, or console menus
48
+
49
+ #### FIXED
50
+
51
+ - If a header section contains no code blocks, don't display it in menu
52
+ - Remove leading and trailing newlines without affecting indentation
53
+ >>>>>>> release/2.0.9
54
+
55
+ ### 2.0.6
56
+
57
+ 2023-04-15 11:55
58
+
59
+ #### IMPROVED
60
+
61
+ - Refactor script as modules and classes
62
+
63
+ ## 2.0.2
64
+
65
+ Initial release as a gem
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snibbets (2.0.7)
4
+ snibbets (2.0.11)
5
5
  tty-which (~> 0.5, >= 0.5.0)
6
6
 
7
7
  GEM
@@ -26,7 +26,7 @@ GEM
26
26
  ast (~> 2.4.1)
27
27
  rainbow (3.1.1)
28
28
  rake (13.0.6)
29
- rdoc (4.3.0)
29
+ rdoc (6.3.3)
30
30
  regexp_parser (2.7.0)
31
31
  rexml (3.2.5)
32
32
  rspec (3.12.0)
@@ -77,12 +77,11 @@ GEM
77
77
  thor (1.2.1)
78
78
  tty-which (0.5.0)
79
79
  unicode-display_width (2.4.2)
80
- webrick (1.7.0)
81
- yard (0.9.28)
82
- webrick (~> 1.7.0)
80
+ yard (0.9.34)
83
81
 
84
82
  PLATFORMS
85
83
  arm64-darwin-20
84
+ x86_64-linux
86
85
 
87
86
  DEPENDENCIES
88
87
  awesome_print (~> 1.9)
@@ -90,7 +89,7 @@ DEPENDENCIES
90
89
  gem-release (~> 2.2)
91
90
  parse_gemspec-cli (~> 1.0)
92
91
  rake (~> 13.0)
93
- rdoc (~> 4.3)
92
+ rdoc (~> 6.3.1)
94
93
  rspec (~> 3.0)
95
94
  simplecov (~> 0.21)
96
95
  simplecov-console (~> 0.9)
data/Gemfile.lock.orig ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snibbets (2.0.10)
5
+ tty-which (~> 0.5, >= 0.5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ansi (1.5.0)
11
+ ast (2.4.2)
12
+ awesome_print (1.9.2)
13
+ diff-lcs (1.5.0)
14
+ docile (1.4.0)
15
+ gem-release (2.2.2)
16
+ json (2.6.3)
17
+ language_server-protocol (3.17.0.3)
18
+ multi_json (1.15.0)
19
+ parallel (1.22.1)
20
+ parse_gemspec (1.0.0)
21
+ parse_gemspec-cli (1.0.0)
22
+ multi_json
23
+ parse_gemspec
24
+ thor
25
+ parser (3.2.2.0)
26
+ ast (~> 2.4.1)
27
+ rainbow (3.1.1)
28
+ rake (13.0.6)
29
+ <<<<<<< HEAD
30
+ rdoc (6.3.1)
31
+ =======
32
+ rdoc (6.3.3)
33
+ >>>>>>> af6f234 (Update rdoc)
34
+ regexp_parser (2.7.0)
35
+ rexml (3.2.5)
36
+ rspec (3.12.0)
37
+ rspec-core (~> 3.12.0)
38
+ rspec-expectations (~> 3.12.0)
39
+ rspec-mocks (~> 3.12.0)
40
+ rspec-core (3.12.1)
41
+ rspec-support (~> 3.12.0)
42
+ rspec-expectations (3.12.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-mocks (3.12.5)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-support (3.12.0)
49
+ rubocop (1.48.1)
50
+ json (~> 2.3)
51
+ parallel (~> 1.10)
52
+ parser (>= 3.2.0.0)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.8, < 3.0)
55
+ rexml (>= 3.2.5, < 4.0)
56
+ rubocop-ast (>= 1.26.0, < 2.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (>= 2.4.0, < 3.0)
59
+ rubocop-ast (1.28.0)
60
+ parser (>= 3.2.1.0)
61
+ rubocop-performance (1.16.0)
62
+ rubocop (>= 1.7.0, < 2.0)
63
+ rubocop-ast (>= 0.4.0)
64
+ ruby-progressbar (1.13.0)
65
+ simplecov (0.22.0)
66
+ docile (~> 1.1)
67
+ simplecov-html (~> 0.11)
68
+ simplecov_json_formatter (~> 0.1)
69
+ simplecov-console (0.9.1)
70
+ ansi
71
+ simplecov
72
+ terminal-table
73
+ simplecov-html (0.12.3)
74
+ simplecov_json_formatter (0.1.4)
75
+ standard (1.26.0)
76
+ language_server-protocol (~> 3.17.0.2)
77
+ rubocop (~> 1.48.1)
78
+ rubocop-performance (~> 1.16.0)
79
+ terminal-table (3.0.2)
80
+ unicode-display_width (>= 1.1.1, < 3)
81
+ thor (1.2.1)
82
+ tty-which (0.5.0)
83
+ unicode-display_width (2.4.2)
84
+ webrick (1.7.0)
85
+ yard (0.9.28)
86
+ webrick (~> 1.7.0)
87
+
88
+ PLATFORMS
89
+ arm64-darwin-20
90
+ x86_64-linux
91
+
92
+ DEPENDENCIES
93
+ awesome_print (~> 1.9)
94
+ bundler (~> 2.0)
95
+ gem-release (~> 2.2)
96
+ parse_gemspec-cli (~> 1.0)
97
+ rake (~> 13.0)
98
+ rdoc (~> 6.3.1)
99
+ rspec (~> 3.0)
100
+ simplecov (~> 0.21)
101
+ simplecov-console (~> 0.9)
102
+ snibbets!
103
+ standard (~> 1.3)
104
+ yard (~> 0.9, >= 0.9.26)
105
+
106
+ BUNDLED WITH
107
+ 2.2.29
data/buildnotes.md CHANGED
@@ -20,7 +20,6 @@ You no longer need to manually bump the version, it will be incremented when thi
20
20
  #!/bin/bash
21
21
 
22
22
  changelog -u
23
- # scripts/fixreadme.rb
24
23
  changelog | git commit -a -F -
25
24
  git pull
26
25
  git push
@@ -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
- next if line =~ /^\s*$/ || line.empty?
20
-
21
- output << line
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
- output = []
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
@@ -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 Which.exist?('fzf')
32
- return 'gum' if Which.exist?('gum')
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('bbedit') if TTY::Which.exist?('bbedit')
51
+ return TTY::Which.which('nano') if TTY::Which.exist?('nano') && @test_editor == 'nano'
47
52
 
48
- return TTY::Which.which('nano') if TTY::Which.exist?('nano')
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
- FileUtils.mkdir_p(config_dir) unless File.directory?(config_dir)
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
@@ -1,34 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Snibbets
2
- class Lexers
3
- attr_accessor :lexers
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
- def build_lexers
6
- IO.read('lexers_db.txt').split(/\n/).each do |line|
7
- key = line.match(/(?mi)^((, )?[^,]+?)+?(?=\[)/)[0]
8
- keys = key.split(/,/).map(&:strip)
9
- value = line.match(/\[(.*?)\]/)[1]
10
- values = value.split(/,/).map(&:strip)
19
+ lex << {
20
+ lexer: keys.shift,
21
+ aliases: keys,
22
+ extensions: values
23
+ }
24
+ end
11
25
 
12
- @lexers << {
13
- lexer: keys.shift,
14
- aliases: keys,
15
- extensions: values
16
- }
26
+ lex
17
27
  end
18
- end
19
28
 
20
- def ext_to_lang(ext)
21
- matches = @lexers.select { |lex| lex[:extensions].map(&:downcase).include?(ext.downcase) }
22
- matches.map { |lex| lex[:lexer] }.first
23
- end
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
- def lang_to_ext(lexer)
26
- matches = @lexers.select { |lex| lex[:lexer] == lexer || lex[:aliases].map(&:downcase).include?(lexer.downcase) }
27
- matches.map { |lex| lex[:extensions].first }.first
28
- end
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
- def syntax_from_extension(filename)
31
- ext_to_lang(filename.split(/\./)[1])
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/menu.rb CHANGED
@@ -113,7 +113,7 @@ module Snibbets
113
113
  return res[line - 1] if line.positive? && line <= res.length
114
114
 
115
115
  warn 'Out of range'
116
- console_menu(res, title)
116
+ return console_menu(res, title, filename, query: query)
117
117
  end
118
118
  rescue Interrupt
119
119
  system('stty', stty_save)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.9'
4
+ VERSION = '2.0.11'
5
5
  end
@@ -16,8 +16,8 @@ module TTY
16
16
  end
17
17
  module_function :app_bundle
18
18
 
19
- def bundle_id?(cmd)
20
- cmd =~ /^\w+(\.\w+){2,}/
19
+ def bundle_id?(id)
20
+ id =~ /^\w+(\.\w+){2,}/ ? true : false
21
21
  end
22
22
  module_function :bundle_id?
23
23
 
data/lib/snibbets.rb CHANGED
@@ -36,14 +36,14 @@ module Snibbets
36
36
  class << self
37
37
  # Search the snippets directory for query using find and grep
38
38
  def search(try: 0)
39
- folder = Snibbets.options[:source]
39
+ folder = File.expand_path(Snibbets.options[:source])
40
40
  # start by doing a spotlight search, if that fails, start trying:
41
41
  # First try only search by filenames
42
42
  # Second try search with grep
43
43
  ext = Snibbets.options[:extension] || 'md'
44
44
  cmd = case try
45
45
  when 1
46
- %(find "#{folder}" -iregex '#{@query.rx}' -name '*.#{ext}')
46
+ %(find "#{folder}" -iregex '^#{Regexp.escape(folder)}/#{@query.rx}' -name '*.#{ext}')
47
47
  when 2
48
48
  rg = TTY::Which.which('rg')
49
49
  ag = TTY::Which.which('ag')
@@ -139,8 +139,6 @@ module Snibbets
139
139
  exit!
140
140
  end
141
141
 
142
- build_lexers
143
-
144
142
  pb = OS.paste.outdent
145
143
 
146
144
  printf 'What does this snippet do? '
@@ -150,12 +148,12 @@ module Snibbets
150
148
  printf 'What language(s) does it use (separate with spaces, full names or file extensions will work)? '
151
149
  input = $stdin.gets.chomp
152
150
  langs = input.split(/ +/).map(&:strip) unless input.empty?
153
- exts = langs.map { |lang| Snibbets::Lexers.lang_to_ext(lang) }
154
- tags = langs.map { |lang| Snibbets::Lexers.ext_to_lang(lang) }.concat(langs).sort.uniq
151
+ exts = langs.map { |lang| Lexers.lang_to_ext(lang) }
152
+ tags = langs.map { |lang| Lexers.ext_to_lang(lang) }.concat(langs).sort.uniq
155
153
 
156
- filename ="#{title}.#{exts.join('.')}.#{Snibbets.options[:extension]}"
154
+ filename = "#{title}.#{exts.join('.')}.#{Snibbets.options[:extension]}"
157
155
 
158
- File.open(File.join(Snibbets.options[:source], filename), 'w') do |f|
156
+ File.open(File.join(File.expand_path(Snibbets.options[:source]), filename), 'w') do |f|
159
157
  f.puts "tags: #{tags.join(', ')}
160
158
 
161
159
  ```
data/snibbets.gemspec CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "gem-release", "~> 2.2"
36
36
  spec.add_development_dependency "parse_gemspec-cli", "~> 1.0"
37
37
  spec.add_development_dependency "rake", "~> 13.0"
38
- spec.add_development_dependency 'rdoc', '~> 4.3'
38
+ spec.add_development_dependency 'rdoc', '~> 6.3.1'
39
39
  spec.add_development_dependency 'yard', '~> 0.9', '>= 0.9.26'
40
40
  spec.add_development_dependency "rspec", "~> 3.0"
41
41
  spec.add_development_dependency "simplecov", "~> 0.21"
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.9
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-15 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '4.3'
89
+ version: 6.3.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '4.3'
96
+ version: 6.3.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: yard
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -199,8 +199,10 @@ extra_rdoc_files:
199
199
  - README.md
200
200
  files:
201
201
  - CHANGELOG.md
202
+ - CHANGELOG.md.orig
202
203
  - Gemfile
203
204
  - Gemfile.lock
205
+ - Gemfile.lock.orig
204
206
  - LICENSE.txt
205
207
  - README.md
206
208
  - README.rdoc