initial
This commit is contained in:
9
Makefile
Normal file
9
Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
INSTALL_DIR=/usr/local/bin
|
||||
|
||||
install:
|
||||
pip3 install -Ur requirements.txt
|
||||
cp alacritty_config.py ${INSTALL_DIR}/alacritty-config
|
||||
chmod u+x ${INSTALL_DIR}/alacritty-config
|
||||
|
||||
uninstall:
|
||||
rm ${INSTALL_DIR}/alacritty-config
|
59
README.md
Normal file
59
README.md
Normal file
@@ -0,0 +1,59 @@
|
||||
# alacritty-config
|
||||
|
||||
A simple Python script to simplify configuring my alacritty.
|
||||
|
||||
## Installation
|
||||
|
||||
You can install `alacritty-config` by cloning this repository and running `make
|
||||
install`. By default, it will be installed in `/usr/local/bin`, but you can set a
|
||||
different `INSTALL_DIR` if you like.
|
||||
|
||||
Uninstall it using `make uninstall`.
|
||||
|
||||
## Usage
|
||||
|
||||
`alacritty-config` has three different modes: show, add, and delete.
|
||||
|
||||
Calling the program without any arguments will dump your entire config: you’re in show
|
||||
mode, but you haven’t selected anything. If you want to know the value of the `tabspaces`
|
||||
property, call `alacritty-config` with just that argument. If you want to know the action
|
||||
of your third key binding, call it with `key_bindings.2.action`—we’re 0-indexed.
|
||||
|
||||
```
|
||||
$ alacritty-config
|
||||
<your entire config>
|
||||
|
||||
$ alacritty-config tabspaces
|
||||
8 # or whatever you set it to
|
||||
|
||||
$ alacritty-config key_bindings.2.action
|
||||
Paste # or whatever you set it to
|
||||
```
|
||||
|
||||
If you want to delete a property, simply add `delete`.
|
||||
|
||||
```
|
||||
$ alacritty-config tabspaces delete
|
||||
# Poof! It’s gone!
|
||||
```
|
||||
|
||||
If you want to add or edit a property, simply add a different YAML-parseable property.
|
||||
If you want to set something to `delete`, simply quote it.
|
||||
|
||||
```
|
||||
$ alacritty-config tabspaces 4
|
||||
# Set tabspaces to 4
|
||||
|
||||
$ alacritty-config tabspaces '"delete"'
|
||||
# Set tabspaces to "delete", which won’t work
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
Oh, so much! Ideally, I’d like a GUI at least for all the colorful properties and for
|
||||
selecting fonts. For now the tool is simple and usable enough to be useful, but a simple
|
||||
GUI would definitely give this a better UX. Another time.
|
||||
|
||||
<hr/>
|
||||
|
||||
Have fun!
|
91
alacritty_config.py
Normal file
91
alacritty_config.py
Normal file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import sys
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
ALACRITTY_CONFIG = os.path.expanduser("~/.config/alacritty/alacritty.yml")
|
||||
|
||||
|
||||
class Action:
|
||||
mutating = False
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
|
||||
def traverse(self, yml):
|
||||
for p in self.path:
|
||||
yml = yml[p]
|
||||
return yml
|
||||
|
||||
|
||||
class ShowAction(Action):
|
||||
def act_on(self, yml):
|
||||
yml = self.traverse(yml)
|
||||
if type(yml) is dict:
|
||||
print(yaml.dump(yml))
|
||||
else:
|
||||
print(yml)
|
||||
|
||||
|
||||
class EditAction(Action):
|
||||
mutating = True
|
||||
def __init__(self, path):
|
||||
self.path = path[:-1]
|
||||
self.prop = path[-1]
|
||||
|
||||
|
||||
class AddAction(EditAction):
|
||||
def __init__(self, path, val):
|
||||
super().__init__(path)
|
||||
self.val = yaml.safe_load(val)
|
||||
|
||||
def act_on(self, yml):
|
||||
yml = self.traverse(yml)
|
||||
yml[self.prop] = self.val
|
||||
|
||||
|
||||
class DeleteAction(EditAction):
|
||||
def act_on(self, yml):
|
||||
yml = self.traverse(yml)
|
||||
del yml[self.prop]
|
||||
|
||||
|
||||
def parse_path(p):
|
||||
if p.isdigit():
|
||||
return int(p)
|
||||
return p
|
||||
|
||||
|
||||
def parse_action():
|
||||
args = sys.argv
|
||||
|
||||
if len(args) == 1:
|
||||
return ShowAction([])
|
||||
|
||||
path = [parse_path(a) for a in args[1].split('.')]
|
||||
if len(args) == 2:
|
||||
return ShowAction(path)
|
||||
|
||||
if len(args) == 3 and args[2] == 'delete':
|
||||
return DeleteAction(path)
|
||||
|
||||
return AddAction(path, args[2])
|
||||
|
||||
|
||||
def main():
|
||||
action = parse_action()
|
||||
|
||||
try:
|
||||
with open(ALACRITTY_CONFIG) as f:
|
||||
y = yaml.safe_load(f.read())
|
||||
action.act_on(y)
|
||||
if action.mutating:
|
||||
with open(ALACRITTY_CONFIG, "w+") as f:
|
||||
f.write(yaml.dump(y))
|
||||
except KeyError as e:
|
||||
print('Key "{}" was not found in alacritty config!'.format(e))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
pyyaml
|
Reference in New Issue
Block a user