git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] contrib/completion: install Bash completion

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 22, 2025, 08:36 UTC
Message-ID
<20250422-b4-pks-meson-install-completions-v2-1-ab29d399bc6c@pks.im>
In-Reply-To
<20250407-b4-pks-meson-install-completions-v1-1-8a7eb8b9284b@pks.im>

The shell completion scripts in "contrib/completion" are being tested, but none of our build systems support installing them. This is somewhat confusing for Meson, where users can explicitly enable building these scripts via `-Dcontrib=completion`. This option only controlls whether the completions are built and tested against, where "building" is a bit of an euphemism for "copying them into the build directory".

Teach both our Makefile and Meson to install our Bash completion script. For now, this is the only completion script that we're installing given that Bash completions "just work" with a canonical well-known location nowadays. Other completion scripts, like for example the one for zsh, don't have a well-known location and/or require extra steps by the user to make them available. As such, we skip installing these scripts for now, but we may do so in the future if we ever figure out a proper way to do this.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
Hi,
this patch is a result from the discussion at [1]. Thanks!
Changes in v2:
 - Only install Bash completion for now.
 - Also install Bash completion via our Makefile.
 - Link to v1: https://lore.kernel.org/r/20250407-b4-pks-meson-install-completions-v1-1-8a7eb8b9284b@pks.im
Patrick
[1]: <Z-uLqQd7QHZq-tB7@akshay.is>
---
 Makefile                       |  6 ++++++
 contrib/completion/meson.build | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)
diff --git a/Makefile b/Makefile
index ac32d2d0bda..118592414b5 100644
--- a/Makefile
+++ b/Makefile
@@ -618,6 +618,7 @@ prefix = $(HOME)
 bindir = $(prefix)/bin
 mandir = $(prefix)/share/man
 infodir = $(prefix)/share/info
+bash_completion_dir = $(prefix)/share/bash-completion/completions
 gitexecdir = libexec/git-core
 mergetoolsdir = $(gitexecdir)/mergetools
 sharedir = $(prefix)/share
@@ -2321,6 +2322,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
 mandir_SQ = $(subst ','\'',$(mandir))
 mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
 infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
+bash_completion_dir_SQ = $(subst ','\'',$(bash_completion_dir))
 perllibdir_SQ = $(subst ','\'',$(perllibdir))
 localedir_SQ = $(subst ','\'',$(localedir))
 localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
@@ -3565,6 +3567,10 @@ endif
 ifneq (,$X)
 	$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_COMMANDS_TO_INSTALL) $(OTHER_PROGRAMS))), test '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p' -ef '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p$X' || $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
 endif
+ifndef NO_BASH_COMPLETION
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bash_completion_dir_SQ)' && \
+	$(INSTALL) -m 644 contrib/completion/git-completion.bash '$(DESTDIR_SQ)$(bash_completion_dir_SQ)/git'
+endif
 
 	bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
 	execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
diff --git a/contrib/completion/meson.build b/contrib/completion/meson.build
index 3a9ddab5940..576125b083d 100644
--- a/contrib/completion/meson.build
+++ b/contrib/completion/meson.build
@@ -14,3 +14,21 @@ foreach script : [
     )
   endif
 endforeach
+
+# We have to discern between the test dependency and the installed file. Our
+# tests assume the completion scripts to have the same name as the in-tree
+# files, but the installed filenames need to match the executable's basename.
+if meson.version().version_compare('>=1.3.0')
+  fs.copyfile('git-completion.bash', 'git',
+    install: true,
+    install_dir: get_option('datadir') / 'bash-completion/completions',
+  )
+else
+  configure_file(
+    input: 'git-completion.bash',
+    output: 'git',
+    copy: true,
+    install: true,
+    install_dir: get_option('datadir') / 'bash-completion/completions',
+  )
+endif

---
base-commit: 5b97a56fa0e7d580dc8865b73107407c9b3f0eff
change-id: 20250407-b4-pks-meson-install-completions-e5552f1ae2bf
Previous: Patrick Steinhardt
Message 8 of 8 in “meson: install shell completion scripts”
  1. meson: install shell completion scriptsPatrick Steinhardt, Apr 7, 2025
  2. Akshay HegdeApr 8, 2025
  3. Todd ZullingerApr 8, 2025
  4. Junio C HamanoApr 9, 2025
  5. Eli SchwartzApr 17, 2025
  6. Junio C HamanoApr 17, 2025
  7. Patrick SteinhardtApr 22, 2025
  8. contrib/completion: install Bash completionPatrick Steinhardt, Apr 22, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.