2021-01-13 17:10:01 +00:00
|
|
|
#!/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
|
2021-02-23 04:36:58 +00:00
|
|
|
# * jq
|
2021-01-13 17:10:01 +00:00
|
|
|
# * 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
|
2021-03-07 05:49:54 +00:00
|
|
|
ping "gitignore.io" --count 4 && curl --silent --location --output $CACHE_FILE "https://gitignore.io/api/list?format=json"
|
2021-01-13 17:10:01 +00:00
|
|
|
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
|