snibbets 2.0.10 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f07f0d4772b8d611c0e29da125b4e6915d3909479c4384348699eedc2e1baf90
4
- data.tar.gz: e9abdf59d66f3c099c0c25f20a912efc53b690c7c45a5f4ada2b18355c3d473c
3
+ metadata.gz: 5d69fb792808e08bf219cc435fda27458be565afb2b2d16dad8bcf40c4bc4386
4
+ data.tar.gz: b798ab66a6928be6d50e160ae8c9a1b6f30042a452ed06de798440f5e6e947c5
5
5
  SHA512:
6
- metadata.gz: ac873395a3735c827164f03b497f21f06e8af227b515e299c40eb8a4eeff26c907a5893077e1ee1a528200ef4ef9e6fe7c5ac1c9ddfecf7522ed0d772e6fd6eb
7
- data.tar.gz: ca65c353589adda9fb4af59d390e98e277e5ba1523d746ab3f5cce19119cfa541b2db36045a90ecddd73be7224665dd96dd8642a2d7c010c438e6e9141a79d6a
6
+ metadata.gz: 1b7b38a0b865c625feb8908a371b2ec76cc36765175abc68bf5956138ad4b60cb39b019aeec7775a4f89e51ce17c61c5b0df8d9b85c0752beb666c9153c9de0f
7
+ data.tar.gz: b5f7f8a20cb33d4828c012d35057b8af7adb0fe475d226b83af8b91cb5d2d9e18ef6fe5e3be42104ea7ded67cdf46d4e9f3ce679a1699053ca41467d32e9095a
data/CHANGELOG.md.orig CHANGED
@@ -1,3 +1,12 @@
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
+
1
10
  ### 2.0.10
2
11
 
3
12
  2023-04-15 16:28
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snibbets (2.0.10)
4
+ snibbets (2.0.11)
5
5
  tty-which (~> 0.5, >= 0.5.0)
6
6
 
7
7
  GEM
@@ -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 TTY::Which.exist?('fzf')
32
- return 'gum' if TTY::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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.10'
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
@@ -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,10 +148,10 @@ 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
156
  File.open(File.join(File.expand_path(Snibbets.options[:source]), filename), 'w') do |f|
159
157
  f.puts "tags: #{tags.join(', ')}
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.10
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