From fcac3b17edcb7cd7c22305bd5c519f9cd7e6c1de Mon Sep 17 00:00:00 2001 From: zsugabubus Date: Wed, 5 Feb 2020 10:03:15 +0100 Subject: [PATCH] Add Zsh completion --- Makefile | 6 ++++++ abduco.zsh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 abduco.zsh diff --git a/Makefile b/Makefile index fe57193..b470b96 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ LDFLAGS_STD ?= -lc -lutil STRIP ?= strip INSTALL ?= install +ZSHPREFIX ?= /usr/local + SRC = abduco.c all: abduco @@ -44,11 +46,15 @@ install: abduco @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < abduco.1 > ${DESTDIR}${MANPREFIX}/man1/abduco.1 @chmod 644 ${DESTDIR}${MANPREFIX}/man1/abduco.1 + @echo installing zsh completion file to ${DESTDIR}${ZSHPREFIX}/share/zsh/site-functions + @install -Dm644 abduco.zsh ${DESTDIR}${ZSHPREFIX}/share/zsh/site-functions/_abduco uninstall: @echo removing executable file from ${DESTDIR}${PREFIX}/bin @rm -f ${DESTDIR}${PREFIX}/bin/abduco @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 @rm -f ${DESTDIR}${MANPREFIX}/man1/abduco.1 + @echo removing zsh completion file from ${DESTDIR}/usr/share/zsh/site-functions + @rm -f ${DESTDIR}${ZSHPREFIX}/share/zsh/site-functions/_abduco .PHONY: all clean dist install-strip install uninstall debug diff --git a/abduco.zsh b/abduco.zsh new file mode 100644 index 0000000..e8e94d1 --- /dev/null +++ b/abduco.zsh @@ -0,0 +1,35 @@ +#compdef abduco + +typeset -A opt_args + +_abduco_sessions() { + declare -a sessions + sessions=( $(abduco | sed '1d;s/.*\t[0-9][0-9]*\t//') ) + _describe -t session 'session' sessions +} + +_abduco_firstarg() { + if (( $+opt_args[-a] || $+opt_args[-A] )); then + _abduco_sessions + elif (( $+opt_args[-c] || $+opt_args[-n] )); then + _guard "^-*" 'session name' + elif [[ -z $words[CURRENT] ]]; then + compadd "$@" -S '' -- - + fi +} + +_arguments -s \ + '(-a -A -c -n -f)-a[attach to an existing session]' \ + '(-a -A -c -n)-A[attach to a session, create if does not exist]' \ + '(-a -A -c -n -l)-c[create a new session and attach to it]' \ + '(-a -A -c -n -l)-n[create a new session but do not attach to it]' \ + '-e[set the detachkey (default: ^\\)]:detachkey' \ + '(-a)-f[force create the session]' \ + '(-q)-p[pass-through mode]' \ + '-q[be quiet]' \ + '-r[read-only session, ignore user input]' \ + '(-c -n)-l[attach with the lowest priority]' \ + '(-)-v[show version information and exit]' \ + '1: :_abduco_firstarg' \ + '2:command:_path_commands' \ + '*:: :{ shift $((CURRENT-3)) words; _precommand; }'