1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# Copyright (C) 2015, 2016 Mattias Andrée <maandree@member.fsf.org>
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
#=== These rules are used for shell tab-completion using auto-auto-complete. ===#
# Enables the rules:
# shell Build tab-completion for all supported shells
# bash Build GNU Bash tab-completion
# fish Build fish tab-completion
# zhs Build Z shell tab-completion
# install-shell Install tab-completion for all supported shells
# install-bash Install GNU Bash tab-completion
# install-fish Install fish tab-completion
# install-zsh Install Z shell tab-completion
#
# This file is ignored unless
# _AUTO_COMPLETE is defined.
#
# _AUTO_COMPLETE shall list all commands that
# have an auto-auto-complete. These should be
# named src/$(COMMAND).auto-completion, where
# $(COMMAND) is the command with the script.
# If all auto-auto-complete scripts translations
# named src/$(COMMAND).$(LOCALE).auto-completion,
# SHELL_LOCALE can be set to install exactly
# on translation in place of the non-translated
# versions.
#
# Although not used by this file, you should
# define _SHELL_LOCALES that lists all available
# translations. (it is used by dist.mk.)
#
# You should also define _WITH_SHELL if you
# want shell tab-completion unless the user
# specifies otherwise. If you want it for
# just some shells, define _WITH_$(SHELL)
# for those shells instead of _WITH_SHELL.
ifdef _AUTO_COMPLETE
# HELP VARIABLES:
# Include all that were not explicitly excluded?
ifdef _WITH_SHELL
_WITH_BASH = 1
_WITH_FISH = 1
_WITH_ZSH = 1
endif
# Include for GNU Bash?
ifdef WITH_BASH
__WITH_BASH = 1
endif
ifndef WITH_BASH
ifndef WITHOUT_BASH
ifdef _WITH_BASH
__WITH_BASH = 1
endif
endif
endif
# Include for fish?
ifdef WITH_FISH
__WITH_FISH = 1
endif
ifndef WITH_FISH
ifndef WITHOUT_FISH
ifdef _WITH_FISH
__WITH_FISH = 1
endif
endif
endif
# Include for Z Shell?
ifdef WITH_ZSH
__WITH_ZSH = 1
endif
ifndef WITH_ZSH
ifndef WITHOUT_ZSH
ifdef _WITH_ZSH
__WITH_ZSH = 1
endif
endif
endif
# WHEN TO BUILD, INSTALL, AND UNINSTALL:
all: shell
everything: shell
install: install-shell
install-doc: install-info install-dvi install-pdf install-ps install-html
uninstall: uninstall-shell
shell:
install-shell:
ifdef __WITH_BASH
shell: bash
install-shell: install-bash
endif
ifdef __WITH_FISH
shell: fish
install-shell: install-fish
endif
ifdef __WITH_ZSH
shell: zsh
install-shell: install-zsh
endif
# HELP VARIABLES:
# Affixes on the source files.
ifdef SHELL_LOCALE
__AAC_L = .$(SHELL_LOCALE)
endif
__AAC = $(__AAC_L).auto-completion
# Customised command name.
ifdef COMMAND
ifeq ($(shell $(PRINTF) '%s\n' $(COMMAND) | $(WC) -l),1)
ifeq ($(shell $(PRINTF) '%s\n' $(_AUTO_COMPLETE) | $(WC) -l),1)
__SHELL_COMMAND = "command=$(COMMAND)"
endif
endif
endif
# BUILD RULES:
# Built tab-completion scripts for GNU Bash.
.PHONY: bash
bash: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).bash-completion)
# Built tab-completion scripts for fish.
.PHONY: fish
fish: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).fish-completion)
# Built tab-completion scripts for Z shell.
.PHONY: zsh
zsh: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).zsh-completion)
# Built a tab-completion script for GNU Bash.
bin/%.bash-completion: $(v)src/%$(__AAC)
@$(PRINTF_INFO) '\e[00;01;31mAUTO-AUTO-COMPLETE\e[34m %s\e[00m$A\n' "$@"
@$(MKDIR) -p bin
$(Q)$(AUTO_AUTO_COMPLETE) bash -o $@ -s $< $(__SHELL_COMMAND) #$Z
@$(ECHO_EMPTY)
# Built a tab-completion script for fish.
bin/%.fish-completion: $(v)src/%$(__AAC)
@$(PRINTF_INFO) '\e[00;01;31mAUTO-AUTO-COMPLETE\e[34m %s\e[00m$A\n' "$@"
@$(MKDIR) -p bin
$(Q)$(AUTO_AUTO_COMPLETE) fish -o $@ -s $< $(__SHELL_COMMAND) #$Z
@$(ECHO_EMPTY)
# Built a tab-completion script for Z shell.
bin/%.zsh-completion: $(v)src/%$(__AAC)
@$(PRINTF_INFO) '\e[00;01;31mAUTO-AUTO-COMPLETE\e[34m %s\e[00m$A\n' "$@"
@$(MKDIR) -p bin
$(Q)$(AUTO_AUTO_COMPLETE) zsh -o $@ -s $< $(__SHELL_COMMAND) #$Z
@$(ECHO_EMPTY)
# INSTALL RULES:
# Install tab-completion scripts for GNU Bash.
.PHONY: install-bash
install-bash: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).bash-completion)
@$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@"
$(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DATADIR)/bash-completion/completions"
ifndef __SHELL_COMMAND
$(Q)$(foreach F,$(_AUTO_COMPLETE),$(INSTALL_DATA) bin/$(F).bash-completion -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(F)" &&) $(TRUE)
endif
ifdef __SHELL_COMMAND
$(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(COMMAND)"
endif
@$(ECHO_EMPTY)
# Install tab-completion scripts for fish.
.PHONY: install-fish
install-fish: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).fish-completion)
@$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@"
$(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DATADIR)/fish/completions"
ifndef __SHELL_COMMAND
$(Q)$(foreach F,$(_AUTO_COMPLETE),$(INSTALL_DATA) bin/$(F).fish-completion -- "$(DESTDIR)$(DATADIR)/fish/completions/$(F).fish" &&) $(TRUE)
endif
ifdef __SHELL_COMMAND
$(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DATADIR)/fish/completions/$(COMMAND).fish"
endif
@$(ECHO_EMPTY)
# Install tab-completion scripts for Z shell.
.PHONY: install-zsh
install-zsh: $(foreach F,$(_AUTO_COMPLETE),bin/$(F).zsh-completion)
@$(PRINTF_INFO) '\e[00;01;31mINSTALL\e[34m %s\e[00m\n' "$@"
$(Q)$(INSTALL_DIR) -- "$(DESTDIR)$(DATADIR)/zsh/site-functions"
ifndef __SHELL_COMMAND
$(Q)$(foreach F,$(_AUTO_COMPLETE),$(INSTALL_DATA) bin/$(F).zsh-completion -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(F)" &&) $(TRUE)
endif
ifdef __SHELL_COMMAND
$(Q)$(INSTALL_DATA) $^ -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(COMMAND)"
endif
@$(ECHO_EMPTY)
# UNINSTALL RULES:
# Uninstall tab-completion.
.PHONY: uninstall-shell
uninstall-shell:
ifndef __SHELL_COMMAND
-$(Q)$(RM) -- $(foreach F,$(_AUTO_COMPLETE),"$(DESTDIR)$(DATADIR)/bash-completion/completions/$(F)")
-$(Q)$(RM) -- $(foreach F,$(_AUTO_COMPLETE),"$(DESTDIR)$(DATADIR)/fish/completions/$(F).fish")
-$(Q)$(RM) -- $(foreach F,$(_AUTO_COMPLETE),"$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(F)")
endif
ifdef __SHELL_COMMAND
-$(Q)$(RM) -- "$(DESTDIR)$(DATADIR)/bash-completion/completions/$(COMMAND)"
-$(Q)$(RM) -- "$(DESTDIR)$(DATADIR)/fish/completions/$(COMMAND).fish"
-$(Q)$(RM) -- "$(DESTDIR)$(DATADIR)/zsh/site-functions/_$(COMMAND)"
endif
endif
|