diff --git a/scripts/git/cheatsheets b/scripts/git/cheatsheets index b5c0493..f126725 100755 --- a/scripts/git/cheatsheets +++ b/scripts/git/cheatsheets @@ -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" }