llm_label_launcher 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 01a4a722a9f9552355c9789ca88e6cc7f68b4be13e5b9e7a85669c6f61645f78
4
+ data.tar.gz: 6ef2b9c82dec040fc1ccb6ece39900ad18605dddc7e7798232e6ef4e0b88c178
5
+ SHA512:
6
+ metadata.gz: b34ffd4da9df3c87e216d7f1f3f5f6efe34c2e3e9fbea3366be6e5fb3b2b05d409e4b45cb8a9d8d81dd522d8a4bae5a3abee92f1ea5ba5eddede26893d8408ff
7
+ data.tar.gz: 0d854d879317d7e80755b2441bbb0ae5600d958d025ec8d15d83e8e7080fc84343c76ced0320f6580079dd59213acce22ceee189baa976286687e48a6e5a7eb0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'llm_label_launcher'
3
+
4
+ llm = LlmLabelLauncher.new
5
+ puts llm.command(ARGV)
@@ -0,0 +1,87 @@
1
+ require 'optparse'
2
+
3
+ class LlmLabelLauncher
4
+ CONFIG_PATH = File.expand_path("~/.label_launcher.config")
5
+ attr_accessor :labels
6
+ attr_accessor :list,
7
+ :config,
8
+ :to_open
9
+
10
+ def initialize
11
+ if !File.exists?(CONFIG_PATH)
12
+ File.open(CONFIG_PATH, 'w') { |f| f.write(%|
13
+ # 注释代码
14
+ # 格式为:[名称] [路径/参数] [启动器]
15
+ # 例:百度 https://www.baidu.com/ google-chrome
16
+ |.strip) }
17
+ end
18
+ config_text = File.open(CONFIG_PATH, 'r') { |f| f.read }
19
+ self.labels = parse_labels(config_text)
20
+ end
21
+
22
+ def run
23
+ if config
24
+ return CONFIG_PATH
25
+ end
26
+
27
+ return to_text(labels) if File.exists?(CONFIG_PATH) if list
28
+
29
+ if to_open
30
+ label = to_open.to_i.to_s == to_open ? labels[to_open.to_i] : labels.select { |l| l[0].include?(to_open) }.first
31
+ return "not found label on #{to_open}" if label.nil?
32
+ `#{label[-1]} #{label[-2]}`
33
+ end
34
+ end
35
+
36
+ def command(args)
37
+ OptionParser.new do |parser|
38
+ parser.banner = "用法: llm_label_launcher [options]"
39
+ parser.separator ""
40
+ parser.separator "指定选项:"
41
+
42
+ # 配置
43
+ parser.on('-c', '--config', %|查看配置文件路径|) do |config|
44
+ self.config = config
45
+ end
46
+
47
+ # 查找
48
+ parser.on('-l', "--list", '列出标签') do
49
+ self.list = true
50
+ end
51
+
52
+ # 打开标签
53
+ parser.on('-o TEXT', '--open TEXT', '打开标签,默认第一个匹配项') do |text|
54
+ self.to_open = text
55
+ end
56
+
57
+ parser.separator ""
58
+ parser.separator "通用选项:"
59
+ parser.on_tail("-h", "--help", "帮助信息") do
60
+ puts parser
61
+ exit
62
+ end
63
+ parser.on_tail("--version", "版本信息") do
64
+ puts '0.0.1'
65
+ exit
66
+ end
67
+
68
+ end.parse!(args)
69
+ run
70
+ end
71
+
72
+ private
73
+
74
+ def parse_label(text)
75
+ tmp = text.strip.split(' ')
76
+ [tmp[0], tmp[1..-2].join(' '), tmp[-1]]
77
+ end
78
+
79
+ def parse_labels(text)
80
+ text.gsub(/\t/, ' ').strip.split("\n").select { |l| l[0] != '#' && !l.empty? }.map { |t| parse_label(t) }
81
+ end
82
+
83
+ def to_text(labels)
84
+ labels.each_with_index
85
+ .map { |l, index| "#{index}|#{l.join('|')}" }.join("\n")
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: llm_label_launcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Liuliming
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-08-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "\n this util help you integration your document!\n use `llm_label_launcher
14
+ -h` read document\n then config ~/.label_launcher.config\n "
15
+ email: 876475897@qq.com
16
+ executables:
17
+ - llm_label_launcher
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/llm_label_launcher
22
+ - lib/llm_label_launcher.rb
23
+ homepage: https://github.com/Beginner125/ruby-center/tree/main/llm-lable-lancher
24
+ licenses:
25
+ - MIT
26
+ metadata:
27
+ source_code_uri: https://github.com/Beginner125/ruby-center/tree/main/llm-lable-lancher
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.6.2
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: saving command label and open quickly
48
+ test_files: []