xremap 0.1.0

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: 2cafc501b56ad37f11da37510eb2b448e70e42ccb448241636ffb03941e3f8fa
4
+ data.tar.gz: ff8bce82246844c4d47cdb4299bda9900e74b9f1014913af131d524091e525ed
5
+ SHA512:
6
+ metadata.gz: 4bdb21df26dfaba5aba608d0e077a2e160fe4bebfbd8502a825d06f0dd8bf64f192a763718dd33d5734ba65491d084c4f4f835eeda02ed3c4f9a3d8c2374cbf5
7
+ data.tar.gz: ed0499f4c0ed070bbfa186252be078eb563461c3cf992f019f7bbe26b331f0899442f236f476b8c89b72d15091a8e7c8edba61d289b6cd91dda1d46c47fb02b3
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.2
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.1.0
2
+
3
+ - Initial release
4
+ - Support `remap` and `window` like xremap 0.0.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in xremap.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Takashi Kokubun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # xremap-ruby
2
+
3
+ Generate an xremap config with a Ruby DSL.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ gem install xremap
9
+ ```
10
+
11
+ This will install `xremap-ruby` command.
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ $ xremap-ruby example/config.rb > config.yml
17
+ $ sudo xremap config.yml
18
+ ```
19
+
20
+ ## License
21
+
22
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "xremap"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/example/config.rb ADDED
@@ -0,0 +1,29 @@
1
+ # emacs-like bindings
2
+ remap 'C-b', to: 'Left'
3
+ remap 'C-f', to: 'Right'
4
+ remap 'C-p', to: 'Up'
5
+ remap 'C-n', to: 'Down'
6
+
7
+ window class_not: %w[slack google-chrome gnome-terminal-server urxvt Focus-Proxy-Window] do
8
+ remap 'M-b', to: 'Ctrl-Left'
9
+ remap 'M-f', to: 'Ctrl-Right'
10
+
11
+ remap 'C-a', to: 'Alt-C-a'
12
+ remap 'C-e', to: 'Alt-C-e'
13
+
14
+ remap 'C-k', to: 'Alt-C-k'
15
+
16
+ remap 'C-d', to: 'Delete'
17
+ remap 'M-d', to: 'Ctrl-Delete'
18
+
19
+ remap 'C-w', to: ['Ctrl-Shift-Left', 'Delete']
20
+ end
21
+
22
+ window class_only: %w[google-chrome slack] do
23
+ remap 'M-b', to: 'Ctrl-Left'
24
+ remap 'M-f', to: 'Ctrl-Right'
25
+
26
+ remap 'C-a', to: 'Home'
27
+ remap 'C-e', to: 'End'
28
+ remap 'C-k', to: ['Shift-End', 'Delete']
29
+ end
data/exe/xremap-ruby ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path('../lib', __dir__)
4
+ require 'xremap'
5
+
6
+ if ARGV.size != 1
7
+ abort "Usage: #{$0} config.rb"
8
+ end
9
+
10
+ source = File.read(ARGV.first)
11
+ dsl = Xremap::DSL.new
12
+ dsl.instance_eval(source)
13
+ puts Xremap.generate(dsl)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xremap
4
+ VERSION = '0.1.0'
5
+ end
data/lib/xremap.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+ require 'json'
3
+ require 'yaml'
4
+ require_relative 'xremap/version'
5
+
6
+ module Xremap
7
+ def self.generate(dsl)
8
+ config = { keymap: [] }
9
+
10
+ # Using instance_variable_get to avoid making an attr_reader a DSL
11
+ dsl.instance_variable_get(:@keymap).each do |keymap|
12
+ unless keymap.remap.empty?
13
+ entry = {
14
+ name: 'xremap-ruby',
15
+ remap: keymap.remap,
16
+ }
17
+ if keymap.application
18
+ entry[:application] = {
19
+ not: keymap.application.not,
20
+ only: keymap.application.only,
21
+ }.compact
22
+ end
23
+ config.fetch(:keymap) << entry
24
+ end
25
+ end
26
+
27
+ config = JSON.parse(config.to_json) # stringify keys
28
+ config.to_yaml
29
+ end
30
+
31
+ class DSL
32
+ def initialize
33
+ @keymap = []
34
+ @keymap << Keymap.new(remap: {})
35
+ end
36
+
37
+ def remap(from, to:)
38
+ @keymap.last.remap[from] = to
39
+ end
40
+
41
+ def window(class_not: nil, class_only: nil, &block)
42
+ @keymap << Keymap.new(
43
+ remap: {},
44
+ application: Application.new(
45
+ not: class_not,
46
+ only: class_only,
47
+ ),
48
+ )
49
+ block.call
50
+ @keymap << Keymap.new(remap: {})
51
+ end
52
+ end
53
+
54
+ Keymap = Struct.new(:application, :remap, keyword_init: true)
55
+ Application = Struct.new(:not, :only, keyword_init: true)
56
+ end
data/xremap.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/xremap/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'xremap'
7
+ spec.version = Xremap::VERSION
8
+ spec.authors = ['Takashi Kokubun']
9
+ spec.email = ['takashikkbn@gmail.com']
10
+
11
+ spec.summary = 'Generate xremap config from Ruby'
12
+ spec.description = 'Generate xremap config from Ruby'
13
+ spec.homepage = 'https://github.com/xremap/xremap-ruby'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.5.0'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ # Uncomment to register a new dependency of your gem
27
+ # spec.add_dependency 'example-gem', '~> 1.0'
28
+
29
+ # For more information and examples about making a new gem, checkout our
30
+ # guide at: https://bundler.io/guides/creating_gem.html
31
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xremap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takashi Kokubun
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Generate xremap config from Ruby
14
+ email:
15
+ - takashikkbn@gmail.com
16
+ executables:
17
+ - xremap-ruby
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - example/config.rb
31
+ - exe/xremap-ruby
32
+ - lib/xremap.rb
33
+ - lib/xremap/version.rb
34
+ - xremap.gemspec
35
+ homepage: https://github.com/xremap/xremap-ruby
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/xremap/xremap-ruby
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.5.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.2.22
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Generate xremap config from Ruby
59
+ test_files: []