dotremap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/bin/dotremap +12 -0
- data/dotremap.gemspec +24 -0
- data/example.rb +135 -0
- data/lib/dotremap/appdef.rb +26 -0
- data/lib/dotremap/dsl/item.rb +32 -0
- data/lib/dotremap/dsl/root.rb +16 -0
- data/lib/dotremap/dsl.rb +4 -0
- data/lib/dotremap/item.rb +54 -0
- data/lib/dotremap/property.rb +13 -0
- data/lib/dotremap/remap.rb +94 -0
- data/lib/dotremap/root.rb +19 -0
- data/lib/dotremap/version.rb +3 -0
- data/lib/dotremap.rb +61 -0
- data/reload.gif +0 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 401825fbab15250619f14ea781ceff9f345819b6
|
4
|
+
data.tar.gz: 5c1630693db09459e9b23d794f509795ad8897f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 567031667b38d096621e099ff818b0dcdad609df05f58b326942aa26bfcf03e83589d57fe380819c8085fa5b91903ceaf961f49e9e58fd09269a50e85f6870d8
|
7
|
+
data.tar.gz: b5546f823689fd450952619f5f01c68970b9c073ebc26e60f73acc8af8eac4c803b60c0f3cb26a3074cdfe498b89e51e4b72eb80fc5e886f73004fc73179a006
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Takashi Kokubun
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Dotremap
|
2
|
+
|
3
|
+
Lightweight configuration DSL for [KeyRemap4MacBook](https://pqrs.org/osx/karabiner/index.html)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
````bash
|
8
|
+
$ gem install dotremap
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
### 1. Create ~/.remap
|
13
|
+
|
14
|
+
```rb
|
15
|
+
# ~/.remap
|
16
|
+
item "Control+PNBF to Up/Down/Left/Right", not: "TERMINAL" do
|
17
|
+
remap "C-p", to: "Up"
|
18
|
+
remap "C-n", to: "Down"
|
19
|
+
remap "C-b", to: "Left"
|
20
|
+
remap "C-f", to: "Right"
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
### 2. Execute dotremap command
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ dotremap
|
28
|
+
```
|
29
|
+
|
30
|
+
It will replace KeyRemap4MacBook's private.xml with compiled ~/.remap:
|
31
|
+
|
32
|
+
```xml
|
33
|
+
<?xml version="1.0"?>
|
34
|
+
<root>
|
35
|
+
<item>
|
36
|
+
<name>Control+PNBF to Up/Down/Left/Right</name>
|
37
|
+
<identifier>remap.control_pnbf_to_up_down_left_right</identifier>
|
38
|
+
<not>TERMINAL</not>
|
39
|
+
<autogen>__KeyToKey__ KeyCode::P, VK_CONTROL, KeyCode::CURSOR_UP</autogen>
|
40
|
+
<autogen>__KeyToKey__ KeyCode::N, VK_CONTROL, KeyCode::CURSOR_DOWN</autogen>
|
41
|
+
<autogen>__KeyToKey__ KeyCode::B, VK_CONTROL, KeyCode::CURSOR_LEFT</autogen>
|
42
|
+
<autogen>__KeyToKey__ KeyCode::F, VK_CONTROL, KeyCode::CURSOR_RIGHT</autogen>
|
43
|
+
</item>
|
44
|
+
</root>
|
45
|
+
```
|
46
|
+
|
47
|
+
### 3. Reload private.xml and update config
|
48
|
+
|
49
|
+
You have to reload private.xml to activate compiled configurations.
|
50
|
+
|
51
|
+
![](https://raw.githubusercontent.com/k0kubun/dotremap/master/reload.gif)
|
52
|
+
|
53
|
+
## Example
|
54
|
+
|
55
|
+
I'm sorry but currently this software is not well documented.
|
56
|
+
Please see [example.rb](https://github.com/k0kubun/dotremap/blob/master/example.rb) to learn how to use.
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it ( https://github.com/k0kubun/dotremap/fork )
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/dotremap
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.dirname(__FILE__) + "/../lib"
|
4
|
+
$:.unshift lib unless $:.include? lib
|
5
|
+
|
6
|
+
require "dotremap"
|
7
|
+
|
8
|
+
DOTREMAP_PATH = File.expand_path("~/.remap")
|
9
|
+
|
10
|
+
dotremap = Dotremap.new(DOTREMAP_PATH)
|
11
|
+
dotremap.compile
|
12
|
+
dotremap.replace_private_xml
|
data/dotremap.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dotremap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dotremap"
|
8
|
+
spec.version = Dotremap::VERSION
|
9
|
+
spec.authors = ["Takashi Kokubun"]
|
10
|
+
spec.email = ["takashikkbn@gmail.com"]
|
11
|
+
spec.summary = %q{Configuration DSL for KeyRemap4MacBook}
|
12
|
+
spec.description = %q{Configuration DSL for KeyRemap4MacBook}
|
13
|
+
spec.homepage = "https://github.com/k0kubun/dotremap"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency 'unindent', '~> 1.0'
|
24
|
+
end
|
data/example.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
item "[Not Terminal] Command+O|P to Command+{|} (US)", not: "TERMINAL" do
|
2
|
+
remap "Cmd-P", to: "Cmd-Shift-]"
|
3
|
+
remap "Cmd-O", to: "Cmd-Shift-["
|
4
|
+
end
|
5
|
+
|
6
|
+
item "[Only Terminal] Command+O|P to Option+{|} (US)", only: "TERMINAL" do
|
7
|
+
remap "Cmd-P", to: "Opt-Shift-]"
|
8
|
+
remap "Cmd-O", to: "Opt-Shift-["
|
9
|
+
end
|
10
|
+
|
11
|
+
item "[Not Terminal] Command+E to Command+W", not: "TERMINAL" do
|
12
|
+
remap "Cmd-E", to: "Cmd-W"
|
13
|
+
end
|
14
|
+
|
15
|
+
item "[Only Terminal] Command+T to Option+T, Command+E to Option+E", only: "TERMINAL" do
|
16
|
+
remap "Cmd-T", to: "Opt-T"
|
17
|
+
remap "Cmd-E", to: "Opt-E"
|
18
|
+
end
|
19
|
+
|
20
|
+
# For tmux copy mode
|
21
|
+
item "[Only Terminal] Command+I to Option+I", only: "TERMINAL" do
|
22
|
+
remap "Cmd-I", to: "Opt-I"
|
23
|
+
end
|
24
|
+
|
25
|
+
item "Command_L to Control_R" do
|
26
|
+
remap "Cmd_L", to: "Ctrl_R"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Change japanese input mode by Cmd_L + Space
|
30
|
+
item "Exchange Control + Space and Command + Space" do
|
31
|
+
remap "C-Space", to: "Cmd-Space"
|
32
|
+
remap "Cmd-Space", to: "C-Space"
|
33
|
+
end
|
34
|
+
|
35
|
+
item "CapsLock ON", config_not: "notsave.private_capslock_on" do
|
36
|
+
remap "Cmd-L", to: ["capslock", "VK_CONFIG_FORCE_OFF_notsave_private_capslock_on"]
|
37
|
+
end
|
38
|
+
|
39
|
+
item "CapsLock OFF", config_only: "notsave.private_capslock_on" do
|
40
|
+
remap "Cmd-L", to: ["capslock", "VK_CONFIG_FORCE_OFF_notsave_private_capslock_on"]
|
41
|
+
end
|
42
|
+
|
43
|
+
item "CapsLock Mode" do
|
44
|
+
identifier "notsave.private_capslock_on", vk_config: "true"
|
45
|
+
show_message "CapsLock"
|
46
|
+
end
|
47
|
+
|
48
|
+
item "[Not Terminal] Control+PNBF to Up/Down/Left/Right", not: "TERMINAL" do
|
49
|
+
remap "C-p", to: "Up"
|
50
|
+
remap "C-n", to: "Down"
|
51
|
+
remap "C-b", to: "Left"
|
52
|
+
remap "C-f", to: "Right"
|
53
|
+
end
|
54
|
+
|
55
|
+
# Use Cmd_R+D as M-d
|
56
|
+
item "[Not Terminal] Command+D to Option+Forward Delete", not: "TERMINAL" do
|
57
|
+
remap "Cmd-D", to: "Opt-forward_delete"
|
58
|
+
end
|
59
|
+
|
60
|
+
item "[Only Terminal] Command+D to Option+D, Command+BF to Option+BF", only: "TERMINAL" do
|
61
|
+
remap "Cmd-D", to: "M-d"
|
62
|
+
remap "Cmd-B", to: "M-b"
|
63
|
+
remap "Cmd-F", to: "M-f"
|
64
|
+
end
|
65
|
+
|
66
|
+
# Use Cmd_R+B/F as M-b/f, and Cmd_R+S as Cmd+F to avoid conflict with M-f
|
67
|
+
item "[Not Terminal] Command+B/F to Option+Left/Right, Command+S to Command+F", not: "TERMINAL" do
|
68
|
+
remap "Cmd-B", to: "Opt-Left"
|
69
|
+
remap "Cmd-B", to: "Opt-Left"
|
70
|
+
remap "Cmd-S", to: "Cmd-F"
|
71
|
+
end
|
72
|
+
|
73
|
+
item "[Not Terminal] Control+W to Option+Delete", not: "TERMINAL" do
|
74
|
+
remap "C-w", to: "Opt-delete"
|
75
|
+
end
|
76
|
+
|
77
|
+
item "Control+LeftClick to Command+LeftClick" do
|
78
|
+
autogen "__PointingButtonToPointingButton__ PointingButton::LEFT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_CONTROL, PointingButton::LEFT, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND"
|
79
|
+
end
|
80
|
+
|
81
|
+
item "[Not Terminal] Chrome inspector Command+Control+I", not: "TERMINAL" do
|
82
|
+
remap "Cmd-Ctrl-I", to: "Cmd-Opt-i"
|
83
|
+
end
|
84
|
+
|
85
|
+
# browser reload
|
86
|
+
item "[Not Terminal] Control-R -> Command-R", not: "TERMINAL" do
|
87
|
+
remap "C-r", to: "Cmd-R"
|
88
|
+
end
|
89
|
+
|
90
|
+
# tmux prefix
|
91
|
+
item "[Only Terminal] Command-R -> Option-R", only: "TERMINAL" do
|
92
|
+
remap "Cmd-R", to: "M-r"
|
93
|
+
end
|
94
|
+
|
95
|
+
# I don't want to press shift key
|
96
|
+
item "Command semicolon to colon" do
|
97
|
+
remap "Cmd-;", to: "Shift-;"
|
98
|
+
end
|
99
|
+
|
100
|
+
item "Shift by control" do
|
101
|
+
remap "C--", to: "Shift--"
|
102
|
+
remap "C-0", to: "Shift-0"
|
103
|
+
remap "C-9", to: "Shift-9"
|
104
|
+
remap "C-8", to: "Shift-8"
|
105
|
+
remap "C-7", to: "Shift-7"
|
106
|
+
remap "C-6", to: "Shift-6"
|
107
|
+
remap "C-[", to: "Shift-["
|
108
|
+
remap "C-]", to: "Shift-]"
|
109
|
+
remap "C-;", to: "Shift-;"
|
110
|
+
remap "C-,", to: "Shift-,"
|
111
|
+
remap "C-.", to: "Shift-."
|
112
|
+
remap "C-/", to: "Shift-/"
|
113
|
+
remap "C-=", to: "Shift-="
|
114
|
+
remap "C-\\", to: "Shift-\\"
|
115
|
+
end
|
116
|
+
|
117
|
+
item "Exchange single quote and double quote" do
|
118
|
+
remap "'", to: "Shift-'"
|
119
|
+
remap "Shift-'", to: "'"
|
120
|
+
end
|
121
|
+
|
122
|
+
item "[Only Terminal] Command+A to Option+A", only: "TERMINAL" do
|
123
|
+
remap "Cmd-A", to: "M-a"
|
124
|
+
end
|
125
|
+
|
126
|
+
item "Disable Command-W" do
|
127
|
+
remap "Cmd-W", to: "w"
|
128
|
+
end
|
129
|
+
|
130
|
+
appdef "YORUFUKUROU", equal: "com.YoruFukurouProject.YoruFukurou"
|
131
|
+
|
132
|
+
item "YoruFukurou Account Change", only: "YORUFUKUROU" do
|
133
|
+
remap "Cmd-K", to: "Cmd-Opt-Up"
|
134
|
+
remap "Cmd-J", to: "Cmd-Opt-Down"
|
135
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Dotremap::Appdef
|
2
|
+
AVAILABLE_OPTIONS = %i(
|
3
|
+
equal
|
4
|
+
prefix
|
5
|
+
suffix
|
6
|
+
).freeze
|
7
|
+
|
8
|
+
def initialize(appname, options)
|
9
|
+
@childs = []
|
10
|
+
@appname = appname
|
11
|
+
|
12
|
+
options.each do |option, value|
|
13
|
+
raise "Unavailable option: #{property}" unless AVAILABLE_OPTIONS.include?(option)
|
14
|
+
@childs << Dotremap::Property.new(option, value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_xml
|
19
|
+
[
|
20
|
+
"<appdef>",
|
21
|
+
" <appname>#{@appname}</appname>",
|
22
|
+
@childs.map(&:to_xml).join("\n").gsub(/^/, " "),
|
23
|
+
"</appdef>",
|
24
|
+
].join("\n")
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "dotremap/dsl"
|
2
|
+
require "dotremap/property"
|
3
|
+
require "dotremap/remap"
|
4
|
+
|
5
|
+
module Dotremap::DSL::Item
|
6
|
+
AVAILABLE_PROPERTIES = %i(
|
7
|
+
name
|
8
|
+
identifier
|
9
|
+
autogen
|
10
|
+
).freeze
|
11
|
+
|
12
|
+
def remap(target, options = {})
|
13
|
+
remap = Dotremap::Remap.new(target, options[:to])
|
14
|
+
childs << remap
|
15
|
+
end
|
16
|
+
|
17
|
+
def show_message(message)
|
18
|
+
property = Dotremap::Property.new("autogen", "__ShowStatusMessage__ #{message}")
|
19
|
+
childs << property
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def method_missing(property, value = '', options = {})
|
25
|
+
if AVAILABLE_PROPERTIES.include?(property)
|
26
|
+
property = Dotremap::Property.new(property, value, options)
|
27
|
+
childs << property
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "dotremap/appdef"
|
2
|
+
require "dotremap/dsl"
|
3
|
+
require "dotremap/item"
|
4
|
+
|
5
|
+
module Dotremap::DSL::Root
|
6
|
+
def item(name = nil, options = {}, &block)
|
7
|
+
item = Dotremap::Item.new(name, options)
|
8
|
+
item.instance_exec(&block)
|
9
|
+
childs << item
|
10
|
+
end
|
11
|
+
|
12
|
+
def appdef(appname = '', options = {})
|
13
|
+
appdef = Dotremap::Appdef.new(appname, options)
|
14
|
+
childs << appdef
|
15
|
+
end
|
16
|
+
end
|
data/lib/dotremap/dsl.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "dotremap/dsl/item"
|
2
|
+
|
3
|
+
class Dotremap::Item
|
4
|
+
include Dotremap::DSL::Item
|
5
|
+
|
6
|
+
AVAILABLE_OPTIONS = %i(
|
7
|
+
not
|
8
|
+
only
|
9
|
+
config_not
|
10
|
+
config_only
|
11
|
+
).freeze
|
12
|
+
|
13
|
+
def initialize(name, options)
|
14
|
+
@childs = []
|
15
|
+
|
16
|
+
if name
|
17
|
+
@childs << Dotremap::Property.new("name", name)
|
18
|
+
end
|
19
|
+
|
20
|
+
options.each do |option, value|
|
21
|
+
raise "Unavailable option: #{option}" unless AVAILABLE_OPTIONS.include?(option)
|
22
|
+
@childs << Dotremap::Property.new(option, value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
attr_accessor :childs
|
26
|
+
|
27
|
+
def to_xml
|
28
|
+
validate_name_existence
|
29
|
+
generate_identifier
|
30
|
+
|
31
|
+
[
|
32
|
+
"<item>",
|
33
|
+
childs.map(&:to_xml).join("\n").gsub(/^/, " "),
|
34
|
+
"</item>",
|
35
|
+
].join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def validate_name_existence
|
41
|
+
properties = childs.select { |c| c.is_a?(Dotremap::Property) }
|
42
|
+
raise "Name property does not exist" unless properties.map(&:attr).include?("name")
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_identifier
|
46
|
+
properties = childs.select { |c| c.is_a?(Dotremap::Property) }
|
47
|
+
return if properties.map(&:attr).include?("identifier")
|
48
|
+
|
49
|
+
name = properties.find { |p| p.attr == "name" }
|
50
|
+
generated_identifier = name.value.gsub(/[^a-zA-Z]/, "_").downcase
|
51
|
+
identifier = Dotremap::Property.new("identifier", "remap.#{generated_identifier}")
|
52
|
+
childs[1, 0] = identifier
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Dotremap::Property
|
2
|
+
def initialize(attr, value, options = {})
|
3
|
+
@attr = attr.to_s
|
4
|
+
@value = value
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
attr_accessor :attr, :value, :options
|
8
|
+
|
9
|
+
def to_xml
|
10
|
+
open_tag = options.map { |a, v| "#{a}=\"#{v}\"" }.unshift(attr).join(" ")
|
11
|
+
"<#{open_tag}>#{value}</#{attr}>"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
class Dotremap::Remap
|
2
|
+
KEYCODE_MAP = {
|
3
|
+
"0" => "KEY_0",
|
4
|
+
"1" => "KEY_1",
|
5
|
+
"2" => "KEY_2",
|
6
|
+
"3" => "KEY_3",
|
7
|
+
"4" => "KEY_4",
|
8
|
+
"5" => "KEY_5",
|
9
|
+
"6" => "KEY_6",
|
10
|
+
"7" => "KEY_7",
|
11
|
+
"8" => "KEY_8",
|
12
|
+
"9" => "KEY_9",
|
13
|
+
"Up" => "CURSOR_UP",
|
14
|
+
"Down" => "CURSOR_DOWN",
|
15
|
+
"Right" => "CURSOR_RIGHT",
|
16
|
+
"Left" => "CURSOR_LEFT",
|
17
|
+
"]" => "BRACKET_RIGHT",
|
18
|
+
"[" => "BRACKET_LEFT",
|
19
|
+
";" => "SEMICOLON",
|
20
|
+
"-" => "MINUS",
|
21
|
+
"," => "COMMA",
|
22
|
+
"." => "DOT",
|
23
|
+
"\\" => "BACKSLASH",
|
24
|
+
"/" => "SLASH",
|
25
|
+
"=" => "EQUAL",
|
26
|
+
"'" => "QUOTE",
|
27
|
+
"Ctrl_R" => "CONTROL_R",
|
28
|
+
"Ctrl_L" => "CONTROL_L",
|
29
|
+
"Opt_R" => "OPTION_R",
|
30
|
+
"Opt_L" => "OPTION_L",
|
31
|
+
"Cmd_R" => "COMMAND_R",
|
32
|
+
"Cmd_L" => "COMMAND_L",
|
33
|
+
}.freeze
|
34
|
+
PREFIX_MAP = {
|
35
|
+
"C" => "VK_CONTROL",
|
36
|
+
"Ctrl" => "VK_CONTROL",
|
37
|
+
"Cmd" => "VK_COMMAND",
|
38
|
+
"Shift" => "VK_SHIFT",
|
39
|
+
"M" => "VK_OPTION",
|
40
|
+
"Opt" => "VK_OPTION",
|
41
|
+
}.freeze
|
42
|
+
PREFIX_EXPRESSION = "(#{PREFIX_MAP.keys.map { |k| k + '-' }.join('|')})"
|
43
|
+
|
44
|
+
def initialize(from, to)
|
45
|
+
@from = from
|
46
|
+
@to = to
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_xml
|
50
|
+
"<autogen>__KeyToKey__ #{from}, #{to}</autogen>"
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def from
|
56
|
+
key_combination(@from)
|
57
|
+
end
|
58
|
+
|
59
|
+
def to
|
60
|
+
[@to].flatten.map { |to| key_combination(to) }.join(", ")
|
61
|
+
end
|
62
|
+
|
63
|
+
def key_combination(raw_combination)
|
64
|
+
raw_prefixes, raw_key = split_key_combination(raw_combination)
|
65
|
+
return key_expression(raw_key) if raw_prefixes.empty?
|
66
|
+
|
67
|
+
prefixes = raw_prefixes.map { |raw_prefix| PREFIX_MAP[raw_prefix] }
|
68
|
+
"#{key_expression(raw_key)}, #{prefixes.join(' | ')}"
|
69
|
+
end
|
70
|
+
|
71
|
+
def key_expression(raw_key)
|
72
|
+
case raw_key
|
73
|
+
when /^(#{KEYCODE_MAP.keys.map { |k| Regexp.escape(k) }.join('|')})$/
|
74
|
+
"KeyCode::#{KEYCODE_MAP[raw_key]}"
|
75
|
+
else
|
76
|
+
raw_key = raw_key.upcase unless raw_key.match(/^VK_/)
|
77
|
+
"KeyCode::#{raw_key}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def split_key_combination(raw_combination)
|
82
|
+
prefixes = []
|
83
|
+
key = raw_combination.dup
|
84
|
+
|
85
|
+
while key.match(/^#{PREFIX_EXPRESSION}/)
|
86
|
+
key.gsub!(/^#{PREFIX_EXPRESSION}/) do
|
87
|
+
prefixes << $1.gsub(/-$/, "")
|
88
|
+
""
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
[prefixes, key]
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "dotremap/dsl/root"
|
2
|
+
|
3
|
+
class Dotremap::Root
|
4
|
+
include Dotremap::DSL::Root
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@childs = []
|
8
|
+
end
|
9
|
+
attr_accessor :childs
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
[
|
13
|
+
"<?xml version=\"1.0\"?>",
|
14
|
+
"<root>",
|
15
|
+
childs.map(&:to_xml).join("\n\n").gsub(/^/, " "),
|
16
|
+
"</root>",
|
17
|
+
].join("\n")
|
18
|
+
end
|
19
|
+
end
|
data/lib/dotremap.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "dotremap/version"
|
2
|
+
require "dotremap/root"
|
3
|
+
require "unindent"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
class Dotremap
|
7
|
+
OLD_XML_DIR = File.expand_path("~/Library/Application Support/KeyRemap4MacBook")
|
8
|
+
NEW_XML_DIR = File.expand_path("~/Library/Application Support/Karabiner")
|
9
|
+
XML_FILE_NAME = "private.xml"
|
10
|
+
|
11
|
+
def initialize(config_path)
|
12
|
+
@config_path = config_path
|
13
|
+
@root = Root.new
|
14
|
+
end
|
15
|
+
attr_reader :config_path, :root
|
16
|
+
|
17
|
+
def compile
|
18
|
+
validate_config_existence
|
19
|
+
|
20
|
+
config = File.read(config_path)
|
21
|
+
root.instance_eval(config)
|
22
|
+
end
|
23
|
+
|
24
|
+
def replace_private_xml
|
25
|
+
ensure_xml_dir_existence
|
26
|
+
remove_current_xml
|
27
|
+
write_new_xml
|
28
|
+
puts "Successfully generated private.xml"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def validate_config_existence
|
34
|
+
return if File.exists?(config_path)
|
35
|
+
|
36
|
+
File.write(config_path, <<-EOS.unindent)
|
37
|
+
#!/usr/bin/env ruby
|
38
|
+
|
39
|
+
# # Example
|
40
|
+
# item "Command+E to Command+W", not: "TERMINAL" do
|
41
|
+
# identifier "option.not_terminal_opt_e"
|
42
|
+
# autogen "__KeyToKey__ KeyCode::E, VK_COMMAND, KeyCode::W, ModifierFlag::COMMAND_L"
|
43
|
+
# end
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
|
47
|
+
def ensure_xml_dir_existence
|
48
|
+
FileUtils.mkdir_p(OLD_XML_DIR)
|
49
|
+
FileUtils.mkdir_p(NEW_XML_DIR)
|
50
|
+
end
|
51
|
+
|
52
|
+
def remove_current_xml
|
53
|
+
FileUtils.rm_f(File.join(OLD_XML_DIR, XML_FILE_NAME))
|
54
|
+
FileUtils.rm_f(File.join(NEW_XML_DIR, XML_FILE_NAME))
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_new_xml
|
58
|
+
File.write(File.join(OLD_XML_DIR, XML_FILE_NAME), root.to_xml)
|
59
|
+
File.write(File.join(NEW_XML_DIR, XML_FILE_NAME), root.to_xml)
|
60
|
+
end
|
61
|
+
end
|
data/reload.gif
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dotremap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takashi Kokubun
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-12 00:00:00.000000000 Z
|
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: rake
|
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: unindent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
description: Configuration DSL for KeyRemap4MacBook
|
56
|
+
email:
|
57
|
+
- takashikkbn@gmail.com
|
58
|
+
executables:
|
59
|
+
- dotremap
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/dotremap
|
69
|
+
- dotremap.gemspec
|
70
|
+
- example.rb
|
71
|
+
- lib/dotremap.rb
|
72
|
+
- lib/dotremap/appdef.rb
|
73
|
+
- lib/dotremap/dsl.rb
|
74
|
+
- lib/dotremap/dsl/item.rb
|
75
|
+
- lib/dotremap/dsl/root.rb
|
76
|
+
- lib/dotremap/item.rb
|
77
|
+
- lib/dotremap/property.rb
|
78
|
+
- lib/dotremap/remap.rb
|
79
|
+
- lib/dotremap/root.rb
|
80
|
+
- lib/dotremap/version.rb
|
81
|
+
- reload.gif
|
82
|
+
homepage: https://github.com/k0kubun/dotremap
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Configuration DSL for KeyRemap4MacBook
|
106
|
+
test_files: []
|