summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaizhao Zhang2019-01-15 13:34:43 +0800
committerKaizhao Zhang2019-01-15 13:34:43 +0800
commit1523642d42b63e6d6c5b237d1a55cffa0102e075 (patch)
tree9d05c2acaed6d2c7c46cecca86f4829bd1a8856c
parent91b3cb67f5b49379f57098de875e53bb18b0f404 (diff)
downloadaur-1523642d42b63e6d6c5b237d1a55cffa0102e075.tar.gz
Add tab completions for Bash and Zsh
-rw-r--r--.SRCINFO6
-rw-r--r--PKGBUILD19
-rw-r--r--hatch_complete.sh21
-rw-r--r--hatch_complete.zsh28
-rw-r--r--python-hatch.sh5
5 files changed, 77 insertions, 2 deletions
diff --git a/.SRCINFO b/.SRCINFO
index a02376e39ea3..38135ad73447 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = python-hatch
pkgdesc = A modern project, package, and virtual env manager
pkgver = 0.11.0
- pkgrel = 1
+ pkgrel = 2
url = https://github.com/ofek/hatch
arch = any
license = MIT
@@ -25,7 +25,11 @@ pkgbase = python-hatch
provides = python-hatch
options = !emptydirs
source = https://github.com/ofek/hatch/archive/0.11.0.tar.gz
+ source = hatch_complete.sh
+ source = hatch_complete.zsh
sha256sums = 89eb2417503125919f5536b0c50390affa2536b193ddcfc826ad96a4d17e7678
+ sha256sums = b87254c621719188907a2062b0aa3c4eb078088872d1de7d53d6a6d61a679c44
+ sha256sums = a43679d72ebb7b5c029192519597eff835586d0b6ed9d1e3dfc93270b8720e71
pkgname = python-hatch
diff --git a/PKGBUILD b/PKGBUILD
index d1e4f6f9317b..034b63fbf4ae 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -4,7 +4,7 @@ _srcname=hatch
pkgname=python-hatch
pkgver=0.11.0
-pkgrel=1
+pkgrel=2
pkgdesc="A modern project, package, and virtual env manager"
arch=('any')
url="https://github.com/ofek/hatch"
@@ -31,9 +31,13 @@ provides=('python-hatch')
options=(!emptydirs)
source=(
"https://github.com/ofek/hatch/archive/${pkgver}.tar.gz"
+ 'hatch_complete.sh'
+ 'hatch_complete.zsh'
)
sha256sums=(
'89eb2417503125919f5536b0c50390affa2536b193ddcfc826ad96a4d17e7678'
+ 'b87254c621719188907a2062b0aa3c4eb078088872d1de7d53d6a6d61a679c44'
+ 'a43679d72ebb7b5c029192519597eff835586d0b6ed9d1e3dfc93270b8720e71'
)
prepare() {
@@ -56,4 +60,17 @@ package() {
install -Dm644 README.rst "${pkgdir}/usr/share/doc/${pkgname}/README.rst"
install -Dm644 LICENSE-MIT "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE-MIT"
install -Dm644 LICENSE-APACHE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE-APACHE"
+
+ cd "${srcdir}"
+
+ # Tab completions.
+ # via https://github.com/ofek/hatch/issues/57 and https://click.palletsprojects.com/en/7.x/bashcomplete/
+
+ # Tab completion for Bash.
+ # Generated by `_HATCH_COMPLETE=source hatch > hatch_complete.sh`
+ install -Dm644 hatch_complete.sh "${pkgdir}/usr/share/bash-completion/completions/${_srcname}"
+
+ # Tab completion for Zsh.
+ # Generated by `_HATCH_COMPLETE=source_zsh hatch > hatch_complete.zsh`
+ install -Dm644 hatch_complete.zsh "${pkgdir}/usr/share/zsh/site-functions/_${_srcname}"
}
diff --git a/hatch_complete.sh b/hatch_complete.sh
new file mode 100644
index 000000000000..0ce2d9886b88
--- /dev/null
+++ b/hatch_complete.sh
@@ -0,0 +1,21 @@
+_hatch_completion() {
+ local IFS=$'
+'
+ COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
+ COMP_CWORD=$COMP_CWORD \
+ _HATCH_COMPLETE=complete $1 ) )
+ return 0
+}
+
+_hatch_completionetup() {
+ local COMPLETION_OPTIONS=""
+ local BASH_VERSION_ARR=(${BASH_VERSION//./ })
+ # Only BASH version 4.4 and later have the nosort option.
+ if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
+ COMPLETION_OPTIONS="-o nosort"
+ fi
+
+ complete $COMPLETION_OPTIONS -F _hatch_completion hatch
+}
+
+_hatch_completionetup;
diff --git a/hatch_complete.zsh b/hatch_complete.zsh
new file mode 100644
index 000000000000..33d3ae350f5c
--- /dev/null
+++ b/hatch_complete.zsh
@@ -0,0 +1,28 @@
+_hatch_completion() {
+ local -a completions
+ local -a completions_with_descriptions
+ local -a response
+ response=("${(@f)$( env COMP_WORDS="${words[*]}" \
+ COMP_CWORD=$((CURRENT-1)) \
+ _HATCH_COMPLETE="complete_zsh" \
+ hatch )}")
+
+ for key descr in ${(kv)response}; do
+ if [[ "$descr" == "_" ]]; then
+ completions+=("$key")
+ else
+ completions_with_descriptions+=("$key":"$descr")
+ fi
+ done
+
+ if [ -n "$completions_with_descriptions" ]; then
+ _describe -V unsorted completions_with_descriptions -U -Q
+ fi
+
+ if [ -n "$completions" ]; then
+ compadd -U -V unsorted -Q -a completions
+ fi
+ compstate[insert]="automenu"
+}
+
+compdef _hatch_completion hatch;
diff --git a/python-hatch.sh b/python-hatch.sh
new file mode 100644
index 000000000000..f7debeb8e521
--- /dev/null
+++ b/python-hatch.sh
@@ -0,0 +1,5 @@
+
+
+ # Tab completion for Bash
+ _HATCH_COMPLETE=source hatch \
+ > "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"