tmux-erb-parser 0.1.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/tmux-erb-parser/command.rb +7 -13
- data/lib/tmux-erb-parser/converter.rb +83 -0
- data/lib/tmux-erb-parser/helpers/environment_helper.rb +2 -0
- data/lib/tmux-erb-parser/helpers/format_helper.rb +2 -0
- data/lib/tmux-erb-parser/helpers.rb +8 -23
- data/lib/tmux-erb-parser/parser.rb +15 -15
- data/lib/tmux-erb-parser/version.rb +1 -1
- data/lib/tmux-erb-parser.rb +6 -1
- metadata +7 -117
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa36f112f4bf7d15b5cbf20d8d19343cab7299dfdac7b2ed81918731ef97ef57
|
4
|
+
data.tar.gz: 45543c76a828931350e9e1bf86cef902576201748b50eae34bf6150542a04a8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '083f5f3dc8d93410fcf156dbe34ce415f6108ea2d1641763b7ca0893262fc843a3235bcea87f54c0f0786ff8dfffcaa645071c81e8b04799fbbac2ea3f68b41a'
|
7
|
+
data.tar.gz: 77eeefd48f4a0f795e02b6d866c3008dc9c1236fa520b93f3ed377b1045a88789d172ccade6bf3f2134ccba25d397b53bf18073b6eb7fedd03943cb94a104089
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Tmux ERB Parser
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/tmux-erb-parser.svg)](https://badge.fury.io/rb/tmux-erb-parser)
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/epaew/tmux-erb-parser/workflows/Run%20TestUnit/badge.svg)](https://github.com/epaew/tmux-erb-parser/actions?query=workflow%3A%22Run+TestUnit%22+branch%3A%22master%22)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/a4c67b3c8ba8e555d98f/maintainability)](https://codeclimate.com/github/epaew/tmux-erb-parser/maintainability)
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/a4c67b3c8ba8e555d98f/test_coverage)](https://codeclimate.com/github/epaew/tmux-erb-parser/test_coverage)
|
6
6
|
|
@@ -13,14 +13,16 @@ A Tmux plugin for loading tmux.conf written in Ruby (eRuby) notation.
|
|
13
13
|
* You can use whatever you like as the default shell.
|
14
14
|
* git
|
15
15
|
* ruby:
|
16
|
-
* 2.
|
16
|
+
* 2.7 or higher is required.
|
17
17
|
* tmux
|
18
18
|
|
19
19
|
## How to use
|
20
20
|
1. Create your `tmux.conf.erb` and place it.
|
21
21
|
* By default, tmux-erb-parser loads all `*.erb` files in `~/.config/tmux/`
|
22
22
|
* Or you can change the load path. (Please see below.)
|
23
|
-
* Sample configuration file:
|
23
|
+
* Sample configuration file:
|
24
|
+
* [sample.tmux.conf.erb](test/fixtures/sample.tmux.conf.erb)
|
25
|
+
* [sample.tmux.conf.yaml](test/fixtures/sample.tmux.conf.yaml)
|
24
26
|
2. Install tmux-erb-parser and run tmux!
|
25
27
|
|
26
28
|
### Install with tpm (Tmux Plugin Manager)
|
@@ -27,9 +27,7 @@ module TmuxERBParser
|
|
27
27
|
|
28
28
|
def check_args
|
29
29
|
msg = 'INPUT_ERB_FILES are required.' if @args.empty?
|
30
|
-
unless @options[:inline] ^ @options[:output]
|
31
|
-
msg = 'Please specify either --inline or --output option.'
|
32
|
-
end
|
30
|
+
msg = 'Please specify either --inline or --output option.' unless @options[:inline] ^ @options[:output]
|
33
31
|
|
34
32
|
raise ArgumentError, msg if msg
|
35
33
|
end
|
@@ -37,17 +35,13 @@ module TmuxERBParser
|
|
37
35
|
def command_opts(opts) # rubocop:disable Metrics/MethodLength
|
38
36
|
opts.banner = "Usage: #{@command_name} INPUT_FILES [options]"
|
39
37
|
|
40
|
-
opts.on('-i',
|
41
|
-
'--inline',
|
42
|
-
'Exec tmux subcommands to the current tmux-server.') do
|
38
|
+
opts.on('-i', '--inline', 'Exec tmux subcommands to the current tmux-server.') do
|
43
39
|
@options[:inline] = true
|
44
40
|
end
|
45
41
|
|
46
|
-
opts.on('-o',
|
47
|
-
|
48
|
-
|
49
|
-
'Output the configuration to a file with the specified name.'\
|
50
|
-
' If the file name is omitted, output to stdout') do |fname|
|
42
|
+
opts.on('-o', '--output [OUTPUT_FILE_NAME]', String, <<~DESC) do |fname|
|
43
|
+
Output the configuration to a file with the specified name. If the file name is omitted, output to stdout
|
44
|
+
DESC
|
51
45
|
@options[:output] = File.open(fname, 'w') if fname
|
52
46
|
@options[:output] ||= $stdout
|
53
47
|
end
|
@@ -89,8 +83,8 @@ module TmuxERBParser
|
|
89
83
|
@args.each do |arg|
|
90
84
|
@logger.info "open #{arg}."
|
91
85
|
File.open(arg, 'r') do |input|
|
92
|
-
p = Parser.new(input, File.extname(arg.downcase)[1
|
93
|
-
commands = p.parse(@options[:output].nil?)
|
86
|
+
p = Parser.new(input, File.extname(arg.downcase)[1..].to_sym)
|
87
|
+
commands = p.parse(strip_comments: @options[:output].nil?)
|
94
88
|
exec(commands, @options[:output])
|
95
89
|
end
|
96
90
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TmuxERBParser
|
4
|
+
class Converter
|
5
|
+
class << self
|
6
|
+
def convert(structured)
|
7
|
+
structured = [structured] if structured.is_a?(Hash)
|
8
|
+
|
9
|
+
structured.inject([], &method(:convert_line))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def convert_line(result, line)
|
15
|
+
result << '' unless result.empty?
|
16
|
+
|
17
|
+
comment = line.is_a?(Hash) && line.delete('comment')
|
18
|
+
result << "# #{comment}" if comment
|
19
|
+
|
20
|
+
result.push(*convert_structured(line))
|
21
|
+
end
|
22
|
+
|
23
|
+
def convert_hash(hash, prefix = [])
|
24
|
+
converted = hash.map do |key, value|
|
25
|
+
case key
|
26
|
+
when '"'
|
27
|
+
convert_structured(value, [*prefix, %('"')])
|
28
|
+
when 'if', 'if-shell', 'run', 'run-shell'
|
29
|
+
convert_structured_shell(value, [*prefix, key])
|
30
|
+
when /style/
|
31
|
+
convert_structured_style(value, [*prefix, key])
|
32
|
+
else
|
33
|
+
convert_structured(value, [*prefix, key])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
converted.flatten
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert_string(string, prefix = [])
|
40
|
+
[*prefix, string].join(' ')
|
41
|
+
end
|
42
|
+
|
43
|
+
def convert_structured(item, prefix = [])
|
44
|
+
case item
|
45
|
+
when Array
|
46
|
+
item.map { |i| convert_structured(i, prefix) }
|
47
|
+
when Hash
|
48
|
+
convert_hash(item, prefix)
|
49
|
+
else
|
50
|
+
convert_string(item, prefix)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def convert_structured_shell(item, prefix = [])
|
55
|
+
case item
|
56
|
+
when Array
|
57
|
+
args = item.map { |i| convert_structured(i, []) }
|
58
|
+
args = args.flatten.map do |arg|
|
59
|
+
arg.include?(' ') ? %('#{arg}') : arg
|
60
|
+
end
|
61
|
+
|
62
|
+
[*prefix, *args].join(' ')
|
63
|
+
else
|
64
|
+
convert_string(item, prefix)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def convert_structured_style(item, prefix = [])
|
69
|
+
case item
|
70
|
+
when Array
|
71
|
+
convert_string(item.join(','), prefix)
|
72
|
+
when Hash
|
73
|
+
convert_string(
|
74
|
+
item.map { |key, value| "#{key}=#{value}" }.join(','),
|
75
|
+
prefix
|
76
|
+
)
|
77
|
+
else
|
78
|
+
convert_string(item, prefix)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -1,32 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
refine String do
|
6
|
-
def classify
|
7
|
-
snake_case = File.basename(self, '.rb')
|
8
|
-
splitted = snake_case.split('_').map do |w|
|
9
|
-
w[0] = w[0].upcase
|
10
|
-
w
|
11
|
-
end
|
12
|
-
splitted.join
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
3
|
+
require_relative 'helpers/environment_helper'
|
4
|
+
require_relative 'helpers/format_helper'
|
16
5
|
|
6
|
+
module TmuxERBParser
|
17
7
|
module Helpers
|
18
|
-
|
8
|
+
extend EnvironmentHelper
|
9
|
+
extend FormatHelper
|
19
10
|
|
20
|
-
|
21
|
-
require h
|
22
|
-
klass = const_get(h.classify)
|
23
|
-
self.class.class_eval do
|
24
|
-
prepend klass
|
25
|
-
end
|
26
|
-
end
|
11
|
+
module_function
|
27
12
|
|
28
|
-
def
|
29
|
-
super
|
13
|
+
def binding # rubocop:disable Lint/UselessMethodDefinition: super(= Kernel.#binding) is private
|
14
|
+
super
|
30
15
|
end
|
31
16
|
end
|
32
17
|
end
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'erb'
|
4
4
|
require 'json'
|
5
5
|
require 'yaml'
|
6
|
+
require_relative 'converter'
|
6
7
|
require_relative 'helpers'
|
7
8
|
|
8
9
|
module TmuxERBParser
|
@@ -21,7 +22,7 @@ module TmuxERBParser
|
|
21
22
|
@type = type
|
22
23
|
end
|
23
24
|
|
24
|
-
def parse(strip_comments
|
25
|
+
def parse(strip_comments: false)
|
25
26
|
parse_string(@input, @type).map do |line|
|
26
27
|
line = replace_source_file(line)
|
27
28
|
line = strip_comment(line) if strip_comments
|
@@ -31,33 +32,32 @@ module TmuxERBParser
|
|
31
32
|
|
32
33
|
private
|
33
34
|
|
34
|
-
def generate_conf(_structured)
|
35
|
-
# TODO
|
36
|
-
# parse_result = []
|
37
|
-
end
|
38
|
-
|
39
35
|
def parse_string(input, type)
|
40
36
|
erb_result = ERB.new(input).result(TmuxERBParser::Helpers.binding)
|
41
37
|
|
38
|
+
parse_structure(erb_result, type)
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_structure(erb_result, type)
|
42
42
|
case type
|
43
43
|
when :json
|
44
|
-
|
44
|
+
Converter.convert(JSON.parse(erb_result))
|
45
45
|
when :yml, :yaml
|
46
|
-
|
46
|
+
if RUBY_VERSION.to_f < 2.6
|
47
|
+
Converter.convert(YAML.safe_load(erb_result, [], [], true))
|
48
|
+
else
|
49
|
+
Converter.convert(YAML.safe_load(erb_result, aliases: true))
|
50
|
+
end
|
47
51
|
else
|
48
|
-
# rubocop:disable Metrics/LineLength
|
49
52
|
erb_result
|
50
|
-
.gsub(/(\R){3,}/) { Regexp.last_match(1) * 2 } # reduce continuity
|
51
|
-
.
|
52
|
-
.each_line
|
53
|
-
.map(&:chomp)
|
54
|
-
# rubocop:enable Metrics/LineLength
|
53
|
+
.gsub(/(\R){3,}/) { Regexp.last_match(1) * 2 } # reduce continuity blankline
|
54
|
+
.each_line(chomp: true)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
58
|
def replace_source_file(line)
|
59
59
|
# source file -> run-shell "parser --inline file"
|
60
|
-
if line
|
60
|
+
if line.include?('source') && line !~ /run(-shell)?/
|
61
61
|
line = line.gsub(/"source(-file)?( -q)?\s([^\s\\;]+)"/) do
|
62
62
|
%("run-shell \\"#{PARSER_CMD} --inline #{Regexp.last_match(3)}\\"")
|
63
63
|
end
|
data/lib/tmux-erb-parser.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'tmux-erb-parser/command'
|
4
|
+
require_relative 'tmux-erb-parser/converter'
|
5
|
+
require_relative 'tmux-erb-parser/helpers'
|
6
|
+
require_relative 'tmux-erb-parser/logger'
|
7
|
+
require_relative 'tmux-erb-parser/parser'
|
8
|
+
require_relative 'tmux-erb-parser/version'
|
metadata
CHANGED
@@ -1,127 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tmux-erb-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epaew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: pry
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: simplecov
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "<"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.18'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "<"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.18'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov-console
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: test-unit
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '3.2'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '3.2'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: test-unit-rr
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '1.0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '1.0'
|
11
|
+
date: 2023-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
125
13
|
description: A Tmux plugin for loading tmux.conf written in Ruby (eRuby) notation.
|
126
14
|
email:
|
127
15
|
- epaew.333@gmail.com
|
@@ -136,6 +24,7 @@ files:
|
|
136
24
|
- erb-parser.tmux
|
137
25
|
- lib/tmux-erb-parser.rb
|
138
26
|
- lib/tmux-erb-parser/command.rb
|
27
|
+
- lib/tmux-erb-parser/converter.rb
|
139
28
|
- lib/tmux-erb-parser/helpers.rb
|
140
29
|
- lib/tmux-erb-parser/helpers/environment_helper.rb
|
141
30
|
- lib/tmux-erb-parser/helpers/format_helper.rb
|
@@ -147,6 +36,7 @@ licenses:
|
|
147
36
|
- MIT
|
148
37
|
metadata:
|
149
38
|
allowed_push_host: https://rubygems.org
|
39
|
+
rubygems_mfa_required: 'true'
|
150
40
|
post_install_message:
|
151
41
|
rdoc_options: []
|
152
42
|
require_paths:
|
@@ -155,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
45
|
requirements:
|
156
46
|
- - ">="
|
157
47
|
- !ruby/object:Gem::Version
|
158
|
-
version: 2.
|
48
|
+
version: 2.7.0
|
159
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
50
|
requirements:
|
161
51
|
- - ">="
|
@@ -164,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
54
|
requirements:
|
165
55
|
- bash
|
166
56
|
- tmux
|
167
|
-
rubygems_version: 3.1.
|
57
|
+
rubygems_version: 3.1.6
|
168
58
|
signing_key:
|
169
59
|
specification_version: 4
|
170
60
|
summary: A Tmux plugin for loading tmux.conf written in Ruby (eRuby) notation.
|