feat: bash completion cache

This commit is contained in:
ange 2024-11-16 15:19:20 +08:00
parent d6aece2460
commit 421674018f
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
4 changed files with 18 additions and 13 deletions

View file

@ -1,6 +1,10 @@
function _ddev() {
mapfile -t COMPREPLY < <(compgen -W \
"$(curl -sfL 'https://api.github.com/repos/docker-library/official-images/git/trees/master?recursive=1' | sed -nE 's/.*"library\/(.+)",$/\1/p')" \
-- "${COMP_WORDS[1]}")
cache="/tmp/${FUNCNAME[0]}"
if ! [ -f "$cache" ]; then
curl -sfL 'https://api.github.com/repos/docker-library/official-images/git/trees/master?recursive=1' | sed -nE 's/.*"library\/(.+)",$/\1/p' > "$cache"
fi
[ "$COMP_CWORD" -ne 1 ] && return
mapfile -t COMPREPLY < <(compgen -W "$(cat "$cache")" -- "${COMP_WORDS[1]}")
}
complete -F _ddev ddev

View file

@ -1,6 +1,9 @@
function _gi() {
mapfile -t COMPREPLY < <(compgen -W \
"$(curl -sfL https://www.toptal.com/developers/gitignore/api/list | tr ',' '\n')" \
-- "${COMP_WORDS[1]}")
cache="/tmp/${FUNCNAME[0]}"
if ! [ -f "$cache" ]; then
curl -sfL https://www.toptal.com/developers/gitignore/api/list | tr ',' '\n' > "$cache"
fi
mapfile -t COMPREPLY < <(compgen -W "$(cat "$cache")" -- "${COMP_WORDS[$COMP_CWORD]}")
}
complete -F _gi gi