From adc39b533a8d1215205a2f3fba1e12d9c313ab5f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 27 Nov 2015 00:22:29 +0100 Subject: add shell tab-completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 62 +++++++++++++++++++++++++++++++++------- src/adjbacklight.auto-completion | 19 ++++++++++++ 2 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 src/adjbacklight.auto-completion diff --git a/Makefile b/Makefile index 45ece5e..a2f5ceb 100644 --- a/Makefile +++ b/Makefile @@ -43,10 +43,10 @@ WARN = -Wall -Wextra -Wdouble-promotion -Wformat=2 -Winit-self -Wmissing-include # compile the package .PHONY: default -default: code info +default: code info shell .PHONY: all -all: code doc +all: code doc shell .PHONY: code code: bin/adjbacklight @@ -89,13 +89,34 @@ bin/%.ps: $(MANUALDIR)%.texinfo cd obj/ps && texi2pdf --ps ../../"$<" < /dev/null mv obj/ps/$*.ps $@ +.PHONY: shell +shell: bash fish zsh + +.PHONY: bash +bash: adjbacklight.bash-completion + +.PHONY: fish +fish: adjbacklight.fish-completion + +.PHONY: zsh +zsh: adjbacklight.zsh-completion + +obj/adjbacklight.auto-completion: src/adjbacklight.auto-completion + @mkdir -p obj + cp "$<" "$@" + sed -i 's/^(adjbacklight$$/($(COMMAND)/' "$@" + +bin/adjbacklight.%sh-completion: obj/adjbacklight.auto-completion + @mkdir -p bin + auto-auto-complete "$*sh" --output "$@" --source "$<" + # install to system .PHONY: install -install: install-base install-info +install: install-base install-info install-shell .PHONY: install-all -install-all: install-base install-doc +install-all: install-base install-doc install-shell .PHONY: install-base install-base: install-cmd install-copyright @@ -110,12 +131,12 @@ install-copyright: install-copying install-license .PHONY: install-copying install-copying: - install -d -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" + install -dm755 -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" install -m644 -- COPYING "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" .PHONY: install-license install-license: - install -d -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" + install -dm755 -- "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" install -m644 -- LICENSE "$(DESTDIR)$(LICENSEDIR)/$(PKGNAME)" .PHONY: install-doc @@ -123,24 +144,42 @@ install-doc: install-info install-pdf install-dvi install-ps .PHONY: install-info install-info: bin/$(MANUAL).info - install -d -- "$(DESTDIR)$(INFODIR)" + install -dm755 -- "$(DESTDIR)$(INFODIR)" install -m644 -- "$<" "$(DESTDIR)$(INFODIR)/$(PKGNAME).info" .PHONY: install-pdf install-pdf: bin/$(MANUAL).pdf - install -d -- "$(DESTDIR)$(DOCDIR)" + install -dm755 -- "$(DESTDIR)$(DOCDIR)" install -m644 -- "$<" "$(DESTDIR)$(DOCDIR)/$(PKGNAME).pdf" .PHONY: install-dvi install-dvi: bin/$(MANUAL).dvi - install -d -- "$(DESTDIR)$(DOCDIR)" + install -dm755 -- "$(DESTDIR)$(DOCDIR)" install -m644 -- "$<" "$(DESTDIR)$(DOCDIR)/$(PKGNAME).dvi" .PHONY: install-ps install-ps: bin/$(MANUAL).ps - install -d -- "$(DESTDIR)$(DOCDIR)" + install -dm755 -- "$(DESTDIR)$(DOCDIR)" install -m644 -- "$<" "$(DESTDIR)$(DOCDIR)/$(PKGNAME).ps" +.PHONY: install-shell +install-shell: install-bash install-fish install-zsh + +.PHONY: install-bash +install-bash: bin/adjbacklight.bash-completion + install -dm755 -- "$(DESTDIR)$(DATADIR)/bash-completion/completions" + install -m644 "$<" -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(COMMAND)" + +.PHONY: install-fish +install-fish: bin/adjbacklight.fish-completion + install -dm755 -- "$(DESTDIR)$(DATADIR)/fish/completions" + install -m644 "$<" -- "$(DESTDIR)$(DATADIR)/fish/completions/$(COMMAND).fish" + +.PHONY: install-zsh +install-zsh: bin/adjbacklight.zsh-completion + install -dm755 -- "$(DESTDIR)$(DATADIR)/zsh/site-functions)" + install -m644 "$<" -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(COMMAND)" + # remove files created by `install` .PHONY: uninstall @@ -153,6 +192,9 @@ uninstall: -rm -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).pdf" -rm -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).dvi" -rm -- "$(DESTDIR)$(DOCDIR)/$(PKGNAME).ps" + -rm -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(COMMAND)" + -rm -- "$(DESTDIR)$(DATADIR)/fish/completions/$(COMMAND).fish" + -rm -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(COMMAND)" # remove files created by `all` diff --git a/src/adjbacklight.auto-completion b/src/adjbacklight.auto-completion new file mode 100644 index 0000000..aca9796 --- /dev/null +++ b/src/adjbacklight.auto-completion @@ -0,0 +1,19 @@ +(adjbacklight + (default (arg '(+|-|=)LEVEL[%|%%]') (files -0) (description 'Adjust backlight')) + + (unargumented (options -c --copyright --copying) (complete --copying) + (desc 'Display copyright information')) + + (unargumented (options -w --warranty) (complete --warranty) + (desc 'Display warranty disclaimer')) + + (unargumented (options -a --all) (complete --all) + (desc 'Run for all devices, including ACPI devices')) + + (unargumented (options -g --get) (complete --get) + (desc 'Get average brightness on devices')) + + (argumented (options -s --set) (complete --set) (files 'LEVEL[%]') (files -0) + (desc 'Set brightness on devices')) +) + -- cgit v1.2.3-70-g09d2