aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile17
-rwxr-xr-xcompletion/make.sh61
-rw-r--r--completion/zsh.patch50
3 files changed, 113 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 8ceddbf..6259f57 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ MAN_PAGES = \
TARGETS = \
completion/bash \
+ completion/zsh \
lib/bisect \
src/pakku \
${MAN_PAGES}
@@ -21,6 +22,7 @@ DIST = \
pakku.conf \
completion/bash.patch \
completion/make.sh \
+ completion/zsh.patch \
doc/asciidoc.conf \
${MAN_PAGES:=.txt} \
lib/*.nim \
@@ -36,7 +38,8 @@ PREFIX = /usr/local
BINDIR = ${PREFIX}/bin
PKGLIBDIR = ${PREFIX}/lib/pakku
-COMPLETIONSDIR = ${PREFIX}/share/bash-completion/completions
+BASHCOMPLETIONSDIR = ${PREFIX}/share/bash-completion/completions
+ZSHCOMPLETIONSDIR = ${PREFIX}/share/zsh/site-functions
MANDIR = ${PREFIX}/share/man
LOCALSTATEDIR = /var
SYSCONFDIR = /etc
@@ -79,7 +82,11 @@ all: \
completion/bash: completion/make.sh completion/bash.patch
@echo "GEN: $@"
- @(cd completion && ./make.sh)
+ @(cd completion && ./make.sh 'bash')
+
+completion/zsh: completion/make.sh completion/zsh.patch
+ @echo "GEN: $@"
+ @(cd completion && ./make.sh 'zsh')
${MAN_PAGES:=.in}: ${MAN_PAGES:=.txt}
@echo "GEN: $@"
@@ -127,7 +134,8 @@ define uninstall
endef
install:
- $(call install,644,'completion/bash','${COMPLETIONSDIR}/pakku')
+ $(call install,644,'completion/bash','${BASHCOMPLETIONSDIR}/pakku')
+ $(call install,644,'completion/zsh','${ZSHCOMPLETIONSDIR}/_pakku')
$(call install,644,'doc/pakku.8','${MANDIR}/man8/pakku.8')
$(call install,644,'doc/pakku.conf.5','${MANDIR}/man5/pakku.conf.5')
$(call install,755,'lib/bisect','${PKGLIBDIR}/bisect')
@@ -135,7 +143,8 @@ install:
$(call install,644,'pakku.conf','${SYSCONFDIR}/pakku.conf')
uninstall:
- $(call uninstall,'${COMPLETIONSDIR}','pakku')
+ $(call uninstall,'${BASHCOMPLETIONSDIR}','pakku')
+ $(call uninstall,'${ZSHCOMPLETIONSDIR}','_pakku')
$(call uninstall,'${MANDIR}/man8','pakku.8')
$(call uninstall,'${MANDIR}/man5','pakku.conf.5')
$(call uninstall,'${PKGLIBDIR}','bisect')
diff --git a/completion/make.sh b/completion/make.sh
index 51b0730..323dad6 100755
--- a/completion/make.sh
+++ b/completion/make.sh
@@ -1,21 +1,60 @@
#!/bin/bash
pacman_bash_completion='/usr/share/bash-completion/completions/pacman'
+pacman_zsh_completion='/usr/share/zsh/site-functions/_pacman'
+
+function error() {
+ local code="$?"
+ rm "$1"
+ exit "$code"
+}
+
+function apply-patch() {
+ patch -sNp1 -r - --no-backup-if-mismatch -i "$1"
+}
function delete-shell-fn() {
perl -0777 -pe 's/\n'"$1"'\(\) *\{\n([^}].*\n)*\}\n*/\n\n/g;s/\n{3,}/\n\n/g'
}
-cat "$pacman_bash_completion" |
-delete-shell-fn '_pacman_keyids' |
-delete-shell-fn '_pacman_key' |
-delete-shell-fn '_makepkg' |
-sed 's/^_pacman() {$/_pakku() {/' \
-> 'bash' || {
- rm 'bash'
- exit 1
+function delete-shell-array() {
+ perl -0777 -pe 's/\n'"$1"'=\(\n([^)].*\n)*\)\n?//g'
+}
+
+[ "$1" = 'bash' ] && {
+ cat "$pacman_bash_completion" |
+ delete-shell-fn '_pacman_keyids' |
+ delete-shell-fn '_pacman_key' |
+ delete-shell-fn '_makepkg' |
+ sed 's/^_pacman() {$/_pakku() {/' \
+ > 'bash' ||
+ error 'bash'
+
+ apply-patch 'bash.patch' ||
+ error 'bash'
+
+ exit 0
}
-patch -sNp1 -r - --no-backup-if-mismatch -i 'bash.patch' || {
- rm 'bash'
- exit 1
+
+[ "$1" = 'zsh' ] && {
+ cat "$pacman_zsh_completion" |
+ delete-shell-array '_key_shortopts' |
+ delete-shell-array '_key_longopts' |
+ delete-shell-array '_pacman_key_options' |
+ delete-shell-fn '_pacman_key' |
+ delete-shell-fn '_keys' |
+ delete-shell-array '_makepkg_shortopts' |
+ delete-shell-array '_makepkg_longopts' |
+ delete-shell-fn '_makepkg_action_none' |
+ delete-shell-fn '_makepkg' |
+ sed 's/_pacman/_pakku/g' \
+ > 'zsh' ||
+ error 'zsh'
+
+ apply-patch 'zsh.patch' ||
+ error 'zsh'
+
+ exit 0
}
+
+exit 1
diff --git a/completion/zsh.patch b/completion/zsh.patch
new file mode 100644
index 0000000..c3eb8c9
--- /dev/null
+++ b/completion/zsh.patch
@@ -0,0 +1,50 @@
+--- a/zsh
++++ b/zsh
+@@ -1,1 +1,1 @@
+-#compdef pacman pacman.static=pacman pacman-key makepkg
++#compdef pakku
+@@ -139,2 +139,6 @@
+ '--print-format[Specify how the targets should be printed]'
++ {-n,--build}'[Build targets from source]'
++ '--keyserver[Keyserver to receive keys from]'
++ '--noaur[Disable all AUR operations]'
++ {-z,--source}'[Retrieve PKGBUILD source]'
+ )
+@@ -310,1 +314,6 @@
+- packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
++ if [[ ${words[CURRENT]%/*} == 'aur' ]]; then
++ packages=( $(_call_program packages $cmd[@] -Ss ${words[CURRENT]#*/} |
++ grep -Po '(?<=^aur/)[^ ]+') )
++ else
++ packages=( $(_call_program packages $cmd[@] -Sql ${words[CURRENT]%/*}) )
++ fi
+@@ -314,1 +323,1 @@
+- packages=( $(_call_program packages $cmd[@] -Sql) )
++ packages=( $(_call_program packages $cmd[@] -Ssq ${words[CURRENT]}) )
+@@ -318,1 +327,1 @@
+- repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options})
++ repositories=(${(o)${${${(M)${(f)"$(</etc/pacman.conf)"}:#\[*}/\[/}/\]/}:#options} aur)
+@@ -361,1 +370,1 @@
+- cmd=( "pacman" "2>/dev/null")
++ cmd=("pakku" "2>/dev/null")
+@@ -371,1 +380,1 @@
+-_pakku_zsh_comp() {
++_pakku_comp() {
+@@ -501,17 +510,0 @@
+-
+-_pakku_comp() {
+- case "$service" in
+- makepkg)
+- _makepkg "$@"
+- ;;
+- pacman-key)
+- _pakku_key "$@"
+- ;;
+- pacman)
+- _pakku_zsh_comp "$@"
+- ;;
+- *)
+- _message "Error"
+- ;;
+- esac
+-}