diff --git a/Pipfile b/Pipfile index f9c78d1..cce515f 100644 --- a/Pipfile +++ b/Pipfile @@ -4,12 +4,12 @@ verify_ssl = true name = "pypi" [packages] -mako = "*" toml = "*" pyyaml = "*" requests = "*" requests-cache = "*" attrs = "*" cattrs = "*" +jinja2 = "*" [dev-packages] diff --git a/Pipfile.lock b/Pipfile.lock index c2f5b4e..80e5b83 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -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", diff --git a/install.py b/install.py index 6a9db94..ef2f691 100755 --- a/install.py +++ b/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, diff --git a/templates/.cache/wal/colors b/templates/.cache/wal/colors deleted file mode 100644 index 2a710de..0000000 --- a/templates/.cache/wal/colors +++ /dev/null @@ -1 +0,0 @@ -${get_base16('wofi-colors')} diff --git a/templates/.cache/wal/colors.j2 b/templates/.cache/wal/colors.j2 new file mode 100644 index 0000000..7b38a5a --- /dev/null +++ b/templates/.cache/wal/colors.j2 @@ -0,0 +1 @@ +{{ get_base16('wofi-colors') }} diff --git a/templates/.config/alacritty/alacritty.toml b/templates/.config/alacritty/alacritty.toml.j2 similarity index 58% rename from templates/.config/alacritty/alacritty.toml rename to templates/.config/alacritty/alacritty.toml.j2 index e71c82b..a633a60 100644 --- a/templates/.config/alacritty/alacritty.toml +++ b/templates/.config/alacritty/alacritty.toml.j2 @@ -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') }} diff --git a/templates/.config/dunst/dunstrc b/templates/.config/dunst/dunstrc.j2 similarity index 77% rename from templates/.config/dunst/dunstrc rename to templates/.config/dunst/dunstrc.j2 index 34adb2b..4473632 100644 --- a/templates/.config/dunst/dunstrc +++ b/templates/.config/dunst/dunstrc.j2 @@ -3,5 +3,4 @@ origin = bottom-center font = "DejaVu Sans Mono 10" -${get_base16('dunst')} - +{{ get_base16('dunst') }} diff --git a/templates/.config/i3status/config b/templates/.config/i3status/config.j2 similarity index 59% rename from templates/.config/i3status/config rename to templates/.config/i3status/config.j2 index e897be3..45adb48 100644 --- a/templates/.config/i3status/config +++ b/templates/.config/i3status/config.j2 @@ -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" diff --git a/templates/.config/niri/config.kdl b/templates/.config/niri/config.kdl.j2 similarity index 99% rename from templates/.config/niri/config.kdl rename to templates/.config/niri/config.kdl.j2 index 563d0d7..d999050 100644 --- a/templates/.config/niri/config.kdl +++ b/templates/.config/niri/config.kdl.j2 @@ -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 {} diff --git a/templates/.config/sway/config b/templates/.config/sway/config.j2 similarity index 91% rename from templates/.config/sway/config rename to templates/.config/sway/config.j2 index c52f708..16628af 100644 --- a/templates/.config/sway/config +++ b/templates/.config/sway/config.j2 @@ -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 diff --git a/templates/.config/swayidle/config b/templates/.config/swayidle/config deleted file mode 100644 index fc2e0a6..0000000 --- a/templates/.config/swayidle/config +++ /dev/null @@ -1 +0,0 @@ -timeout 10 'pgrep swaylock && ${host.display_off_cmd}' resume 'pgrep swaylock && ${host.display_on_cmd}' diff --git a/templates/.config/swayidle/config.j2 b/templates/.config/swayidle/config.j2 new file mode 100644 index 0000000..a93cd52 --- /dev/null +++ b/templates/.config/swayidle/config.j2 @@ -0,0 +1 @@ +timeout 10 'pgrep swaylock && {{ host.display_off_cmd }}' resume 'pgrep swaylock && {{ host.display_on_cmd }}' diff --git a/templates/.config/swaylock/config b/templates/.config/swaylock/config.j2 similarity index 57% rename from templates/.config/swaylock/config rename to templates/.config/swaylock/config.j2 index 62ae49b..fb7152a 100644 --- a/templates/.config/swaylock/config +++ b/templates/.config/swaylock/config.j2 @@ -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 }} diff --git a/templates/.config/waybar/config.jsonc b/templates/.config/waybar/config.jsonc.j2 similarity index 64% rename from templates/.config/waybar/config.jsonc rename to templates/.config/waybar/config.jsonc.j2 index c554ad4..18294d1 100644 --- a/templates/.config/waybar/config.jsonc +++ b/templates/.config/waybar/config.jsonc.j2 @@ -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, diff --git a/templates/.config/waybar/style.css b/templates/.config/waybar/style.css.j2 similarity index 98% rename from templates/.config/waybar/style.css rename to templates/.config/waybar/style.css.j2 index 477364d..09caa44 100644 --- a/templates/.config/waybar/style.css +++ b/templates/.config/waybar/style.css.j2 @@ -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; } diff --git a/templates/.config/wofi/style.css b/templates/.config/wofi/style.css.j2 similarity index 85% rename from templates/.config/wofi/style.css rename to templates/.config/wofi/style.css.j2 index 5b46f8a..2f19da4 100644 --- a/templates/.config/wofi/style.css +++ b/templates/.config/wofi/style.css.j2 @@ -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; } - diff --git a/templates/.config/wpaperd/config.toml b/templates/.config/wpaperd/config.toml deleted file mode 100644 index 11be19c..0000000 --- a/templates/.config/wpaperd/config.toml +++ /dev/null @@ -1 +0,0 @@ -${host.wpaperd_config} diff --git a/templates/.config/wpaperd/config.toml.j2 b/templates/.config/wpaperd/config.toml.j2 new file mode 100644 index 0000000..4178021 --- /dev/null +++ b/templates/.config/wpaperd/config.toml.j2 @@ -0,0 +1 @@ +{{ host.wpaperd_config }} diff --git a/templates/.ssh/config b/templates/.ssh/config.j2 similarity index 74% rename from templates/.ssh/config rename to templates/.ssh/config.j2 index b310070..3b9b1f6 100644 --- a/templates/.ssh/config +++ b/templates/.ssh/config.j2 @@ -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 %} diff --git a/templates/.vim/colors/base16.vim b/templates/.vim/colors/base16.vim deleted file mode 100644 index 7d33c19..0000000 --- a/templates/.vim/colors/base16.vim +++ /dev/null @@ -1 +0,0 @@ -${get_base16('vim')} diff --git a/templates/.vim/colors/base16.vim.j2 b/templates/.vim/colors/base16.vim.j2 new file mode 100644 index 0000000..6fd5477 --- /dev/null +++ b/templates/.vim/colors/base16.vim.j2 @@ -0,0 +1 @@ +{{ get_base16('vim') }}