dotfiles/bin/generate-gitignore
Gabriel Arazas 1388f7b7af Add a script for converting Newpipe to OPML
This script uses Oil shell as an initial test for writing scripts with
Oil shell. I think it's a great starting example demonstrating the newer
features such as eggexes and the new formatting of the blocks (e.g., if
and while loops).

Also, updated some scripts lel.
2021-02-23 12:36:58 +08:00

27 lines
814 B
Bash
Executable File

#!/usr/bin/env bash
# A quick command line interface for creating a gitignore with the API from https://gitignore.io.
# This script comes with a simple caching to avoid creating too much requests.
# Dependencies:
# * bash
# * curl
# * fzf
# * jq
# * paste
# * xargs
set -eo pipefail
CACHE_FILE="${XDG_CACHE_DIR:-$HOME/.cache}/gitignore-io.langs.json"
# Check if the language list is downloaded for the last hour (3600 seconds).
if [ ! -e $CACHE_FILE ] || test $(expr $(date "+%s") - $(date -r $CACHE_FILE "+%s")) -gt 3600
then
curl --silent --location --output $CACHE_FILE "https://gitignore.io/api/list?format=json"
fi
KEYS=$(jq 'keys | .[] | @text' --raw-output $CACHE_FILE | fzf --multi | while read lang; do echo " .[\"$lang\"].contents"; done | paste -s -d ',')
jq "$KEYS" --raw-output $CACHE_FILE