From bea6e5506ab3091d1198edff5e9b61d68ee7e4b7 Mon Sep 17 00:00:00 2001 From: Jonathan Daigle Date: Thu, 21 May 2020 00:40:54 -0400 Subject: [PATCH] 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 %> ) --- yadm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/yadm b/yadm index cad4b8e..58a7418 100755 --- a/yadm +++ b/yadm @@ -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