From cc3af6cd809a2029fe3b67b67efcb2868ee23d70 Mon Sep 17 00:00:00 2001 From: dabruh <11458706-dabruh@users.noreply.gitlab.com> Date: Sun, 29 May 2022 01:44:01 +0200 Subject: [PATCH] Greatly improved layering mechanism. --- .config/i3/layers/abdiel.layer | 2 + .config/i3/layers/abijah.layer | 2 + .config/i3/{ => layers}/config.main | 0 .../{ => layers}/config.post-main-00-security | 0 .../{ => layers}/config.post-main-01-visuals | 0 .../{ => layers}/config.post-main-10-applets | 0 .../i3/{ => layers}/config.post-main-10-audio | 0 .../i3/{ => layers}/config.post-main-10-misc | 0 .../i3/{ => layers}/config.pre-main-00-vars | 0 ...-90-cerberus => config.pre-main-90-abdiel} | 0 .config/i3/layers/default.layer | 7 ++ .config/i3status/layers/abdiel.layer | 3 + .config/i3status/layers/abijah.layer | 2 + .config/i3status/{ => layers}/config.main | 0 .../i3status/{ => layers}/config.post-main-25 | 0 ...-50-desktop => config.post-main-50-abdiel} | 0 .../i3status/{ => layers}/config.post-main-75 | 0 .config/i3status/layers/default.layer | 4 + .installer/ignored | 2 - .local/bin/i3-config-builder | 76 +++++++++++++------ 20 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 .config/i3/layers/abdiel.layer create mode 100644 .config/i3/layers/abijah.layer rename .config/i3/{ => layers}/config.main (100%) rename .config/i3/{ => layers}/config.post-main-00-security (100%) rename .config/i3/{ => layers}/config.post-main-01-visuals (100%) rename .config/i3/{ => layers}/config.post-main-10-applets (100%) rename .config/i3/{ => layers}/config.post-main-10-audio (100%) rename .config/i3/{ => layers}/config.post-main-10-misc (100%) rename .config/i3/{ => layers}/config.pre-main-00-vars (100%) rename .config/i3/layers/{config.pre-main-90-cerberus => config.pre-main-90-abdiel} (100%) create mode 100644 .config/i3/layers/default.layer create mode 100644 .config/i3status/layers/abdiel.layer create mode 100644 .config/i3status/layers/abijah.layer rename .config/i3status/{ => layers}/config.main (100%) rename .config/i3status/{ => layers}/config.post-main-25 (100%) rename .config/i3status/layers/{config.post-main-50-desktop => config.post-main-50-abdiel} (100%) rename .config/i3status/{ => layers}/config.post-main-75 (100%) create mode 100644 .config/i3status/layers/default.layer diff --git a/.config/i3/layers/abdiel.layer b/.config/i3/layers/abdiel.layer new file mode 100644 index 0000000..21d178f --- /dev/null +++ b/.config/i3/layers/abdiel.layer @@ -0,0 +1,2 @@ +config.post-main-90-gaps +config.pre-main-90-abdiel diff --git a/.config/i3/layers/abijah.layer b/.config/i3/layers/abijah.layer new file mode 100644 index 0000000..811f12a --- /dev/null +++ b/.config/i3/layers/abijah.layer @@ -0,0 +1,2 @@ +config.post-main-90-gaps +config.post-main-90-laptop diff --git a/.config/i3/config.main b/.config/i3/layers/config.main similarity index 100% rename from .config/i3/config.main rename to .config/i3/layers/config.main diff --git a/.config/i3/config.post-main-00-security b/.config/i3/layers/config.post-main-00-security similarity index 100% rename from .config/i3/config.post-main-00-security rename to .config/i3/layers/config.post-main-00-security diff --git a/.config/i3/config.post-main-01-visuals b/.config/i3/layers/config.post-main-01-visuals similarity index 100% rename from .config/i3/config.post-main-01-visuals rename to .config/i3/layers/config.post-main-01-visuals diff --git a/.config/i3/config.post-main-10-applets b/.config/i3/layers/config.post-main-10-applets similarity index 100% rename from .config/i3/config.post-main-10-applets rename to .config/i3/layers/config.post-main-10-applets diff --git a/.config/i3/config.post-main-10-audio b/.config/i3/layers/config.post-main-10-audio similarity index 100% rename from .config/i3/config.post-main-10-audio rename to .config/i3/layers/config.post-main-10-audio diff --git a/.config/i3/config.post-main-10-misc b/.config/i3/layers/config.post-main-10-misc similarity index 100% rename from .config/i3/config.post-main-10-misc rename to .config/i3/layers/config.post-main-10-misc diff --git a/.config/i3/config.pre-main-00-vars b/.config/i3/layers/config.pre-main-00-vars similarity index 100% rename from .config/i3/config.pre-main-00-vars rename to .config/i3/layers/config.pre-main-00-vars diff --git a/.config/i3/layers/config.pre-main-90-cerberus b/.config/i3/layers/config.pre-main-90-abdiel similarity index 100% rename from .config/i3/layers/config.pre-main-90-cerberus rename to .config/i3/layers/config.pre-main-90-abdiel diff --git a/.config/i3/layers/default.layer b/.config/i3/layers/default.layer new file mode 100644 index 0000000..48205f1 --- /dev/null +++ b/.config/i3/layers/default.layer @@ -0,0 +1,7 @@ +config.pre-main-00-vars +config.main +config.post-main-00-security +config.post-main-01-visuals +config.post-main-10-applets +config.post-main-10-audio +config.post-main-10-misc diff --git a/.config/i3status/layers/abdiel.layer b/.config/i3status/layers/abdiel.layer new file mode 100644 index 0000000..3265d9a --- /dev/null +++ b/.config/i3status/layers/abdiel.layer @@ -0,0 +1,3 @@ +config.post-main-01-cmus +config.post-main-01-docker +config.post-main-50-abdiel diff --git a/.config/i3status/layers/abijah.layer b/.config/i3status/layers/abijah.layer new file mode 100644 index 0000000..1ffa2b6 --- /dev/null +++ b/.config/i3status/layers/abijah.layer @@ -0,0 +1,2 @@ +config.post-main-01-cmus +config.post-main-01-docker diff --git a/.config/i3status/config.main b/.config/i3status/layers/config.main similarity index 100% rename from .config/i3status/config.main rename to .config/i3status/layers/config.main diff --git a/.config/i3status/config.post-main-25 b/.config/i3status/layers/config.post-main-25 similarity index 100% rename from .config/i3status/config.post-main-25 rename to .config/i3status/layers/config.post-main-25 diff --git a/.config/i3status/layers/config.post-main-50-desktop b/.config/i3status/layers/config.post-main-50-abdiel similarity index 100% rename from .config/i3status/layers/config.post-main-50-desktop rename to .config/i3status/layers/config.post-main-50-abdiel diff --git a/.config/i3status/config.post-main-75 b/.config/i3status/layers/config.post-main-75 similarity index 100% rename from .config/i3status/config.post-main-75 rename to .config/i3status/layers/config.post-main-75 diff --git a/.config/i3status/layers/default.layer b/.config/i3status/layers/default.layer new file mode 100644 index 0000000..b43dfc5 --- /dev/null +++ b/.config/i3status/layers/default.layer @@ -0,0 +1,4 @@ +config.main +config.post-main-25 +config.post-main-75 +config.post-main-01-docker diff --git a/.installer/ignored b/.installer/ignored index 5a75368..e9effb2 100755 --- a/.installer/ignored +++ b/.installer/ignored @@ -3,5 +3,3 @@ ^\.install ^install\.sh$ ^setup_system\.sh$ -^\.config\/i3\/layers -^\.config\/i3status\/layers diff --git a/.local/bin/i3-config-builder b/.local/bin/i3-config-builder index 219a122..ad744b6 100755 --- a/.local/bin/i3-config-builder +++ b/.local/bin/i3-config-builder @@ -1,43 +1,71 @@ #!/bin/bash -function i3setup() { - local file dir cfg path \ - component="$1" \ - patterns=( - "config.vars" - "config.pre-main" - "config.main" - "config.post-main" - ) +# +# Title: i3-config-builder +# Version: 0.1.0 +# Author: dabruh +# GitLab: https://gitlab.com/dabruh +# GitHub: https://github.com/dabruh +# +# Builds an i3/i3status configuration file by merging +# multiple defined configurations in an orderly manner. +# +# The files you wish to include MUST exist under ~/.config/i3(status)/layers. +# The files MUST start with one of the defined "PATTERNS" below. However, they +# WILL NOT be read unless explicitly mentioned in a .layer file located in the +# same directory. +# +# Two .layer files are read during execution: +# - default.layer +# - $HOSTNAME.layer: This file doesn't have to exist, but will allow you to +# load a special set of files depending on the hostname of the machine which +# executes this script. +# +# The contents of the .layer files are read first, and then sorted. +# +HOSTNAME="$(hostname | cut -d. -f1)" +PATTERNS=( + "config.vars" + "config.pre-main" + "config.main" + "config.post-main" +) + +function i3setup() { + local file dir layers config includes path component="$1" dir="$HOME/.config/$component" - cfg="$dir/config" + layers="$dir/layers" + config="$dir/config" echo "Building $component config... 🔨" - rm "$cfg" 2>/dev/null + rm "$config" 2>/dev/null + includes=$(cat "$layers/default.layer" "$layers/$HOSTNAME.layer" 2>/dev/null | sort -u) - for pattern in "${patterns[@]}"; do - while IFS= read -r path; do - [ -z "$path" ] && continue - file="${path##*/}" + for pattern in "${PATTERNS[@]}"; do + for file in $includes; do + ! [[ "$file" =~ "$pattern"* ]] && continue + path="$layers/$file" + + if ! [ -f "$path" ] && ! [ -L "$path" ]; then + echo "ERROR: Invalid path: $path" + continue + fi echo "WRITE : '$file'." - { echo "# >>>$file" - cat "$path" >>"$cfg" + cat "$path" echo "# <<<$file" echo - } >>"$cfg" - - done <<<"$(find "$dir" -maxdepth 1 -type f -name "$pattern*" | sort -n)" + } >>"$config" + done done - - echo - echo "Restarting i3... 🔄" - i3 restart echo } i3setup i3 i3setup i3status + +echo "Restarting i3... 🔄" +i3 restart