From c9b81e65fc8b71fe9ef09fe5228a170645f4e750 Mon Sep 17 00:00:00 2001 From: kymnob Date: Mon, 11 Mar 2024 01:01:32 +0500 Subject: [PATCH 1/2] completions/_xmirror: turn _xmirrors into #autoload file This way it can be re-used it in other completion functions. Also added missing local declarations and deactivated sorting by default so that tier 1 mirrors go first. --- Makefile | 5 +++-- completions/_xmirror.in | 12 ------------ completions/_xmirrors.in | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 completions/_xmirrors.in diff --git a/Makefile b/Makefile index 13b322d..1d3cf4c 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ xmirror: xmirror.in chmod +x $@+ mv $@+ $@ -completions: completions/_xmirror completions/xmirror.fish completions/xmirror.bash +completions: completions/_xmirror completions/_xmirrors completions/xmirror.fish completions/xmirror.bash completions/%: completions/%.in sed -e "s,@@PREFIX@@,$(PREFIX),g" $< >$@ @@ -22,12 +22,13 @@ install: all install -Dm 755 xmirror -t $(DESTDIR)$(PREFIX)/bin install -Dm 644 mirrors.lst -t $(DESTDIR)$(PREFIX)/share/xmirror install -Dm 644 completions/_xmirror -t $(DESTDIR)$(PREFIX)/share/zsh/site-functions + install -Dm 644 completions/_xmirrors -t $(DESTDIR)$(PREFIX)/share/zsh/site-functions install -Dm 644 completions/xmirror.fish -t $(DESTDIR)/$(PREFIX)/share/fish/vendor_completions.d install -Dm 644 completions/xmirror.bash -t $(DESTDIR)/usr/share/bash-completion/completions install -Dm 644 xmirror.1 -t $(DESTDIR)$(PREFIX)/share/man/man1 clean: - rm -rf xmirror _site completions/_xmirror completions/xmirror.fish completions/xmirror.bash + rm -rf xmirror _site completions/_xmirror completions/_xmirrors completions/xmirror.fish completions/xmirror.bash README: xmirror.1 mandoc -Tutf8 $< | col -bx >$@ diff --git a/completions/_xmirror.in b/completions/_xmirror.in index 16d7d7f..ef12128 100644 --- a/completions/_xmirror.in +++ b/completions/_xmirror.in @@ -1,17 +1,5 @@ #compdef xmirror -_xmirrors() { - local mirror_lst - for line in "${(@f)"$(<@@PREFIX@@/share/xmirror/mirrors.lst)"}" - { - [[ "$line" = '#'* ]] && continue - while IFS=$'\t' read -r region url location tier rest; do - mirror_lst+=("${url//:/\\:}":"$location, Tier $tier") - done <<< "$line" - } - _describe -t mirrors "available mirrors" mirror_lst -} - _arguments -s : \ + '(meta)' \ '(common interactive noninteractive)'{-h,--help}'[Show help for this command and exit]' \ diff --git a/completions/_xmirrors.in b/completions/_xmirrors.in new file mode 100644 index 0000000..ebcb4d8 --- /dev/null +++ b/completions/_xmirrors.in @@ -0,0 +1,14 @@ +#autoload + +local -a mirror_lst +local line region url location rest +local -i tier + +for line in ${(f)"$(<@@PREFIX@@/share/xmirror/mirrors.lst)"}; do + [[ $line = '#'* ]] && continue + while IFS=$'\t' read -r region url location tier rest; do + mirror_lst+=("${url//:/\\:}:$location, Tier $tier") + done <<< $line +done + +_describe -t mirrors "available mirrors" mirror_lst "$@" -o nosort From 1861f1b7783d05e20137a1a5203d8370c886325e Mon Sep 17 00:00:00 2001 From: kymnob Date: Mon, 11 Mar 2024 01:01:50 +0500 Subject: [PATCH 2/2] completions/_xmirrors: add optional mirror/repository completion --- completions/_xmirrors.in | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/completions/_xmirrors.in b/completions/_xmirrors.in index ebcb4d8..f712f62 100644 --- a/completions/_xmirrors.in +++ b/completions/_xmirrors.in @@ -1,14 +1,21 @@ #autoload -local -a mirror_lst +local -a mirror_lst expl suf local line region url location rest -local -i tier +local -i tier repos + +[[ "$@[-1]" = --repos ]] && shift -p && repos=1 && suf=( -S "" ) for line in ${(f)"$(<@@PREFIX@@/share/xmirror/mirrors.lst)"}; do [[ $line = '#'* ]] && continue while IFS=$'\t' read -r region url location tier rest; do mirror_lst+=("${url//:/\\:}:$location, Tier $tier") + if (( repos )) && compset -P ${(b)url}; then + _wanted mirror-repositories expl "typical mirror repositories" \ + compadd "$@" - current{,/musl,aarch64} nonfree multilib{,/nonfree} debug + return + fi done <<< $line done -_describe -t mirrors "available mirrors" mirror_lst "$@" -o nosort +_describe -t mirrors "available mirrors" mirror_lst "$@" -o nosort "$suf[@]"