Skip to content

Commit

Permalink
add gen-compose-export command
Browse files Browse the repository at this point in the history
  • Loading branch information
Granitosaurus committed Sep 26, 2022
1 parent 93e57b1 commit d512804
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ _note: Some programs need a hard reboot to take in the map, like `kill -9` sort
Linux's xcompose mappings are supported via experimental conversion:

```
$ gen-compose-conver xcompose --help
$ gen-compose-convert xcompose --help
Usage: gen-compose-convert xcompose [OPTIONS] [FILES]...
Convert xcompose file, that follows format like: <Multi_key> <parenleft>
Expand All @@ -107,13 +107,51 @@ Options:
For example:

```
$ cat mappings/example.compose
$ head mappings/example.compose
<Multi_key> <B> <bar> : "₿" U20BF # BITCOIN SIGN
$ gen-compose-convert xcompose mappings/example.compose --keep-comments > example.yaml
...
$ gen-compose-convert xcompose mappings/xcompose.compose --keep-comments > example.yaml
$ cat example.yaml
"B|": "₿" # BITCOIN SIGN
...
```

## Exporting to XCompose

`gen-compose-export` command can be used export yaml configuration back to XCompose file:

```shell
$ gen-compose-export --help
Usage: gen-compose-export [OPTIONS] YAMLFILE
Export .yaml config file back to XCompose file i.e. this is reverse of
gen-compose-convert
Options:
--help Show this message and exit.
```

For example:

```python
$ head mappings/xcompose.yaml
"..": "…" # HORIZONTAL ELLIPSIS
"v..": "⋮" # VERTICAL ELLIPSIS
...
$ gen-compose-export mappings/xcompose.yaml > xcompose.compose
$ head xcompose.compose
<Multi_key> <period><period>:"…"
<Multi_key> <v><period><period>:"⋮"
<Multi_key> <c><period><period>:"⋯"
<Multi_key> <slash><period><period>:"⋰"
<Multi_key> <period><backslash><period>:"⋱"
<Multi_key> <2><period>:"‥"
<Multi_key> <c><1><period>:"·"
<Multi_key> <period><slash><period>:"⁒"
<Multi_key> <ampersand><at>:"⅋"
<Multi_key> <ampersand><7>:"⁊"
...
```

## Notes and Issues

Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[tool.poetry]
name = "gen-compose"
version = "1.1.0"
version = "1.2.0"
description = "Key generator for macos keybinding system"
authors = ["Granitosaurus <[email protected]>"]
license = "GPL-3.0-or-later"
packages = [
{"include" = "gencompose.py"},
{"include" = "convcompose.py"}
{"include" = "convcompose.py"},
{"include" = "toXcompose.py"},
]
readme = "README.md"
homepage = "https://github.com/Granitosaurus/macos-compose"
Expand All @@ -30,6 +31,8 @@ pytest = "^6.1.0"
[tool.poetry.scripts]
gen-compose = "gencompose:main"
gen-compose-convert = "convcompose:main"
gen-compose-export = "toXcompose:main"


[build-system]
requires = ["poetry>=0.12"]
Expand Down
10 changes: 7 additions & 3 deletions toXcompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@ def get_xcompose_key(key):
kval = i
if i in mapping_dict:
kval = mapping_dict[i]
xval += "<" + kval +"> "
xval += f"<{kval}>"
return xval

def get_xcompose_val(val):
return '"' + val + '"'
return f'"{val}"'

@click.command()
@click.argument('yamlfile', type=click.File())
def main(yamlfile):
"""
Export .yaml config file back to XCompose file
i.e. this is reverse of gen-compose-convert
"""
yamldata = yaml.load(yamlfile.read(), Loader=yaml.Loader)
for k, v in yamldata.items():
xkey = get_xcompose_key(k)
xval = get_xcompose_val(v)
echo(xkey + ":" + xval)
echo(f"{xkey}:{xval}")

if __name__ == '__main__':
main()
Expand Down

0 comments on commit d512804

Please sign in to comment.