|
1 | | -#!/bin/bash |
| 1 | +#!/bin/sh |
2 | 2 |
|
3 | 3 | # Save this file as ~/.config/yadm/bootstrap and make it executable. It will |
4 | 4 | # execute all executable files (excluding templates and editor backups) in the |
5 | 5 | # ~/.config/yadm/bootstrap.d directory when run. |
6 | 6 |
|
7 | | -set -eu |
| 7 | +set -e |
8 | 8 |
|
9 | 9 | # Directory to look for bootstrap executables in |
10 | | -BOOTSTRAP_D="${BASH_SOURCE[0]}.d" |
| 10 | +# Works in sh, bash, and zsh |
| 11 | +if [ -n "${BASH_SOURCE:-}" ]; then |
| 12 | + BOOTSTRAP_D="${BASH_SOURCE[0]}.d" |
| 13 | +else |
| 14 | + BOOTSTRAP_D="${0}.d" |
| 15 | +fi |
11 | 16 |
|
12 | | -if [[ ! -d "$BOOTSTRAP_D" ]]; then |
| 17 | +if [ ! -d "$BOOTSTRAP_D" ]; then |
13 | 18 | echo "Error: bootstrap directory '$BOOTSTRAP_D' not found" >&2 |
14 | 19 | exit 1 |
15 | 20 | fi |
16 | 21 |
|
17 | | -declare -a bootstraps |
18 | | -while IFS= read -r bootstrap; do |
19 | | - if [[ -x "$bootstrap" && ! "$bootstrap" =~ "##" && ! "$bootstrap" =~ ~$ ]]; then |
20 | | - bootstraps+=("$bootstrap") |
21 | | - fi |
22 | | -done < <(find -L "$BOOTSTRAP_D" -type f | sort) |
| 22 | +# Find and execute bootstrap files |
| 23 | +find -L "$BOOTSTRAP_D" -type f | sort | while IFS= read -r bootstrap; do |
| 24 | + # Skip non-executable files, editor backups (~), and templates (##) |
| 25 | + if [ -x "$bootstrap" ]; then |
| 26 | + case "$bootstrap" in |
| 27 | + *\##*|*~) continue ;; |
| 28 | + esac |
23 | 29 |
|
24 | | -for bootstrap in "${bootstraps[@]}"; do |
25 | | - if ! "$bootstrap"; then |
26 | | - echo "Error: bootstrap '$bootstrap' failed" >&2 |
27 | | - exit 1 |
| 30 | + if ! "$bootstrap"; then |
| 31 | + echo "Error: bootstrap '$bootstrap' failed" >&2 |
| 32 | + exit 1 |
| 33 | + fi |
28 | 34 | fi |
29 | 35 | done |
0 commit comments