Process config alt before any other.

This allows to version the configuration, using alt and to still be
able to use those configuration values in esh template
(using <% yamd config some-config %> )
This commit is contained in:
Jonathan Daigle 2020-05-21 00:40:54 -04:00 committed by Jonathan Daigle
parent f348e154c7
commit bea6e5506a
No known key found for this signature in database
GPG Key ID: 90C82C275D872859
1 changed files with 13 additions and 5 deletions

18
yadm
View File

@ -251,11 +251,19 @@ function record_score() {
done
# if we don't find an existing index, create one by appending to the array
if [ "$index" -eq -1 ]; then
alt_targets+=("$tgt")
# set index to the last index (newly created one)
for index in "${!alt_targets[@]}"; do :; done
# and set its initial score to zero
alt_scores[$index]=0
# The configuration must be the first alt of the list.
# This ensures that if any templates uses "yadm config some-confid", the config will be available.
if [ "$tgt" = "$YADM_DIR/.config/yadm/config" ]; then
alt_targets=("$tgt" "${alt_targets[@]}")
alt_scores=(0 "${alt_scores[@]}")
index=0
else
alt_targets+=("$tgt")
# set index to the last index (newly created one)
for index in "${!alt_targets[@]}"; do :; done
# and set its initial score to zero
alt_scores[$index]=0
fi
fi
# record nothing if a template command is registered for this file