Migrate to Jinja templates
This commit is contained in:
parent
88255140d1
commit
47de35844a
21 changed files with 103 additions and 120 deletions
2
Pipfile
2
Pipfile
|
@ -4,12 +4,12 @@ verify_ssl = true
|
|||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
mako = "*"
|
||||
toml = "*"
|
||||
pyyaml = "*"
|
||||
requests = "*"
|
||||
requests-cache = "*"
|
||||
attrs = "*"
|
||||
cattrs = "*"
|
||||
jinja2 = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
|
20
Pipfile.lock
generated
20
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "3b96d3b70c9cd62e42cf05545b406ce7aba31fe6b71050e7f6f71dfe3afe7624"
|
||||
"sha256": "fc47da1b3ed38e959a395151eeda0547cf4399f14ebe255028e1465586bbe20b"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
|
@ -146,14 +146,14 @@
|
|||
"markers": "python_version >= '3.6'",
|
||||
"version": "==3.10"
|
||||
},
|
||||
"mako": {
|
||||
"jinja2": {
|
||||
"hashes": [
|
||||
"sha256:42f48953c7eb91332040ff567eb7eea69b22e7a4affbc5ba8e845e8f730f6627",
|
||||
"sha256:577b97e414580d3e088d47c2dbbe9594aa7a5146ed2875d4dfa9075af2dd3cc8"
|
||||
"sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d",
|
||||
"sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version >= '3.8'",
|
||||
"version": "==1.3.8"
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==3.1.6"
|
||||
},
|
||||
"markupsafe": {
|
||||
"hashes": [
|
||||
|
@ -308,14 +308,6 @@
|
|||
"markers": "python_version >= '3.8'",
|
||||
"version": "==1.2.1"
|
||||
},
|
||||
"six": {
|
||||
"hashes": [
|
||||
"sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274",
|
||||
"sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
|
||||
"version": "==1.17.0"
|
||||
},
|
||||
"toml": {
|
||||
"hashes": [
|
||||
"sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
|
||||
|
|
21
install.py
21
install.py
|
@ -15,8 +15,7 @@ from typing import List
|
|||
|
||||
from attrs import define, field
|
||||
import cattrs
|
||||
import mako.lookup
|
||||
import mako.template
|
||||
import jinja2
|
||||
import requests_cache
|
||||
import toml
|
||||
import yaml
|
||||
|
@ -224,7 +223,6 @@ def main():
|
|||
dotfiles_dir: Path = args.dotfiles
|
||||
raw_dir = dotfiles_dir / "raw"
|
||||
templates_dir = dotfiles_dir / "templates"
|
||||
include_dir = dotfiles_dir / "include"
|
||||
host_filename = dotfiles_dir / "hosts" / "{}.toml".format(args.hostname)
|
||||
|
||||
host_toml = {
|
||||
|
@ -277,11 +275,9 @@ def main():
|
|||
print("Could not contact sway or niri to retrieve output names.")
|
||||
print("Please re-run in sway or niri to finish configuring swaylock.")
|
||||
|
||||
lookup = mako.lookup.TemplateLookup(
|
||||
directories=[
|
||||
str(templates_dir),
|
||||
str(include_dir),
|
||||
],
|
||||
jenv = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader("templates"),
|
||||
autoescape=jinja2.select_autoescape(),
|
||||
)
|
||||
|
||||
changed_paths = set()
|
||||
|
@ -302,15 +298,12 @@ def main():
|
|||
if not template_path.is_file():
|
||||
continue
|
||||
rel_path = template_path.relative_to(templates_dir)
|
||||
output_path = args.home / template_path.relative_to(templates_dir)
|
||||
output_path: Path = args.home / template_path.relative_to(templates_dir)
|
||||
output_path = output_path.with_name(output_path.name.removesuffix(".j2"))
|
||||
|
||||
if args.force or is_outdated([template_path, host_filename], output_path):
|
||||
print(rel_path)
|
||||
template = mako.template.Template(
|
||||
filename=str(template_path),
|
||||
strict_undefined=True,
|
||||
lookup=lookup,
|
||||
)
|
||||
template = jenv.get_template(str(rel_path))
|
||||
output = template.render(
|
||||
host=host_config,
|
||||
home=args.home,
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
${get_base16('wofi-colors')}
|
1
templates/.cache/wal/colors.j2
Normal file
1
templates/.cache/wal/colors.j2
Normal file
|
@ -0,0 +1 @@
|
|||
{{ get_base16('wofi-colors') }}
|
|
@ -1,5 +1,5 @@
|
|||
[font]
|
||||
size = ${10 if host.is_virtual else 12}
|
||||
size = {{ 10 if host.is_virtual else 12 }}
|
||||
|
||||
[font.bold]
|
||||
family = "Fira Mono"
|
||||
|
@ -10,4 +10,4 @@ family = "Fira Mono"
|
|||
[window]
|
||||
opacity = 0.9
|
||||
|
||||
${get_base16('alacritty')}
|
||||
{{ get_base16('alacritty') }}
|
|
@ -3,5 +3,4 @@
|
|||
origin = bottom-center
|
||||
font = "DejaVu Sans Mono 10"
|
||||
|
||||
${get_base16('dunst')}
|
||||
|
||||
{{ get_base16('dunst') }}
|
|
@ -3,23 +3,23 @@ general {
|
|||
interval = 5
|
||||
}
|
||||
|
||||
${get_base16('i3status')}
|
||||
{{ get_base16('i3status') }}
|
||||
|
||||
% for iface in host.wireless:
|
||||
wireless ${iface} {
|
||||
format_up = "${iface} %ip %essid %quality"
|
||||
format_down = "${iface} down"
|
||||
{% for iface in host.wireless %}
|
||||
wireless {{ iface }} {
|
||||
format_up = "{{ iface }} %ip %essid %quality"
|
||||
format_down = "{{ iface }} down"
|
||||
}
|
||||
order += "wireless ${iface}"
|
||||
% endfor
|
||||
order += "wireless {{ iface }}"
|
||||
{% endfor %}
|
||||
|
||||
% for iface in host.ethernet:
|
||||
ethernet ${iface} {
|
||||
format_up = "${iface} %ip"
|
||||
format_down = "${iface} down"
|
||||
{% for iface in host.ethernet %}
|
||||
ethernet {{ iface }} {
|
||||
format_up = "{{ iface }} %ip"
|
||||
format_down = "{{ iface }} down"
|
||||
}
|
||||
order += "ethernet ${iface}"
|
||||
% endfor
|
||||
order += "ethernet {{ iface }}"
|
||||
{% endfor %}
|
||||
|
||||
volume default {
|
||||
format = "vol %volume"
|
||||
|
@ -38,12 +38,12 @@ battery all {
|
|||
}
|
||||
order += "battery all"
|
||||
|
||||
% for disk in host.disks:
|
||||
disk "${disk}" {
|
||||
format = "${disk} %avail"
|
||||
{% for disk in host.disks %}
|
||||
disk "{{ disk }}" {
|
||||
format = "{{ disk }} %avail"
|
||||
}
|
||||
order += "disk ${disk}"
|
||||
% endfor
|
||||
order += "disk {{ disk }}"
|
||||
{% endfor %}
|
||||
|
||||
cpu_usage {
|
||||
format = "cpu %usage"
|
||||
|
@ -59,13 +59,13 @@ memory {
|
|||
}
|
||||
order += "memory"
|
||||
|
||||
% if host.temperature_path:
|
||||
{% if host.temperature_path %}
|
||||
cpu_temperature 0 {
|
||||
format = "temp %degrees°C"
|
||||
path = "${host.temperature_path}"
|
||||
path = "{{ host.temperature_path }}"
|
||||
}
|
||||
order += "cpu_temperature 0"
|
||||
% endif
|
||||
{% endif %}
|
||||
|
||||
tztime utc {
|
||||
format = "%Y-%m-%d %H:%M:%S"
|
|
@ -61,12 +61,12 @@ input {
|
|||
disable-power-key-handling
|
||||
}
|
||||
|
||||
% for output in host.outputs:
|
||||
output "${output.match}" {
|
||||
${output.niri_lines}
|
||||
{% for output in host.outputs %}
|
||||
output "{{ output.match }}" {
|
||||
{{ output.niri_lines }}
|
||||
}
|
||||
|
||||
% endfor
|
||||
{% endfor %}
|
||||
|
||||
// Settings that influence how windows are positioned and sized.
|
||||
// Find more information on the wiki:
|
||||
|
@ -100,7 +100,7 @@ layout {
|
|||
// preset-window-heights { }
|
||||
|
||||
// You can change the default width of the new windows.
|
||||
default-column-width { proportion ${host.niri.default_column_width}; }
|
||||
default-column-width { proportion {{ host.niri.default_column_width }}; }
|
||||
// If you leave the brackets empty, the windows themselves will decide their initial width.
|
||||
// default-column-width {}
|
||||
|
|
@ -27,7 +27,7 @@ set $kdown j
|
|||
set $kup k
|
||||
set $kright l
|
||||
|
||||
${get_base16('i3', 'colors')}
|
||||
{{ get_base16('i3', 'colors') }}
|
||||
|
||||
# property border bg text indic child
|
||||
client.focused $base0D $base0D $base00 $base0E $base0D
|
||||
|
@ -37,17 +37,17 @@ client.urgent $base08 $base08 $base00 $base08 $base08
|
|||
client.placeholder $base01 $base01 $base05 $base01 $base01
|
||||
client.background $base07
|
||||
|
||||
% for output in host.outputs:
|
||||
output ${repr(output.match)} {
|
||||
${output.sway_lines}
|
||||
{% for output in host.outputs %}
|
||||
output "{{ output.match }}" {
|
||||
{{ output.sway_lines }}
|
||||
}
|
||||
% endfor
|
||||
{% endfor %}
|
||||
|
||||
% for input in host.inputs:
|
||||
input ${repr(input.match)} {
|
||||
${input.sway_lines}
|
||||
{% for input in host.inputs %}
|
||||
input "{{ input.match }}" {
|
||||
{{ input.sway_lines }}
|
||||
}
|
||||
%endfor
|
||||
{% endfor %}
|
||||
|
||||
gaps inner 8
|
||||
|
||||
|
@ -73,7 +73,7 @@ exec dunst
|
|||
exec udiskie
|
||||
exec fcitx5
|
||||
|
||||
font pango:${host.system_mono_font} 8
|
||||
font pango:{{ host.system_mono_font }} 8
|
||||
focus_follows_mouse no
|
||||
|
||||
floating_modifier $mod
|
||||
|
@ -82,14 +82,14 @@ bindsym $mod+Shift+c reload
|
|||
bindsym $mod+Shift+r restart
|
||||
bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'
|
||||
bindsym $mod+Shift+q kill
|
||||
bindsym $mod+Shift+p exec ${host.lock_cmd}
|
||||
bindsym $mod+Shift+p exec {{ host.lock_cmd }}
|
||||
|
||||
# Blank individual displays
|
||||
bindsym $mod+o output - dpms off
|
||||
# Unblank all displays
|
||||
bindsym $mod+Shift+o output * dpms on
|
||||
|
||||
bindsym $mod+Return exec ${host.terminal}
|
||||
bindsym $mod+Return exec {{ host.terminal }}
|
||||
bindsym $mod+d exec wofi --show drun
|
||||
bindsym $mod+Shift+d exec wofi --show run
|
||||
bindsym $mod+p exec wofi-pass
|
||||
|
@ -181,9 +181,9 @@ bindsym XF86AudioPlay exec playerctl play-pause
|
|||
bar {
|
||||
tray_output none
|
||||
status_command i3status
|
||||
font pango:${host.system_mono_font} 10
|
||||
font pango:{{ host.system_mono_font }} 10
|
||||
|
||||
${get_base16('i3', 'bar-colors')}
|
||||
{{ get_base16('i3', 'bar-colors') }}
|
||||
|
||||
colors {
|
||||
background $base01
|
|
@ -1 +0,0 @@
|
|||
timeout 10 'pgrep swaylock && ${host.display_off_cmd}' resume 'pgrep swaylock && ${host.display_on_cmd}'
|
1
templates/.config/swayidle/config.j2
Normal file
1
templates/.config/swayidle/config.j2
Normal file
|
@ -0,0 +1 @@
|
|||
timeout 10 'pgrep swaylock && {{ host.display_off_cmd }}' resume 'pgrep swaylock && {{ host.display_on_cmd }}'
|
|
@ -2,7 +2,7 @@ ignore-empty-password
|
|||
indicator-idle-visible
|
||||
color=000000
|
||||
scaling=fill
|
||||
font=${host.system_font}
|
||||
font={{ host.system_font }}
|
||||
|
||||
|
||||
${host.swaylock_images}
|
||||
{{ host.swaylock_images }}
|
|
@ -12,13 +12,13 @@
|
|||
],
|
||||
"modules-right": [
|
||||
|
||||
% for iface in host.wireless + host.ethernet:
|
||||
"network#${iface}",
|
||||
% endfor
|
||||
{% for iface in host.wireless + host.ethernet %}
|
||||
"network#{{ iface }}",
|
||||
{% endfor %}
|
||||
|
||||
% if not host.ethernet and host.auto_ethernet:
|
||||
{% if not host.ethernet and host.auto_ethernet %}
|
||||
"network#auto_ethernet",
|
||||
% endif
|
||||
{% endif %}
|
||||
|
||||
"wireplumber",
|
||||
"battery",
|
||||
|
@ -26,43 +26,43 @@
|
|||
"cpu",
|
||||
"memory",
|
||||
|
||||
% if host.temperature_path:
|
||||
{% if host.temperature_path %}
|
||||
"temperature",
|
||||
% endif
|
||||
{% endif %}
|
||||
|
||||
"clock#utc",
|
||||
"clock#local"
|
||||
],
|
||||
|
||||
% for iface in host.wireless:
|
||||
"network#${iface}": {
|
||||
"interface": "${iface}",
|
||||
{% for iface in host.wireless %}
|
||||
"network#{{ iface }}": {
|
||||
"interface": "{{ iface }}",
|
||||
"format": "\uf1eb \uf058",
|
||||
"format-disconnected": "\uf1eb \uf057",
|
||||
"tooltip-format": "${iface} {ipaddr} {essid} {signalStrength}",
|
||||
"tooltip-format-disconnected": "${iface} down"
|
||||
"tooltip-format": "{{ iface }} {ipaddr} {essid} {signalStrength}",
|
||||
"tooltip-format-disconnected": "{{ iface }} down"
|
||||
},
|
||||
% endfor
|
||||
{% endfor %}
|
||||
|
||||
% for iface in host.ethernet:
|
||||
"network#${iface}": {
|
||||
"interface": "${iface}",
|
||||
{% for iface in host.ethernet %}
|
||||
"network#{{ iface }}": {
|
||||
"interface": "{{ iface }}",
|
||||
"format": "\uf6ff \uf058",
|
||||
"format-disconnected": "\uf6ff \uf057",
|
||||
"tooltip-format": "${iface} {ipaddr}",
|
||||
"tooltip-format-disconnected": "${iface} down"
|
||||
"tooltip-format": "{{ iface }} {ipaddr}",
|
||||
"tooltip-format-disconnected": "{{ iface }} down"
|
||||
},
|
||||
% endfor
|
||||
{% endfor %}
|
||||
|
||||
% if not host.ethernet and host.auto_ethernet:
|
||||
{% if not host.ethernet and host.auto_ethernet %}
|
||||
"network#auto_ethernet": {
|
||||
"interface": "en*",
|
||||
"format": "\uf6ff \uf058",
|
||||
"format-disconnected": "\uf6ff \uf057",
|
||||
"tooltip-format": "${iface} {ipaddr}",
|
||||
"tooltip-format-disconnected": "${iface} down"
|
||||
"tooltip-format": "{{ iface }} {ipaddr}",
|
||||
"tooltip-format-disconnected": "{{ iface }} down"
|
||||
},
|
||||
% endif
|
||||
{% endif %}
|
||||
|
||||
"wireplumber": {
|
||||
"format": "{icon} {volume}%",
|
||||
|
@ -70,7 +70,7 @@
|
|||
"format-icons": ["\uf026", "\uf027", "\uf028"]
|
||||
},
|
||||
|
||||
% if host.has_battery:
|
||||
{% if host.has_battery %}
|
||||
"battery": {
|
||||
"design-capacity": true,
|
||||
"format": "{icon} {capacity}% {time}",
|
||||
|
@ -85,26 +85,26 @@
|
|||
"format-charging": "\ue55b {capacity}% {time}",
|
||||
"format-full": "\ue55c {capacity}%",
|
||||
},
|
||||
% endif
|
||||
{% endif %}
|
||||
|
||||
"group/disks": {
|
||||
// TODO: make drawer that expands orthogonally, outside of the bar
|
||||
"orientation": "inherit",
|
||||
"modules": [
|
||||
% for disk in host.disks:
|
||||
"disk#${disk}",
|
||||
% endfor
|
||||
{% for disk in host.disks %}
|
||||
"disk#{{ disk }}",
|
||||
{% endfor %}
|
||||
],
|
||||
"drawer": {}
|
||||
},
|
||||
|
||||
% for disk in host.disks:
|
||||
"disk#${disk}": {
|
||||
"path": "${disk}",
|
||||
"format": "${disk} {free}",
|
||||
{% for disk in host.disks %}
|
||||
"disk#{{ disk }}": {
|
||||
"path": "{{ disk }}",
|
||||
"format": "{{ disk }} {free}",
|
||||
"tooltip-format": "{used} / {total} ({percentage_used}%)"
|
||||
},
|
||||
% endfor
|
||||
{% endfor %}
|
||||
|
||||
"cpu": {
|
||||
"format": "\uf2db {usage}%",
|
||||
|
@ -115,12 +115,12 @@
|
|||
"tooltip-format": "{used}GiB / {total}GiB"
|
||||
},
|
||||
|
||||
% if host.temperature_path:
|
||||
{% if host.temperature_path %}
|
||||
"temperature": {
|
||||
"format": "{temperatureC}°C",
|
||||
"hwmon-path": "${host.temperature_path}"
|
||||
"hwmon-path": "{{ host.temperature_path }}"
|
||||
},
|
||||
% endif
|
||||
{% endif %}
|
||||
|
||||
"clock#utc": {
|
||||
"interval": 5,
|
|
@ -1,6 +1,6 @@
|
|||
* {
|
||||
/* `otf-font-awesome` is required to be installed for icons */
|
||||
font-family: '${host.system_mono_font}', 'Font Awesome 6 Free';
|
||||
font-family: '{{ host.system_mono_font }}', 'Font Awesome 6 Free';
|
||||
font-size: 13px;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
window {
|
||||
background-color: --wofi-color1;
|
||||
color: --wofi-color5;
|
||||
font-family: '${host.system_mono_font}';
|
||||
font-family: '{{ host.system_mono_font }}';
|
||||
}
|
||||
|
||||
#input {
|
||||
|
@ -17,4 +17,3 @@ window {
|
|||
#entry:selected {
|
||||
background-color: --wofi-color2;
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
${host.wpaperd_config}
|
1
templates/.config/wpaperd/config.toml.j2
Normal file
1
templates/.config/wpaperd/config.toml.j2
Normal file
|
@ -0,0 +1 @@
|
|||
{{ host.wpaperd_config }}
|
|
@ -3,7 +3,7 @@ AddKeysToAgent confirm
|
|||
Host *.mst.edu
|
||||
User um-ad\ajgq56
|
||||
|
||||
% if host.use_jump_host:
|
||||
{% if host.use_jump_host %}
|
||||
Host *.flock.wg
|
||||
ProxyJump goose@reliant.gaussian.dev
|
||||
% endif
|
||||
{% endif %}
|
|
@ -1 +0,0 @@
|
|||
${get_base16('vim')}
|
1
templates/.vim/colors/base16.vim.j2
Normal file
1
templates/.vim/colors/base16.vim.j2
Normal file
|
@ -0,0 +1 @@
|
|||
{{ get_base16('vim') }}
|
Loading…
Add table
Reference in a new issue