Skip to content

Commit

Permalink
Minor cleanups of alt handling
Browse files Browse the repository at this point in the history
Also correct alt conditions precedence list in manual.
  • Loading branch information
erijo committed Mar 2, 2025
1 parent 9ff5e09 commit bee1558
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
11 changes: 7 additions & 4 deletions yadm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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"
Expand Down
23 changes: 11 additions & 12 deletions yadm.1
Original file line number Diff line number Diff line change
Expand Up @@ -512,19 +512,19 @@ 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
.B "lsb_release \-si"
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
Expand Down Expand Up @@ -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:
Expand All @@ -606,13 +606,12 @@ 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.

.IR $HOME/path/example.txt " -> " $HOME/path/example.txt##class.Work,~os.Darwin
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:

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

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

0 comments on commit bee1558

Please sign in to comment.