fix: readarray doesn't work on osx, change shebang to /bin/bash since failed to use posix sh to expand tilde

This commit is contained in:
Lonenso 2022-03-20 15:20:45 +08:00
parent e2ec1344f4
commit cd2473e885
1 changed files with 12 additions and 9 deletions

View File

@ -1,16 +1,19 @@
#!/bin/sh -e #!/bin/bash -e
init() { init() {
readarray d < <(yq -c '.cheatpaths[]' "$(cheat -C | awk '{print $2}')") if ! cheat -C > /dev/null; then
exit 1
for c in "${d[@]}"; fi
while IFS=$'\t' read -r name path source;
do do
name="$(echo ${c} | yq -r '.name')" # failed to use posix sh to expand tilde
path="$(echo ${c} | yq -r '.path')"
path="${path/#\~/$HOME}" path="${path/#\~/$HOME}"
src="$( echo ${c} | yq -r '.source')" # git clone when path not exists or path exists but empty
if [ ! -d "$path" ] || [ -d "$path" ] && [ -z "$(ls -A "$path")" ]; then
echo "Init $name"
git clone "$source" "$path"
fi
done < <(yq -r '.cheatpaths[] | [.name, .path, .source] | @tsv' "$(cheat -C | awk '{print $2}')")
[ ! -d "$path" ] && (echo "Init $name"; git clone $src $path) || :
done
echo "Finished init" echo "Finished init"
} }