mirror of https://github.com/cheat/cheat.git
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:
parent
e2ec1344f4
commit
cd2473e885
|
@ -1,16 +1,19 @@
|
|||
#!/bin/sh -e
|
||||
#!/bin/bash -e
|
||||
init() {
|
||||
readarray d < <(yq -c '.cheatpaths[]' "$(cheat -C | awk '{print $2}')")
|
||||
|
||||
for c in "${d[@]}";
|
||||
if ! cheat -C > /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
while IFS=$'\t' read -r name path source;
|
||||
do
|
||||
name="$(echo ${c} | yq -r '.name')"
|
||||
path="$(echo ${c} | yq -r '.path')"
|
||||
# failed to use posix sh to expand tilde
|
||||
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"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue