From f8a231138aa13b143843f46fec750ce5c07fb530 Mon Sep 17 00:00:00 2001 From: aleidk Date: Wed, 5 Feb 2025 13:44:28 -0300 Subject: [PATCH] feat: add script to add gitignore tempaltes --- .devfiles/scripts/gitignore.sh | 42 ++++++++++++++++++++++++++++++++++ .gitignore | 4 ++++ 2 files changed, 46 insertions(+) create mode 100755 .devfiles/scripts/gitignore.sh diff --git a/.devfiles/scripts/gitignore.sh b/.devfiles/scripts/gitignore.sh new file mode 100755 index 0000000..0b5100d --- /dev/null +++ b/.devfiles/scripts/gitignore.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +set -euo pipefail + +root="$(git rev-parse --show-toplevel)" + +base_url="https://git.alecodes.page/api/v1/gitignore/templates" + +query="$*" + +list_available() { + curl -Ssl $base_url | jq -r '.[]' +} + +if [[ -z $query ]]; then + list_available + exit 0 +fi + +tmp_file="$(mktemp)" + +for template in $query; do + # Capitalize the string + template=${template,,} + template=${template^} + + response="$(curl -Ssl "$base_url/$template")" + name="$(echo "$response" | jq -r '.name')" + content="$(echo "$response" | jq -r '.source')" + + if [[ "$content" == "null" ]]; then + echo "Template not found, available options:" + list_available + exit 1 + fi + + printf "\n### %s\n\n%s\n\n" "$name" "$content" >>"$tmp_file" +done + +sed -i -ne "/#### -- TEMPLATES BEGIN -- ####/ {p; r $tmp_file" -e ':a; n; /#### -- TEMPLATES END -- ####/ {p; b}; ba}; p' "$root/.gitignore" + +rm "$tmp_file" diff --git a/.gitignore b/.gitignore index cd4da0d..59cc215 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ # Devfiles .devfiles/bin/**/* +#### -- TEMPLATES BEGIN -- #### + +#### -- TEMPLATES END -- #### + # Allow to presever folder structure in excluded folers, should be the last rule !**/.gitkeep