From bee1558a4edc3b4ad392be8373a8dda2f8c08793 Mon Sep 17 00:00:00 2001 From: Erik Flodin Date: Sun, 2 Mar 2025 22:18:09 +0100 Subject: [PATCH] Minor cleanups of alt handling Also correct alt conditions precedence list in manual. --- yadm | 11 +++++++---- yadm.1 | 23 +++++++++++------------ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/yadm b/yadm index dccb7c9..c239f65 100755 --- a/yadm +++ b/yadm @@ -191,7 +191,11 @@ function score_file() { local -i delta=$((negate ? 1 : -1)) case "$label" in default) - delta=0 + if ((negate)); then + INVALID_ALT+=("$source") + else + delta=0 + fi ;; a | arch) [[ "$value" = "$local_arch" ]] && delta=1 || delta=-1 @@ -219,7 +223,7 @@ function score_file() { continue ;; t | template | yadm) - if [ -d "$source" ]; then + if [ -d "$source" ] || ((negate)); then INVALID_ALT+=("$source") else template_processor=$(choose_template_processor "$value") @@ -243,8 +247,7 @@ function score_file() { score=0 return fi - ((negate)) || delta=$((delta + 1000)) - score=$((score + delta)) + score=$((score + delta + (negate ? 0 : 1000))) done record_score "$score" "$target" "$source" "$template_processor" diff --git a/yadm.1 b/yadm.1 index fd631ad..9145b24 100644 --- a/yadm.1 +++ b/yadm.1 @@ -512,6 +512,12 @@ Class must be manually set using See the CONFIGURATION section for more details about setting .BR local.class . .TP +.BR distro_family ,\ f +Valid if the value matches the distro family. +Distro family is calculated by inspecting the ID_LIKE line from +.B "/etc/os-release" +(or ID if no ID_LIKE line is found). +.TP .BR distro ,\ d Valid if the value matches the distro. Distro is calculated by running @@ -519,12 +525,6 @@ Distro is calculated by running or by inspecting the ID from .BR "/etc/os-release" . .TP -.BR distro_family ,\ f -Valid if the value matches the distro family. -Distro family is calculated by inspecting the ID_LIKE line from -.B "/etc/os-release" -(or ID if no ID_LIKE line is found). -.TP .BR os ,\ o Valid if the value matches the OS. OS is calculated by running @@ -573,13 +573,13 @@ files are managed by yadm's repository: - $HOME/path/example.txt##default - $HOME/path/example.txt##class.Work + - $HOME/path/example.txt##class.Work,~os.Darwin - $HOME/path/example.txt##os.Darwin - $HOME/path/example.txt##os.Darwin,hostname.host1 - $HOME/path/example.txt##os.Darwin,hostname.host2 - $HOME/path/example.txt##os.Linux - $HOME/path/example.txt##os.Linux,hostname.host1 - $HOME/path/example.txt##os.Linux,hostname.host2 - - $HOME/path/example.txt##class.Work,~os.Darwin If running on a Macbook named "host2", yadm will create a symbolic link which looks like this: @@ -606,14 +606,13 @@ If running on a Macbook with class set to "Work", the link will be: .IR $HOME/path/example.txt " -> " $HOME/path/example.txt##class.Work -Negative conditions are supported via the "~" prefix. If again running on a system -with class set to "Work", but instead within Windows Subsystem for Linux, where the -os is reported as WSL, the link will be: +Since class has higher precedence than os, this version is chosen. + +If running on a system with class set to "Work", but instead within Windows +Subsystem for Linux, where the os is reported as WSL, the link will be: .IR $HOME/path/example.txt " -> " $HOME/path/example.txt##class.Work,~os.Darwin -Negative conditions use the same weight which corresponds to the attached attribute. - If no "##default" version exists and no files have valid conditions, then no link will be created.