dotfiles/bin/generate-gitignore

20 lines
853 B
Plaintext
Raw Normal View History

2021-06-24 07:19:21 +00:00
#!/usr/bin/env nix-shell
#! nix-shell --pure -i bash -p curl jq fzf coreutils findutils iputils
2021-01-13 17:10:01 +00:00
# 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.
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).
2021-06-24 07:19:21 +00:00
if [[ ! -e $CACHE_FILE ]] || test $(expr $(date "+%s") - $(date -r $CACHE_FILE "+%s")) -gt 3600
2021-01-13 17:10:01 +00:00
then
2021-06-24 07:19:21 +00:00
ping -q -c 4 "gitignore.io" && curl --silent --location "https://gitignore.io/api/list?format=json" --output $CACHE_FILE
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