From c0dea465da4c59c1cd497cc5964b8385ea25b697 Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Tue, 23 Jul 2024 11:32:47 +0200 Subject: [PATCH] bin: add `git-ignore` --- bin/git-ignore | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 bin/git-ignore diff --git a/bin/git-ignore b/bin/git-ignore new file mode 100755 index 0000000..4481cfc --- /dev/null +++ b/bin/git-ignore @@ -0,0 +1,26 @@ +#!/bin/sh + +set -eu + +WORKDIR="${XDG_CACHE_HOME:-$HOME/.cache}/git-ignore" +URL="https://github.com/github/gitignore.git" + +if [ ! -d "$WORKDIR" ]; then + git clone --quiet --depth 1 "$URL" "$WORKDIR" +else + git -C "$WORKDIR" pull --quiet +fi + +find "$WORKDIR" -maxdepth 1 -type f -name '*gitignore' | + sed -e "s,^$WORKDIR/\(.*\)\.gitignore$,\1," | + sort | + fzf --multi \ + --preview="cat $WORKDIR/{}.gitignore" \ + --bind='ctrl-p:toggle-preview' | + while read -r lang; do + echo "############################################################" + echo "# ${lang}" + echo "############################################################" + cat "$WORKDIR/${lang}.gitignore" + echo + done