mirror of https://gitlab.com/dabruh/dotfiles.git
Greatly improved layering mechanism.
This commit is contained in:
parent
442e0309b8
commit
cc3af6cd80
|
@ -0,0 +1,2 @@
|
|||
config.post-main-90-gaps
|
||||
config.pre-main-90-abdiel
|
|
@ -0,0 +1,2 @@
|
|||
config.post-main-90-gaps
|
||||
config.post-main-90-laptop
|
|
@ -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
|
|
@ -0,0 +1,3 @@
|
|||
config.post-main-01-cmus
|
||||
config.post-main-01-docker
|
||||
config.post-main-50-abdiel
|
|
@ -0,0 +1,2 @@
|
|||
config.post-main-01-cmus
|
||||
config.post-main-01-docker
|
|
@ -0,0 +1,4 @@
|
|||
config.main
|
||||
config.post-main-25
|
||||
config.post-main-75
|
||||
config.post-main-01-docker
|
|
@ -3,5 +3,3 @@
|
|||
^\.install
|
||||
^install\.sh$
|
||||
^setup_system\.sh$
|
||||
^\.config\/i3\/layers
|
||||
^\.config\/i3status\/layers
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue