diff options
| author | Danilo M. <danix@danix.xyz> | 2026-05-06 12:25:09 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-05-06 12:25:09 +0200 |
| commit | 9ee7d5231513ef7bd51d51dac73693922814cde2 (patch) | |
| tree | 92d30d7ad14d9b2cf7e2b6881e09c126374d3ed2 | |
| parent | 51cccf8fa8a944289f51791b61fb18b8f2c490b4 (diff) | |
| download | dots-backup-9ee7d5231513ef7bd51d51dac73693922814cde2.tar.gz dots-backup-9ee7d5231513ef7bd51d51dac73693922814cde2.zip | |
feat: files.list replaces hardcoded array when non-empty
Previously files.list appended to the built-in DOTFILES array, causing
duplicate processing. Now a non-empty files.list replaces the array
entirely; missing or empty file falls back to the hardcoded defaults.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | README.md | 15 | ||||
| -rwxr-xr-x | dot-backup.sh | 12 |
2 files changed, 20 insertions, 7 deletions
@@ -135,15 +135,18 @@ GIT_BRANCH="master" ## Adding Files -**Edit the script** — add paths to the `DOTFILES` array in `dot-backup.sh`. - -**Or use the external list** — add paths to `~/.config/dot-backup/files.list`, one per line: +**External list (recommended)** — create `~/.config/dot-backup/files.list` with one path per line. When this file exists and is non-empty it replaces the built-in list entirely: ``` -# extra dotfiles -.config/myapp -.config/otherapp.conf +# shell +.bashrc +.bash_aliases + +# system files /etc/hosts +/etc/fstab ``` +**Built-in fallback** — if `files.list` is missing or empty, the script uses the `DOTFILES` array hardcoded in `dot-backup.sh`. + Relative paths are treated as `$HOME`-relative. Absolute paths (starting with `/`) are treated as system files. diff --git a/dot-backup.sh b/dot-backup.sh index 0e22d70..f58c873 100755 --- a/dot-backup.sh +++ b/dot-backup.sh @@ -160,10 +160,20 @@ DOTFILES=( "/etc/bash_completion.d" ) -# Load external list if it exists, appending to built-in list +# Use external list exclusively if it exists and is non-empty +_has_external_list=false if [[ -f "$DOTFILES_LIST" ]]; then while IFS= read -r line || [[ -n "$line" ]]; do [[ "$line" =~ ^#.*$ || -z "$line" ]] && continue + _has_external_list=true + break + done < "$DOTFILES_LIST" +fi + +if [[ "$_has_external_list" == true ]]; then + DOTFILES=() + while IFS= read -r line || [[ -n "$line" ]]; do + [[ "$line" =~ ^#.*$ || -z "$line" ]] && continue DOTFILES+=("$line") done < "$DOTFILES_LIST" fi |
