From d310048f7db55f2776d2cf51e155096334c452ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna=20=E2=80=9CCyberTailor=E2=80=9D?= Date: Sat, 6 Jan 2024 20:03:06 +0500 Subject: [PATCH] cli: add shell completions --- .gitignore | 1 + Makefile | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 6 ++++++ 3 files changed, 63 insertions(+) create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index ef4cece..f0f2d84 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ __pycache__ *.pyo +completions docs/_build docs/api dist diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6755aa3 --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: WTFPL +# SPDX-FileCopyrightText: 2024 Anna +# No warranty + +PROG = find-work + +PREFIX ?= /usr/local +MANDIR ?= $(PREFIX)/share/man +BASHCOMPDIR ?= $(PREFIX)/share/bash-completion/completions +ZSHCOMPDIR ?= $(PREFIX)/share/zsh/site-functions +FISHCOMPDIR ?= $(PREFIX)/share/fish/vendor_completions.d + +INSTALL ?= install +INSTALL_DATA ?= $(INSTALL) -m 0644 + +help: + @echo 'usage: make [target] ...' + @echo + @echo 'suggested targets:' + @echo 'install-man - Install manpages' + @echo 'install-comp - Install shell completions' + @echo 'install-data - Shorhand for "install-man install-comp"' + +install-data: install-man install-comp + +install-man: + mkdir -p $(DESTDIR)$(MANDIR)/man1 + $(INSTALL_DATA) man/$(PROG).1 $(DESTDIR)$(MANDIR)/man1 + +install-comp: install-bashcomp install-zshcomp install-fishcomp + +install-bashcomp: completions/$(PROG).bash + mkdir -p $(DESTDIR)$(BASHCOMPDIR) + $(INSTALL_DATA) $< $(DESTDIR)$(BASHCOMPDIR)/$(PROG) + +install-zshcomp: completions/$(PROG).zsh + mkdir -p $(DESTDIR)$(ZSHCOMPDIR) + $(INSTALL_DATA) $< $(DESTDIR)$(ZSHCOMPDIR)/_$(PROG) + +install-fishcomp: completions/$(PROG).fish + mkdir -p $(DESTDIR)$(FISHCOMPDIR) + $(INSTALL_DATA) $< $(DESTDIR)$(FISHCOMPDIR)/$(PROG).fish + +completions/$(PROG).bash: + mkdir -p completions + _FIND_WORK_COMPLETE=bash_source $(PROG) > $@ + +completions/$(PROG).zsh: + mkdir -p completions + _FIND_WORK_COMPLETE=zsh_source $(PROG) > $@ + +completions/$(PROG).fish: + mkdir -p completions + _FIND_WORK_COMPLETE=fish_source $(PROG) > $@ + +.PHONY: help install-data install-man install-comp install-bashcomp install-zshcomp install-fishcomp diff --git a/pyproject.toml b/pyproject.toml index 3c63802..22fcf37 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,6 +40,12 @@ Source = "https://git.sysrq.in/find-work" Issues = "https://bugs.sysrq.in/enter_bug.cgi?product=Software&component=find-work" Changelog = "https://find-work.sysrq.in/release-notes.html" +[tool.flit.sdist] +include = [ + "Makefile", + "man/", +] + [tool.mypy] disallow_untyped_defs = true no_implicit_optional = true