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

@ -5,10 +5,10 @@ export XDG_STATE_HOME="$HOME/.local/state"
export XDG_CONFIG_DIRS=/etc/xdg
export XDG_DATA_DIRS="$XDG_DATA_HOME/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share"
HISTFILE="$XDG_STATE_HOME/bash_history"
HISTCONTROL=ignoreboth
HISTSIZE=65536
SAVEHIST=8192
export HISTFILE="$XDG_STATE_HOME/bash_history"
export HISTCONTROL=ignoreboth
export HISTSIZE=65536
export SAVEHIST=8192
export LESSHISTFILE='-'

View File

@ -1,5 +1,3 @@
function gi() {
local IFS=,
curl -fL "https://www.toptal.com/developers/gitignore/api/$*"
curl -fL "https://www.toptal.com/developers/gitignore/api/$(printf '%s\n' "$@" | sort -u | paste -sd,)"
}

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