snibbets 2.0.10 → 2.0.11
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 +9 -0
- data/Gemfile.lock +1 -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/version.rb +1 -1
- data/lib/snibbets/which.rb +2 -2
- data/lib/snibbets.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d69fb792808e08bf219cc435fda27458be565afb2b2d16dad8bcf40c4bc4386
|
4
|
+
data.tar.gz: b798ab66a6928be6d50e160ae8c9a1b6f30042a452ed06de798440f5e6e947c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b7b38a0b865c625feb8908a371b2ec76cc36765175abc68bf5956138ad4b60cb39b019aeec7775a4f89e51ce17c61c5b0df8d9b85c0752beb666c9153c9de0f
|
7
|
+
data.tar.gz: b5f7f8a20cb33d4828c012d35057b8af7adb0fe475d226b83af8b91cb5d2d9e18ef6fe5e3be42104ea7ded67cdf46d4e9f3ce679a1699053ca41467d32e9095a
|
data/CHANGELOG.md.orig
CHANGED
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/version.rb
CHANGED
data/lib/snibbets/which.rb
CHANGED
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|
|
154
|
-
tags = langs.map { |lang|
|
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.
|
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-
|
11
|
+
date: 2023-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|