2021-04-20 08:28:40 +02:00
|
|
|
#!/bin/sh -e
|
2022-03-19 14:51:47 +01:00
|
|
|
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"
|
|
|
|
}
|
2021-04-20 08:28:40 +02:00
|
|
|
|
|
|
|
pull() {
|
|
|
|
for d in `cheat -d | awk '{print $2}'`;
|
|
|
|
do
|
|
|
|
echo "Update $d"
|
|
|
|
cd "$d"
|
|
|
|
[ -d ".git" ] && git pull || :
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Finished update"
|
|
|
|
}
|
|
|
|
|
|
|
|
push() {
|
|
|
|
for d in `cheat -d | grep -v "community" | awk '{print $2}'`;
|
|
|
|
do
|
|
|
|
cd "$d"
|
|
|
|
if [ -d ".git" ]
|
|
|
|
then
|
|
|
|
echo "Push modifications $d"
|
|
|
|
files=$(git ls-files -mo | tr '\n' ' ')
|
|
|
|
git add -A && git commit -m "Edited files: $files" && git push || :
|
|
|
|
else
|
|
|
|
echo "$(pwd) is not a git managed folder"
|
|
|
|
echo "First connect this to your personal git repository"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Finished push operation"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$1" = "pull" ]; then
|
|
|
|
pull
|
|
|
|
elif [ "$1" = "push" ]; then
|
|
|
|
push
|
2022-03-19 14:51:47 +01:00
|
|
|
elif [ "$1" = "init" ]; then
|
|
|
|
init
|
2021-04-20 08:28:40 +02:00
|
|
|
else
|
|
|
|
echo "Usage:
|
2022-03-19 14:51:47 +01:00
|
|
|
# init cheatsheets
|
|
|
|
cheatsheets init
|
|
|
|
|
2021-04-20 08:28:40 +02:00
|
|
|
# pull changes
|
|
|
|
cheatsheets pull
|
|
|
|
|
|
|
|
# push changes
|
|
|
|
cheatsheets push"
|
|
|
|
fi
|