Skip to content

Commit bee1558

Browse files
committed
Minor cleanups of alt handling
Also correct alt conditions precedence list in manual.
1 parent 9ff5e09 commit bee1558

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

yadm

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ function score_file() {
191191
local -i delta=$((negate ? 1 : -1))
192192
case "$label" in
193193
default)
194-
delta=0
194+
if ((negate)); then
195+
INVALID_ALT+=("$source")
196+
else
197+
delta=0
198+
fi
195199
;;
196200
a | arch)
197201
[[ "$value" = "$local_arch" ]] && delta=1 || delta=-1
@@ -219,7 +223,7 @@ function score_file() {
219223
continue
220224
;;
221225
t | template | yadm)
222-
if [ -d "$source" ]; then
226+
if [ -d "$source" ] || ((negate)); then
223227
INVALID_ALT+=("$source")
224228
else
225229
template_processor=$(choose_template_processor "$value")
@@ -243,8 +247,7 @@ function score_file() {
243247
score=0
244248
return
245249
fi
246-
((negate)) || delta=$((delta + 1000))
247-
score=$((score + delta))
250+
score=$((score + delta + (negate ? 0 : 1000)))
248251
done
249252

250253
record_score "$score" "$target" "$source" "$template_processor"

yadm.1

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -512,19 +512,19 @@ Class must be manually set using
512512
See the CONFIGURATION section for more details about setting
513513
.BR local.class .
514514
.TP
515+
.BR distro_family ,\ f
516+
Valid if the value matches the distro family.
517+
Distro family is calculated by inspecting the ID_LIKE line from
518+
.B "/etc/os-release"
519+
(or ID if no ID_LIKE line is found).
520+
.TP
515521
.BR distro ,\ d
516522
Valid if the value matches the distro.
517523
Distro is calculated by running
518524
.B "lsb_release \-si"
519525
or by inspecting the ID from
520526
.BR "/etc/os-release" .
521527
.TP
522-
.BR distro_family ,\ f
523-
Valid if the value matches the distro family.
524-
Distro family is calculated by inspecting the ID_LIKE line from
525-
.B "/etc/os-release"
526-
(or ID if no ID_LIKE line is found).
527-
.TP
528528
.BR os ,\ o
529529
Valid if the value matches the OS.
530530
OS is calculated by running
@@ -573,13 +573,13 @@ files are managed by yadm's repository:
573573

574574
- $HOME/path/example.txt##default
575575
- $HOME/path/example.txt##class.Work
576+
- $HOME/path/example.txt##class.Work,~os.Darwin
576577
- $HOME/path/example.txt##os.Darwin
577578
- $HOME/path/example.txt##os.Darwin,hostname.host1
578579
- $HOME/path/example.txt##os.Darwin,hostname.host2
579580
- $HOME/path/example.txt##os.Linux
580581
- $HOME/path/example.txt##os.Linux,hostname.host1
581582
- $HOME/path/example.txt##os.Linux,hostname.host2
582-
- $HOME/path/example.txt##class.Work,~os.Darwin
583583

584584
If running on a Macbook named "host2",
585585
yadm will create a symbolic link which looks like this:
@@ -606,13 +606,12 @@ If running on a Macbook with class set to "Work", the link will be:
606606

607607
.IR $HOME/path/example.txt " -> " $HOME/path/example.txt##class.Work
608608

609-
Negative conditions are supported via the "~" prefix. If again running on a system
610-
with class set to "Work", but instead within Windows Subsystem for Linux, where the
611-
os is reported as WSL, the link will be:
609+
Since class has higher precedence than os, this version is chosen.
612610

613-
.IR $HOME/path/example.txt " -> " $HOME/path/example.txt##class.Work,~os.Darwin
611+
If running on a system with class set to "Work", but instead within Windows
612+
Subsystem for Linux, where the os is reported as WSL, the link will be:
614613

615-
Negative conditions use the same weight which corresponds to the attached attribute.
614+
.IR $HOME/path/example.txt " -> " $HOME/path/example.txt##class.Work,~os.Darwin
616615

617616
If no "##default" version exists and no files have valid conditions, then no
618617
link will be created.

0 commit comments

Comments
 (0)