From f27c13426495472e345f61b30afb328e46d5856e Mon Sep 17 00:00:00 2001 From: HOHOH134 <1992537+showchi@users.noreply.github.com> Date: Thu, 1 Jan 2026 16:30:48 +0800 Subject: [PATCH] gitignore: add configurable API endpoint with fallback --- plugins/gitignore/gitignore.plugin.zsh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/plugins/gitignore/gitignore.plugin.zsh b/plugins/gitignore/gitignore.plugin.zsh index 3271d61a9..2977f2426 100644 --- a/plugins/gitignore/gitignore.plugin.zsh +++ b/plugins/gitignore/gitignore.plugin.zsh @@ -1,12 +1,23 @@ -function gi() { curl -fLw '\n' https://www.toptal.com/developers/gitignore/api/"${(j:,:)@}" } +# Allow overriding API endpoint +: ${GITIGNORE_API_PRIMARY:="https://www.toptal.com/developers/gitignore/api"} +: ${GITIGNORE_API_FALLBACK:="https://www.gitignore.io/api"} + +function _gi_curl() { + curl -sfL "$1/$2" || curl -sfL "$GITIGNORE_API_FALLBACK/$2" +} + +function gi() { + local query="${(j:,:)@}" + _gi_curl "$GITIGNORE_API_PRIMARY" "$query" || return 1 +} _gitignoreio_get_command_list() { - curl -sfL https://www.toptal.com/developers/gitignore/api/list | tr "," "\n" + _gi_curl "$GITIGNORE_API_PRIMARY" "list" | tr "," "\n" } _gitignoreio () { compset -P '*,' - compadd -S '' `_gitignoreio_get_command_list` + compadd -S '' $(_gitignoreio_get_command_list) } -compdef _gitignoreio gi +compdef _gitignoreio gi \ No newline at end of file