tmux-erb-parser 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +12 -7
- data/bin/tmux-erb-parser +0 -2
- data/lib/tmux-erb-parser/command.rb +36 -16
- data/lib/tmux-erb-parser/parser.rb +34 -52
- data/lib/tmux-erb-parser/version.rb +1 -1
- 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: 7da9078d32cc8302a89b36462a0cd9bc9329679e205e8be50cfdc0e839b019e0
|
4
|
+
data.tar.gz: c3ef1b2b8c8105d7f4a32515853920aabb72f337a009bfae36a2c8840a04f624
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7150f31dfd4bef069c6799cc25cdcd28c529eff87746e774f5560eb4a611c69c3306c9c9a15120ffc5e534b1c672c87e96f65846624e452916ddf0703ecc0133
|
7
|
+
data.tar.gz: 300d0087b6e77ae478d31ddb57d441e68536c61b4f31dbeb2aa1fce560d9fbf55fce66e1da414b4b27db77d44f088fba71d3a7e9d572edfba74f4323efd07d9d
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ A Tmux plugin to load tmux.conf.erb
|
|
20
20
|
2. Install tmux-erb-parser and run tmux!
|
21
21
|
|
22
22
|
### Install with tpm (Tmux Plugin Manager)
|
23
|
-
* Put this at the bottom of `~/.tmux.conf` (**Not your tmux.conf.erb
|
23
|
+
* Put this at the bottom of `~/.tmux.conf` (**Not your tmux.conf.erb!**):
|
24
24
|
```tmux
|
25
25
|
setenv -g TMUX_CONF_EXT_PATH "path/to/tmux.conf.erb" # set your tmux.conf.erb's path
|
26
26
|
# Note: You can specify multiple files using glob expressions. This is parsed by bash.
|
@@ -35,16 +35,21 @@ A Tmux plugin to load tmux.conf.erb
|
|
35
35
|
|
36
36
|
* Run tmux and press `Prefix + I` to install plugins!
|
37
37
|
|
38
|
-
### Install and configure with git
|
38
|
+
### Install and configure with git/rubygems
|
39
39
|
* Install:
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
* with git:
|
41
|
+
```bash
|
42
|
+
git clone https://github.com/epaew/tmux-erb-parser ~/.tmux/plugins/tmux-erb-parser
|
43
|
+
```
|
44
|
+
* from rubygems:
|
45
|
+
```bash
|
46
|
+
gem install tmux-erb-parser
|
47
|
+
```
|
43
48
|
|
44
49
|
* Configure:
|
45
|
-
* Put this in `~/.tmux.conf
|
50
|
+
* Put this in `~/.tmux.conf` (**Not your tmux.conf.erb!**):
|
46
51
|
```tmux
|
47
|
-
run '
|
52
|
+
run 'path/to/bin/tmux-erb-parser --inline path/to/tmux.conf.erb'
|
48
53
|
```
|
49
54
|
|
50
55
|
## License
|
data/bin/tmux-erb-parser
CHANGED
@@ -34,22 +34,6 @@ module TmuxERBParser
|
|
34
34
|
raise ArgumentError, msg if msg
|
35
35
|
end
|
36
36
|
|
37
|
-
def process
|
38
|
-
check_args
|
39
|
-
|
40
|
-
args = @args.dup
|
41
|
-
args.each do |arg|
|
42
|
-
@logger.info "open #{arg}."
|
43
|
-
File.open(arg, 'r') do |input|
|
44
|
-
p = Parser.new(input,
|
45
|
-
@options[:output],
|
46
|
-
File.extname(arg.downcase)[1..-1].to_sym,
|
47
|
-
@options)
|
48
|
-
p.parse
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
37
|
def command_opts(opts) # rubocop:disable Metrics/MethodLength
|
54
38
|
opts.banner = "Usage: #{@command_name} INPUT_FILES [options]"
|
55
39
|
|
@@ -78,5 +62,41 @@ module TmuxERBParser
|
|
78
62
|
exit
|
79
63
|
end
|
80
64
|
end
|
65
|
+
|
66
|
+
def exec(commands, output = nil)
|
67
|
+
if output
|
68
|
+
commands.each(&output.method(:puts))
|
69
|
+
else
|
70
|
+
commands.inject(+'', &method(:exec_tmux))
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def exec_tmux(buf, line)
|
75
|
+
buf << line
|
76
|
+
return buf if buf.empty?
|
77
|
+
|
78
|
+
if buf.end_with?('\\')
|
79
|
+
buf.chop!
|
80
|
+
else
|
81
|
+
command = "tmux #{buf.gsub(%(\\;), %( '\\;'))}"
|
82
|
+
@logger.debug "exec: #{command}"
|
83
|
+
|
84
|
+
`#{command}` unless ENV['DEBUG']
|
85
|
+
+''
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def process
|
90
|
+
check_args
|
91
|
+
|
92
|
+
@args.each do |arg|
|
93
|
+
@logger.info "open #{arg}."
|
94
|
+
File.open(arg, 'r') do |input|
|
95
|
+
p = Parser.new(input, File.extname(arg.downcase)[1..-1].to_sym)
|
96
|
+
commands = p.parse(@options[:output].nil?)
|
97
|
+
exec(commands, @options[:output])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
81
101
|
end
|
82
102
|
end
|
@@ -10,54 +10,33 @@ module TmuxERBParser
|
|
10
10
|
class ParseError < StandardError; end
|
11
11
|
|
12
12
|
class Parser
|
13
|
-
def initialize(input,
|
14
|
-
@input = input
|
15
|
-
|
13
|
+
def initialize(input, type = :erb)
|
14
|
+
@input = case input
|
15
|
+
when IO then input.read
|
16
|
+
when Array then input.join('\n')
|
17
|
+
when String then input
|
18
|
+
else raise ArgumentError
|
19
|
+
end
|
16
20
|
@type = type
|
17
|
-
@options = options
|
18
|
-
@logger = Logger.instance
|
19
21
|
end
|
20
22
|
|
21
|
-
def parse
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def exec(commands, output = nil)
|
30
|
-
if output
|
31
|
-
commands.each(&output.method(:puts))
|
32
|
-
else
|
33
|
-
commands.inject(+'', &method(:exec_tmux))
|
23
|
+
def parse(strip_comments = false)
|
24
|
+
parse_string(@input, @type).map do |line|
|
25
|
+
line = replace_source_file(line)
|
26
|
+
line = strip_comment(line) if strip_comments
|
27
|
+
line
|
34
28
|
end
|
35
29
|
end
|
36
30
|
|
37
|
-
|
38
|
-
buf = +buf if buf.frozen?
|
39
|
-
buf << line
|
40
|
-
buf = strip_comments(buf)
|
41
|
-
return buf if buf.empty?
|
42
|
-
|
43
|
-
if buf.end_with?('\\')
|
44
|
-
buf.chop!
|
45
|
-
else
|
46
|
-
command = "tmux #{buf.gsub(%(\\;), %( '\\;'))}"
|
47
|
-
@logger.debug "exec: #{command}"
|
48
|
-
|
49
|
-
`#{command}` unless ENV['DEBUG']
|
50
|
-
buf.clear
|
51
|
-
end
|
52
|
-
end
|
31
|
+
private
|
53
32
|
|
54
33
|
def generate_conf(_structured)
|
55
34
|
# TODO
|
56
35
|
parse_result = []
|
57
36
|
end
|
58
37
|
|
59
|
-
def
|
60
|
-
erb_result = ERB.new(input
|
38
|
+
def parse_string(input, type)
|
39
|
+
erb_result = ERB.new(input).result
|
61
40
|
|
62
41
|
case type
|
63
42
|
when :json
|
@@ -88,32 +67,35 @@ module TmuxERBParser
|
|
88
67
|
line
|
89
68
|
end
|
90
69
|
|
91
|
-
def
|
70
|
+
def strip_comment(str)
|
92
71
|
return '' if str.empty? || str.lstrip.start_with?('#')
|
93
72
|
|
94
|
-
|
73
|
+
strip_eol_comment(str)
|
95
74
|
end
|
96
75
|
|
97
|
-
|
98
|
-
def strip_eol_comments(str)
|
76
|
+
def strip_eol_comment(str)
|
99
77
|
flags = {}
|
100
78
|
str = str.each_char.inject(+'') do |result, char|
|
101
|
-
|
102
|
-
|
103
|
-
if !flags[:double] || (flags[:single] && result[-1] != '\\')
|
104
|
-
flags[:single] = !flags[:single]
|
105
|
-
end
|
106
|
-
when '"'
|
107
|
-
if !flags[:single] || (flags[:double] && result[-1] != '\\')
|
108
|
-
flags[:double] = !flags[:double]
|
109
|
-
end
|
110
|
-
when '#'
|
111
|
-
break result if flags.values.none?
|
112
|
-
end
|
79
|
+
flags = update_flags(flags, char)
|
80
|
+
break result if char == '#' && flags.values.none?
|
113
81
|
|
114
82
|
result << char
|
115
83
|
end
|
116
84
|
str.rstrip
|
117
85
|
end
|
86
|
+
|
87
|
+
def update_flags(current_flags, char)
|
88
|
+
result = current_flags.dup
|
89
|
+
result.delete(:'\\')
|
90
|
+
|
91
|
+
case char
|
92
|
+
when '\\'
|
93
|
+
result[char.to_sym] = !current_flags[char.to_sym]
|
94
|
+
when '\'', '"'
|
95
|
+
result[char.to_sym] =
|
96
|
+
current_flags.delete(char.to_sym) ^ current_flags.values.none?
|
97
|
+
end
|
98
|
+
result
|
99
|
+
end
|
118
100
|
end
|
119
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tmux-erb-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epaew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|