From 5513724232797a9b6fa0355372abb6bf50b66146 Mon Sep 17 00:00:00 2001 From: Lonenso Date: Sat, 19 Mar 2022 21:51:47 +0800 Subject: [PATCH] feat: add source field to each cheatpath to describe cheatsheet's source, use cheatsheet helper script to init cheatsheet --- scripts/git/cheatsheets | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/git/cheatsheets b/scripts/git/cheatsheets index 08bcb90..1e649a5 100755 --- a/scripts/git/cheatsheets +++ b/scripts/git/cheatsheets @@ -1,4 +1,18 @@ #!/bin/sh -e +init() { + readarray d < <(yq -c '.cheatpaths[]' ~/.cheat.yml) + + for c in "${d[@]}"; + do + name="$(echo ${c} | yq -r '.name')" + path="$(echo ${c} | yq -r '.path')" + src="$( echo ${c} | yq -r '.source')" + + echo "Init $name" + [ ! -d "$path" ] && git clone $src $path || : + done + echo "Finished init" +} pull() { for d in `cheat -d | awk '{print $2}'`; @@ -36,8 +50,13 @@ if [ "$1" = "pull" ]; then pull elif [ "$1" = "push" ]; then push +elif [ "$1" = "init" ]; then + init else echo "Usage: + # init cheatsheets + cheatsheets init + # pull changes cheatsheets pull