Skip to content

Commit fe35ce2

Browse files
pks-tgitster
authored andcommitted
contrib/completion: install Bash completion
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4bbb303 commit fe35ce2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ prefix = $(HOME)
618618
bindir = $(prefix)/bin
619619
mandir = $(prefix)/share/man
620620
infodir = $(prefix)/share/info
621+
bash_completion_dir = $(prefix)/share/bash-completion/completions
621622
gitexecdir = libexec/git-core
622623
mergetoolsdir = $(gitexecdir)/mergetools
623624
sharedir = $(prefix)/share
@@ -2325,6 +2326,7 @@ bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
23252326
mandir_SQ = $(subst ','\'',$(mandir))
23262327
mandir_relative_SQ = $(subst ','\'',$(mandir_relative))
23272328
infodir_relative_SQ = $(subst ','\'',$(infodir_relative))
2329+
bash_completion_dir_SQ = $(subst ','\'',$(bash_completion_dir))
23282330
perllibdir_SQ = $(subst ','\'',$(perllibdir))
23292331
localedir_SQ = $(subst ','\'',$(localedir))
23302332
localedir_relative_SQ = $(subst ','\'',$(localedir_relative))
@@ -3569,6 +3571,10 @@ endif
35693571
ifneq (,$X)
35703572
$(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';)
35713573
endif
3574+
ifndef NO_BASH_COMPLETION
3575+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bash_completion_dir_SQ)' && \
3576+
$(INSTALL) -m 644 contrib/completion/git-completion.bash '$(DESTDIR_SQ)$(bash_completion_dir_SQ)/git'
3577+
endif
35723578

35733579
bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
35743580
execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \

contrib/completion/meson.build

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@ foreach script : [
1414
)
1515
endif
1616
endforeach
17+
18+
# We have to discern between the test dependency and the installed file. Our
19+
# tests assume the completion scripts to have the same name as the in-tree
20+
# files, but the installed filenames need to match the executable's basename.
21+
if meson.version().version_compare('>=1.3.0')
22+
fs.copyfile('git-completion.bash', 'git',
23+
install: true,
24+
install_dir: get_option('datadir') / 'bash-completion/completions',
25+
)
26+
else
27+
configure_file(
28+
input: 'git-completion.bash',
29+
output: 'git',
30+
copy: true,
31+
install: true,
32+
install_dir: get_option('datadir') / 'bash-completion/completions',
33+
)
34+
endif

0 commit comments

Comments
 (0)