Skip to content

Commit 6a76b58

Browse files
committed
Make bootstrap-in-dir work in different SHELL
* I love yadm, but not all of my machines use bash. * Update bootstrap-in-dir script to work with SHELL other than bash
1 parent bbb58e6 commit 6a76b58

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

contrib/bootstrap/bootstrap-in-dir

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
# Save this file as ~/.config/yadm/bootstrap and make it executable. It will
44
# execute all executable files (excluding templates and editor backups) in the
55
# ~/.config/yadm/bootstrap.d directory when run.
66

7-
set -eu
7+
set -e
88

99
# 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
1116

12-
if [[ ! -d "$BOOTSTRAP_D" ]]; then
17+
if [ ! -d "$BOOTSTRAP_D" ]; then
1318
echo "Error: bootstrap directory '$BOOTSTRAP_D' not found" >&2
1419
exit 1
1520
fi
1621

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
2329

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
2834
fi
2935
done

0 commit comments

Comments
 (0)