Skip to content

Commit ae38166

Browse files
author
Paul Holzinger
committed
Install the new shell completion logic
Add a new make target (completion) to generate the shell completion scripts. This will generate the scripts for bash, zsh and fish for both podman and podman-remote with `podman completion`. The scripts are put into the completions directory and can be installed system wide with `sudo make install.completions`. This commit replaces the current handwritten scripts for bash and zsh. The `validate.completion` target has been adjusted to make sure nobody edits these scripts directly. Signed-off-by: Paul Holzinger <[email protected]>
1 parent b5d1d89 commit ae38166

File tree

10 files changed

+1256
-3934
lines changed

10 files changed

+1256
-3934
lines changed

Makefile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ OCI_RUNTIME ?= ""
4848

4949
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
5050
ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
51+
FISHINSTALLDIR=${PREFIX}/share/fish/vendor_completions.d
5152

5253
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
5354

@@ -474,6 +475,15 @@ changelog: ## Generate changelog
474475
$(shell cat $(TMPFILE) >> changelog.txt)
475476
$(shell rm $(TMPFILE))
476477

478+
completions: binaries
479+
install ${SELINUXOPT} -d -m 755 completions/{bash,zsh,fish}
480+
./bin/podman completion bash --no-desc -f completions/bash/podman
481+
./bin/podman-remote completion bash --no-desc -f completions/bash/podman-remote
482+
./bin/podman completion zsh -f completions/zsh/_podman
483+
./bin/podman-remote completion zsh -f completions/zsh/_podman-remote
484+
./bin/podman completion fish -f completions/fish/podman.fish
485+
./bin/podman-remote completion fish -f completions/fish/podman-remote.fish
486+
477487
.PHONY: install
478488
install: .gopathok install.bin install.remote install.man install.cni install.systemd ## Install binaries to system locations
479489

@@ -512,8 +522,13 @@ install.man: docs install.man-nobuild
512522
install.completions:
513523
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
514524
install ${SELINUXOPT} -m 644 completions/bash/podman ${DESTDIR}${BASHINSTALLDIR}
525+
install ${SELINUXOPT} -m 644 completions/bash/podman-remote ${DESTDIR}${BASHINSTALLDIR}
515526
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
516527
install ${SELINUXOPT} -m 644 completions/zsh/_podman ${DESTDIR}${ZSHINSTALLDIR}
528+
install ${SELINUXOPT} -m 644 completions/zsh/_podman-remote ${DESTDIR}${ZSHINSTALLDIR}
529+
install ${SELINUXOPT} -d -m 755 ${DESTDIR}${FISHINSTALLDIR}
530+
install ${SELINUXOPT} -m 644 completions/fish/podman.fish ${DESTDIR}${FISHINSTALLDIR}
531+
install ${SELINUXOPT} -m 644 completions/fish/podman-remote.fish ${DESTDIR}${FISHINSTALLDIR}
517532

518533
.PHONY: install.cni
519534
install.cni:
@@ -656,9 +671,20 @@ API.md: pkg/varlink/io.podman.varlink
656671
$(GO) generate ./docs/...
657672

658673
.PHONY: validate.completions
659-
validate.completions: completions/bash/podman
674+
validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
675+
validate.completions:
676+
# Check that nobody has manually edited the completion scripts
677+
# If this check fails run make completions to restore the correct scripts
678+
diff completions/bash/podman <(./bin/podman completion --no-desc bash)
679+
diff completions/zsh/_podman <(./bin/podman completion zsh)
680+
diff completions/fish/podman.fish <(./bin/podman completion fish)
681+
diff completions/bash/podman-remote <(./bin/podman-remote completion --no-desc bash)
682+
diff completions/zsh/_podman-remote <(./bin/podman-remote completion zsh)
683+
diff completions/fish/podman-remote.fish <(./bin/podman-remote completion fish)
684+
# Check if the files can be loaded by the shell
660685
. completions/bash/podman
661686
if [ -x /bin/zsh ]; then /bin/zsh completions/zsh/_podman; fi
687+
if [ -x /bin/fish ]; then /bin/fish completions/fish/podman.fish; fi
662688

663689
.PHONY: validate
664690
validate: gofmt lint .gitvalidation validate.completions man-page-check swagger-check

completions/Readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Shell completion scripts
2+
3+
Podman offers shell completion scripts for bash, zsh and fish. The completion scripts are available for both `podman` and `podman-remote`.
4+
5+
The shell completion scripts are generated by `make completion`, do not edit these files directly. To install them you can run `sudo make install.completions`.
6+
7+
For information about these sripts see [`man podman-completion`](../docs/source/markdown/podman-completion.1.md)

0 commit comments

Comments
 (0)