From bb1a89a8372b5b8c5372578b2ffe4b7ff04f0843 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Wed, 18 May 2022 02:07:01 +0200 Subject: make: split out completion scripts from root worktree --- Makefile | 33 ++++----- bash_completion.in | 90 ------------------------- contrib/completion/bash/devtools.in | 90 +++++++++++++++++++++++++ contrib/completion/zsh/_devtools.in | 129 ++++++++++++++++++++++++++++++++++++ zsh_completion.in | 129 ------------------------------------ 5 files changed, 236 insertions(+), 235 deletions(-) delete mode 100644 bash_completion.in create mode 100644 contrib/completion/bash/devtools.in create mode 100644 contrib/completion/zsh/_devtools.in delete mode 100644 zsh_completion.in diff --git a/Makefile b/Makefile index b7dcfd1..128c298 100644 --- a/Makefile +++ b/Makefile @@ -74,11 +74,7 @@ CROSSREPOMOVE_LINKS = \ extra2community \ community2extra -COMPLETIONS = \ - bash_completion \ - zsh_completion -COMPLETIONS := $(addprefix $(BUILDDIR)/completion/,$(COMPLETIONS)) - +COMPLETIONS = $(addprefix $(BUILDDIR)/,$(patsubst %.in,%,$(wildcard contrib/completion/*/*))) BASHCOMPLETION_LINKS = \ archco \ communityco @@ -108,14 +104,18 @@ man: $(MANS) edit = sed -e "s|@pkgdatadir[@]|$(PREFIX)/share/devtools|g" -$(BUILDDIR)/bin/% $(BUILDDIR)/completion/%: %.in Makefile $(wildcard lib/*.sh) - @echo "GEN $(notdir $@)" - @mkdir -p $(dir $@) - @$(RM) "$@" - @{ echo -n 'm4_changequote([[[,]]])'; cat $<; } | m4 -P --define=m4_devtools_version=$(BUILDTOOLVER) | $(edit) >$@ - @chmod a-w "$@" - @chmod +x "$@" - @bash -O extglob -n "$@" +define buildInScript +$(1)/%: $(2)%.in + @echo "GEN $$(notdir $$@)" + @mkdir -p $$(dir $$@) + @$(RM) "$$@" + @{ echo -n 'm4_changequote([[[,]]])'; cat $$<; } | m4 -P --define=m4_devtools_version=$$(BUILDTOOLVER) | $(edit) >$$@ + @chmod $(3) "$$@" + @bash -O extglob -n "$$@" +endef + +$(eval $(call buildInScript,build/bin,,555)) +$(foreach completion,$(wildcard contrib/completion/*),$(eval $(call buildInScript,build/$(completion),$(completion)/,444))) $(BUILDDIR)/doc/%: doc/%.asciidoc doc/asciidoc.conf doc/footer.asciidoc @mkdir -p $(BUILDDIR)/doc @@ -134,9 +134,9 @@ install: all for l in ${ARCHBUILD_LINKS}; do ln -sf archbuild $(DESTDIR)$(PREFIX)/bin/$$l; done for l in ${CROSSREPOMOVE_LINKS}; do ln -sf crossrepomove $(DESTDIR)$(PREFIX)/bin/$$l; done ln -sf find-libdeps $(DESTDIR)$(PREFIX)/bin/find-libprovides - install -Dm0644 $(BUILDDIR)/bash_completion $(DESTDIR)$(PREFIX)/share/bash-completion/completions/devtools + install -Dm0644 $(BUILDDIR)/contrib/completion/bash/devtools $(DESTDIR)$(PREFIX)/share/bash-completion/completions/devtools for l in ${BASHCOMPLETION_LINKS}; do ln -sf devtools $(DESTDIR)$(PREFIX)/share/bash-completion/completions/$$l; done - install -Dm0644 $(BUILDDIR)/zsh_completion $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_devtools + install -Dm0644 $(BUILDDIR)/contrib/completion/zsh/_devtools $(DESTDIR)$(PREFIX)/share/zsh/site-functions/_devtools ln -sf archco $(DESTDIR)$(PREFIX)/bin/communityco for manfile in $(MANS); do \ install -Dm644 $$manfile -t $(DESTDIR)$(MANDIR)/man$${manfile##*.}; \ @@ -155,6 +155,7 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/communityco rm -f $(DESTDIR)$(PREFIX)/bin/find-libprovides for manfile in $(notdir $(MANS)); do rm -f $(DESTDIR)$(MANDIR)/man$${manfile##*.}/$${manfile}; done; + rmdir --ignore-fail-on-non-empty $(DESTDIR)$(PREFIX)/share/devtools/setarch-aliases.d $(DESTDIR)$(PREFIX)/share/devtools TODAY=$(shell date +"%Y%m%d") tag: @@ -169,7 +170,7 @@ dist: upload: scp devtools-$(V).tar.gz devtools-$(V).tar.gz.sig repos.archlinux.org:/srv/ftp/other/devtools/ -check: $(BINPROGS) $(BUILDDIR)/bash_completion makepkg-x86_64.conf PKGBUILD.proto +check: $(BINPROGS) $(BUILDDIR)/contrib/completion/bash/devtools makepkg-x86_64.conf PKGBUILD.proto shellcheck $^ .PHONY: all completion man clean install uninstall dist upload check tag diff --git a/bash_completion.in b/bash_completion.in deleted file mode 100644 index e7925b3..0000000 --- a/bash_completion.in +++ /dev/null @@ -1,90 +0,0 @@ -#!/hint/bash -# -# SPDX-License-Identifier: GPL-3.0-or-later - -_devtools_compgen() { - local i r - COMPREPLY=($(compgen -W '$*' -- "$cur")) - for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do - for r in "${!COMPREPLY[@]}"; do - if [[ ${COMP_WORDS[i]} = "${COMPREPLY[r]}" ]]; then - unset 'COMPREPLY[r]'; break - fi - done - done -} - -_archco_pkg() { - _devtools_compgen "$( - command pacman "-$1" - )" -} - -_archco() { - local cur prev - COMPREPLY=() - cur=$(_get_cword) - prev=${COMP_WORDS[COMP_CWORD-1]} - - _archco_pkg Slq - true -} && -complete -F _archco archco communityco - -_makechrootpkg() { - local cur - COMPREPLY=() - _get_comp_words_by_ref cur - - case $cur in - -*) - COMPREPLY=( $( compgen -W '-I -c -h -l -r -u' -- "$cur" ) ) - ;; - *) - _filedir - return 0 - ;; - esac - - true -} && -complete -F _makechrootpkg makechrootpkg - -_mkarchroot() { - local cur - COMPREPLY=() - _get_comp_words_by_ref cur - - case $cur in - -*) - COMPREPLY=( $( compgen -W '-C -M -c -h' -- "$cur" ) ) - ;; - *) - _filedir - return 0 - ;; - esac - - true -} && -complete -F _mkarchroot mkarchroot - -_arch-nspawn() { - local cur - COMPREPLY=() - _get_comp_words_by_ref cur - - case $cur in - -*) - COMPREPLY=( $( compgen -W '-C -M -c -h' -- "$cur" ) ) - ;; - *) - _filedir - return 0 - ;; - esac - - true -} && -complete -F _arch-nspawn arch-nspawn -# ex:et ts=2 sw=2 ft=sh diff --git a/contrib/completion/bash/devtools.in b/contrib/completion/bash/devtools.in new file mode 100644 index 0000000..e7925b3 --- /dev/null +++ b/contrib/completion/bash/devtools.in @@ -0,0 +1,90 @@ +#!/hint/bash +# +# SPDX-License-Identifier: GPL-3.0-or-later + +_devtools_compgen() { + local i r + COMPREPLY=($(compgen -W '$*' -- "$cur")) + for ((i=1; i < ${#COMP_WORDS[@]}-1; i++)); do + for r in "${!COMPREPLY[@]}"; do + if [[ ${COMP_WORDS[i]} = "${COMPREPLY[r]}" ]]; then + unset 'COMPREPLY[r]'; break + fi + done + done +} + +_archco_pkg() { + _devtools_compgen "$( + command pacman "-$1" + )" +} + +_archco() { + local cur prev + COMPREPLY=() + cur=$(_get_cword) + prev=${COMP_WORDS[COMP_CWORD-1]} + + _archco_pkg Slq + true +} && +complete -F _archco archco communityco + +_makechrootpkg() { + local cur + COMPREPLY=() + _get_comp_words_by_ref cur + + case $cur in + -*) + COMPREPLY=( $( compgen -W '-I -c -h -l -r -u' -- "$cur" ) ) + ;; + *) + _filedir + return 0 + ;; + esac + + true +} && +complete -F _makechrootpkg makechrootpkg + +_mkarchroot() { + local cur + COMPREPLY=() + _get_comp_words_by_ref cur + + case $cur in + -*) + COMPREPLY=( $( compgen -W '-C -M -c -h' -- "$cur" ) ) + ;; + *) + _filedir + return 0 + ;; + esac + + true +} && +complete -F _mkarchroot mkarchroot + +_arch-nspawn() { + local cur + COMPREPLY=() + _get_comp_words_by_ref cur + + case $cur in + -*) + COMPREPLY=( $( compgen -W '-C -M -c -h' -- "$cur" ) ) + ;; + *) + _filedir + return 0 + ;; + esac + + true +} && +complete -F _arch-nspawn arch-nspawn +# ex:et ts=2 sw=2 ft=sh diff --git a/contrib/completion/zsh/_devtools.in b/contrib/completion/zsh/_devtools.in new file mode 100644 index 0000000..eee9776 --- /dev/null +++ b/contrib/completion/zsh/_devtools.in @@ -0,0 +1,129 @@ +#compdef archbuild archco arch-nspawn archrelease commitpkg diffpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-x86_64-build=archbuild testing-x86_64-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco checkpkg sogrep offload-build makerepropkg +# +# SPDX-License-Identifier: GPL-3.0-or-later + +m4_include(lib/valid-tags.sh) +m4_include(lib/valid-repos.sh) + +_binary_arch=${_arch[*]:0:-1} + +_archbuild_args=( + '-c[Recreate the chroot before building]' + '-r[Create chroots in this directory]:base_dir:_files -/' + '-h[Display usage]' + '--[Introduce makechrootpkg options]:*::makechrootpkg options:= _dispatch makechrootpkg makechrootpkg' +) + +_archco_args=( + '*:packages:_devtools_completions_all_packages' +) + +_arch_nspawn_args=( + '-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"' + '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' + '-c[Set pacman cache]:pacman_cache:_files -/' + '-f[Copy file from the host to the chroot]:copy_file:_files' + '-s[Do not run setarch]' + '-h[Display usage]' + '1:chroot_dir:_files -/' +) + +_archrelease_args=( + '-f[Force release without checks]' + "*:arch:($_tags[*])" +) + +_commitpkg_args=( + '-f[Force release without checks]' + '-s[Target repo server]' + '-l[Set bandwidth limit]:limit' + "-a[Release to a specific architecture only]:arch:($_arch[*])" + '1:commit_msg' +) + +_diffpkg_args=( + '(-l --list)'{-l,--list}'[Tar content list diff mode]' + '(-d --diffoscope)'{-d,--diffoscope}'[Diffoscope diff mode]' + '(-p --pkginfo)'{-p,--pkginfo}'[.PKGINFO diff mode]' + '(-b --buildinfo)'{-b,--buildinfo}'[.BUILDINFO diff mode]' + '(-m --makepkg-config)'{-m,--makepkg-config}'[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' + '(-v --verbose)'{-v,--verbose}'[Provide more detailed/unfiltered output]' + '(-h --help)'{-h,--help}'[Display usage]' + '*:packages:_devtools_completions_all_packages' +) + +_finddeps_args=( + '1:packages:_devtools_completions_all_packages' +) + +_makechrootpkg_args=( + '-h[Display usage]' + '-c[Clean the chroot before building]' + '-d[Bind directory into build chroot as read-write]:bind_dir_rw:_files -/' + '-D[Bind directory into build chroot as read-only]:bind_dir_ro:_files -/' + '-u[Update the working copy of the chroot before building]' + '-r[The chroot dir to use]:chroot_dir:_files -/' + '-I[Install a package into the working copy]:target:_files -g "*.pkg.tar.*(.)"' + '-l[The directory to use as the working copy]:copy_dir:_files -/' + '-n[Run namcap on the package]' + '-T[Build in a temporary directory]' + '-U[Run makepkg as a specified user]:makepkg_user' +) + +_mkarchroot_args=( + '-U[Install a package into the working copy]:target:_files -g "*.pkg.tar.*(.)"' + '-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"' + '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' + '-c[Set pacman cache]:pacman_cache:_files -/' + '-h[Display usage]' + '1:working_dir:_files -/' + '*:packages:_devtools_completions_all_packages' +) + +_rebuildpkgs_args=( + '1:chroot_dir:_files -/' + '*:packages:_devtools_completions_all_packages' +) + +_checkpkg_args=( + '(-r --rmdir)'{-r,--rmdir}'[Remove the temporary directory]' + '(-w --warn)'{-w,--warn}'[Print a warning in case of differences]' + '(-M --makepkg-config)'{-M,--makepkg-config}'[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' + '(-h --help)'{-h,--help}'[Display usage]' +) + +_sogrep_args=( + '(-v --verbose)'{-v,--verbose}'[Show matched links in addition to pkgname]' + '(-r --refresh)'{-r,--refresh}'[Refresh the links databases]' + '(-h --help)'{-h,--help}'[Display usage]' + '1:repo:(all $_repos[*])' + '2:libname' +) + +_offload_build_args=( + '(-r --repo)'{-r,--repo}'[Build against a specific repository]:repo:($_build_repos[*])' + '(-a --arch)'{-a,--arch}'[Build against a specific architecture]:arch:(${_binary_arch[*]})' + '(-s --server)'{-s,--server}'[Offload to a specific Build server]:server:' + '(-h --help)'{-h,--help}'[Display usage]' +) + +_makerepropkg_args=( + '-d[Run diffoscope if the package is unreproducible]' + '-c[Set pacman cache]:pacman_cache:_files -/' + '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' + '-h[Display usage]' + '*:working_dir:_files -g "*.pkg.tar.*(.)"' +) + +_devtools_completions_all_packages() { + typeset -U packages + packages=($(_call_program packages pacman -Sql)) + compadd - "${(@)packages}" +} + +_devtools() { + local argname="_${service//-/_}_args[@]" + _arguments -s "${(P)argname}" +} + +_devtools diff --git a/zsh_completion.in b/zsh_completion.in deleted file mode 100644 index eee9776..0000000 --- a/zsh_completion.in +++ /dev/null @@ -1,129 +0,0 @@ -#compdef archbuild archco arch-nspawn archrelease commitpkg diffpkg finddeps makechrootpkg mkarchroot rebuildpkgs extrapkg=commitpkg corepkg=commitpkg testingpkg=commitpkg stagingpkg=commitpkg communitypkg=commitpkg community-testingpkg=commitpkg community-stagingpkg=commitpkg multilibpkg=commitpkg multilib-testingpkg=commitpkg extra-x86_64-build=archbuild testing-x86_64-build=archbuild staging-x86_64-build=archbuild multilib-build=archbuild multilib-testing-build=archbuild multilib-staging-build=archbuild kde-unstable-x86_64-build=archbuild gnome-unstable-x86_64-build=archbuild communityco=archco checkpkg sogrep offload-build makerepropkg -# -# SPDX-License-Identifier: GPL-3.0-or-later - -m4_include(lib/valid-tags.sh) -m4_include(lib/valid-repos.sh) - -_binary_arch=${_arch[*]:0:-1} - -_archbuild_args=( - '-c[Recreate the chroot before building]' - '-r[Create chroots in this directory]:base_dir:_files -/' - '-h[Display usage]' - '--[Introduce makechrootpkg options]:*::makechrootpkg options:= _dispatch makechrootpkg makechrootpkg' -) - -_archco_args=( - '*:packages:_devtools_completions_all_packages' -) - -_arch_nspawn_args=( - '-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"' - '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' - '-c[Set pacman cache]:pacman_cache:_files -/' - '-f[Copy file from the host to the chroot]:copy_file:_files' - '-s[Do not run setarch]' - '-h[Display usage]' - '1:chroot_dir:_files -/' -) - -_archrelease_args=( - '-f[Force release without checks]' - "*:arch:($_tags[*])" -) - -_commitpkg_args=( - '-f[Force release without checks]' - '-s[Target repo server]' - '-l[Set bandwidth limit]:limit' - "-a[Release to a specific architecture only]:arch:($_arch[*])" - '1:commit_msg' -) - -_diffpkg_args=( - '(-l --list)'{-l,--list}'[Tar content list diff mode]' - '(-d --diffoscope)'{-d,--diffoscope}'[Diffoscope diff mode]' - '(-p --pkginfo)'{-p,--pkginfo}'[.PKGINFO diff mode]' - '(-b --buildinfo)'{-b,--buildinfo}'[.BUILDINFO diff mode]' - '(-m --makepkg-config)'{-m,--makepkg-config}'[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' - '(-v --verbose)'{-v,--verbose}'[Provide more detailed/unfiltered output]' - '(-h --help)'{-h,--help}'[Display usage]' - '*:packages:_devtools_completions_all_packages' -) - -_finddeps_args=( - '1:packages:_devtools_completions_all_packages' -) - -_makechrootpkg_args=( - '-h[Display usage]' - '-c[Clean the chroot before building]' - '-d[Bind directory into build chroot as read-write]:bind_dir_rw:_files -/' - '-D[Bind directory into build chroot as read-only]:bind_dir_ro:_files -/' - '-u[Update the working copy of the chroot before building]' - '-r[The chroot dir to use]:chroot_dir:_files -/' - '-I[Install a package into the working copy]:target:_files -g "*.pkg.tar.*(.)"' - '-l[The directory to use as the working copy]:copy_dir:_files -/' - '-n[Run namcap on the package]' - '-T[Build in a temporary directory]' - '-U[Run makepkg as a specified user]:makepkg_user' -) - -_mkarchroot_args=( - '-U[Install a package into the working copy]:target:_files -g "*.pkg.tar.*(.)"' - '-C[Location of a pacman config file]:pacman_config:_files -g "*.conf(.)"' - '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' - '-c[Set pacman cache]:pacman_cache:_files -/' - '-h[Display usage]' - '1:working_dir:_files -/' - '*:packages:_devtools_completions_all_packages' -) - -_rebuildpkgs_args=( - '1:chroot_dir:_files -/' - '*:packages:_devtools_completions_all_packages' -) - -_checkpkg_args=( - '(-r --rmdir)'{-r,--rmdir}'[Remove the temporary directory]' - '(-w --warn)'{-w,--warn}'[Print a warning in case of differences]' - '(-M --makepkg-config)'{-M,--makepkg-config}'[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' - '(-h --help)'{-h,--help}'[Display usage]' -) - -_sogrep_args=( - '(-v --verbose)'{-v,--verbose}'[Show matched links in addition to pkgname]' - '(-r --refresh)'{-r,--refresh}'[Refresh the links databases]' - '(-h --help)'{-h,--help}'[Display usage]' - '1:repo:(all $_repos[*])' - '2:libname' -) - -_offload_build_args=( - '(-r --repo)'{-r,--repo}'[Build against a specific repository]:repo:($_build_repos[*])' - '(-a --arch)'{-a,--arch}'[Build against a specific architecture]:arch:(${_binary_arch[*]})' - '(-s --server)'{-s,--server}'[Offload to a specific Build server]:server:' - '(-h --help)'{-h,--help}'[Display usage]' -) - -_makerepropkg_args=( - '-d[Run diffoscope if the package is unreproducible]' - '-c[Set pacman cache]:pacman_cache:_files -/' - '-M[Location of a makepkg config file]:makepkg_config:_files -g "*.conf(.)"' - '-h[Display usage]' - '*:working_dir:_files -g "*.pkg.tar.*(.)"' -) - -_devtools_completions_all_packages() { - typeset -U packages - packages=($(_call_program packages pacman -Sql)) - compadd - "${(@)packages}" -} - -_devtools() { - local argname="_${service//-/_}_args[@]" - _arguments -s "${(P)argname}" -} - -_devtools -- cgit v1.2.3-70-g09d2