Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,22 @@ A. [ Disclaimer: Here, how to make the completion code visible to
Install it in one of the directories pointed to by bash-completion's
`pkgconfig` file variables. There are two alternatives:

- The recommended directory is `completionsdir`, which you can get with
- The recommended directory is `<completionsdir>`, which you can get with
`pkg-config --variable=completionsdir bash-completion`. From this
directory, completions are automatically loaded on demand based on invoked
commands' names, so be sure to name your completion file accordingly, and
to include (for example) symbolic links in case the file provides
completions for more than one command. The completion filename for
command `foo` in this directory should be either `foo`, or `foo.bash`.
(Underscore prefixed `_foo` works too, but is reserved for
bash-completion internal use as a deprecation/fallback marker.)
- The other directory which is only present for backwards compatibility,
its usage is no longer recommended, is `compatdir` (get it with
`pkg-config --variable=compatdir bash-completion`). From this
completions for more than one command. The completion filename for command
`foo` in this directory should be `foo.bash`. Unsuffixed `foo` also
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Remove double space after period, there are some more

Suggested change
`foo` in this directory should be `foo.bash`. Unsuffixed `foo` also
`foo` in this directory should be `foo.bash`. Unsuffixed `foo` also

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is there a specific preference or a rule for double-space sentence separators? The double-space style is the tradition in typewriters, while a single space is more typical in modern text files.

The problem is that I use GNU Emacs, and GNU Emacs recognizes "a period plus double spaces" as the sentence terminator, while "a period plus a space" is treated as a period after an abbreviation (like Mr., Inc., Rev., etc), following the convention in typewriters. If the sentence-end double spaces are converted to single spaces, it affects the behavior of the auto line breaking at column 79. I don't want to manually convert all single spaces at the end of sentences to double spaces and convert back double spaces to single spaces every time I edit a paragraph and adjust line breaking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I look at the codebase, both styles are mixed. @scop also seems to use the double-space style (though I'm not sure about its frequency compared to that of the single-space style). For example, the message in the deprecated files # Use of this file is deprecated. Upstream completion is available in (with double spaces) was introduced by @scop in e.g. 861be75.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have really have a specific preference, I'm just used to the single space. It's fine to leave it likes this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I've noticed this issue too, though I have never raised it in a discussion. It's a subtle issue about the conflict between the modern style and the text editor behavior, so I haven't tried to normalize the style either way. If both of you are fine with it, let me just leave it as is until an actual issue occurs.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a long time Emacs user as well, and have had the habit of using two for ages, but I'm not paying that much attention to it these days, as not doing so does not interfere with anything I routinely do. So either style is fine with me, but I'd prefer consistency and even better if there's a linter or something that whines about the "wrong" one. Flagging double is quite a bit easier to implement if one wants to write one, and some are in existence already, for example https://github.com/Automattic/harper advises against using "French spaces" (i.e. the double ones).

works, but it is deprecated in >= 2.18.
- Helper scripts used by completions may be placed in the directory
`<helpersdir>`, which can be retrieved with `pkg-config
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this particular line, but the first commit message refers to helpers-dist -> should change that to helpers-core.

--variable=helpersdir bash-completion`. The completion files in
`<completionsdir>` can reference the helper script `<helpersdir>/<helper>`
as `${BASH_SOURCE[0]%/*}/../helpers/<helper>`.
- The other directory, which is only present for backwards compatibility and
is not recommended to use, is `<compatdir>` (get it with
`pkg-config --variable=compatdir bash-completion`). From this
directory, files are loaded eagerly when `bash_completion` is loaded.

For packages using GNU autotools the installation can be handled
Expand Down
14 changes: 6 additions & 8 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -3506,14 +3506,12 @@ _comp_load()
shift
local -a source_args=("$@")

local i prefix
for prefix in "" _; do # Regular from all dirs first, then fallbacks
for i in "${!dirs[@]}"; do
dir=${dirs[i]}/completions
[[ -d $dir ]] || continue
for compfile in "$prefix$cmdname" "$prefix$cmdname.bash"; do
_comp_load__visit_file "$dir/$compfile" && return 0
done
local i
for i in "${!dirs[@]}"; do
dir=${dirs[i]}/completions
[[ -d $dir ]] || continue
for compfile in "$cmdname.bash" "$cmdname"; do
_comp_load__visit_file "$dir/$compfile" && return 0
done
done
_comp_load__visit_file "$_comp__base_directory/completions-core/$cmdname.bash" && return 0
Expand Down
1 change: 0 additions & 1 deletion completions-core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ cross_platform = 2to3.bash \
inject.bash \
inotifywait.bash \
installpkg.bash \
interdiff.bash \
invoke-rc.d.bash \
ip.bash \
ipcalc.bash \
Expand Down
1 change: 1 addition & 0 deletions completions-fallback/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cross_platform = adb.bash \
hexdump.bash \
hwclock.bash \
insmod.bash \
interdiff.bash \
ionice.bash \
jj.bash \
jungle.bash \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# interdiff(1) completion -*- shell-script -*-

# Use of this file is deprecated. Upstream completion is available in
# patchutil >= 0.4.3, use that instead.

_comp_cmd_interdiff()
{
local cur prev words cword was_split comp_args
Expand Down
14 changes: 6 additions & 8 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# We include all the files in the tarball

scriptfiles =

bashcompdir = $(datadir)/$(PACKAGE)/completions
bashcomp_DATA =
bashcomp_DATA = README.md $(scriptfiles)

EXTRA_DIST = $(bashcomp_DATA)

symlinks: $(DATA)
.PHONY: symlinks
Expand All @@ -16,14 +20,8 @@ install-data-hook: symlinks

check-local:
REPLY=0; \
for file in $(bashcomp_DATA); do \
for file in $(scriptfiles); do \
$${bashcomp_bash:-$${BASH:-bash}} \
-O extglob -n $(srcdir)/$$file || REPLY=$$?; \
done; \
exit $$REPLY

install-data-local:
$(MKDIR_P) $(DESTDIR)$(datadir)/bash-completion/$(subdir)

uninstall-local:
-rmdir $(DESTDIR)$(datadir)/bash-completion/$(subdir)
24 changes: 24 additions & 0 deletions completions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Third-party completions directory - bash-completion

This directory `completions` is the place to put **third-party completion
files** that are loaded by
Comment on lines +3 to +4
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe clarify here (and in helpers) what we mean by "third party". There's also a mention of "external" in the note below. How about something like this to unify the terms?

Suggested change
This directory `completions` is the place to put **third-party completion
files** that are loaded by
This directory, `completions`, is the place to put "external" completion files,
i.e. ones not shipped by the bash-completion project itself.
They are loaded by

[bash-completion](https://github.com/scop/bash-completion) on demand.

> [!NOTE]
>
> The core `bash-completion` framework (<= 2.17) has provided also *completion
> files bundled with the bash-completion framework itself* in this directory,
> but we separated those files into `completions-core` and
> `completions-fallback`. However, external completion provider should
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> `completions-fallback`. However, external completion provider should
> `completions-fallback`. However, external completion providers should

> continue to install their completion files in `completions`. The new
> directories `completions-core` and `completions-fallback` are internal
> directories intended to be used by the core `bash-completion`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> directories intended to be used by the core `bash-completion`.
> directories intended to be used by the core bash-completion only.

The programmable completion for the command `<cmd>` is supposed to be provided
as the file `completions/<cmd>.bash`. The implementation examples are found in
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
as the file `completions/<cmd>.bash`. The implementation examples are found in
in the file `completions/<cmd>.bash`. The implementation examples are found in

`completions-core`, which uses the latest bash-completion API (v3). If you
want to make the completion file to work also with an older version of
`bash-completion`, you need to use the previous API of v2, which is contiuned
to be supported. For examples with API v2, please reference the completion
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to be supported. For examples with API v2, please reference the completion
to be supported for now. For examples with API v2, please reference the completion

files in `completions` of
[bash-completion-2.11](https://github.com/scop/bash-completion/releases/tag/2.11).
8 changes: 1 addition & 7 deletions helpers/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
helpersdir = $(datadir)/$(PACKAGE)/helpers
helpers_DATA =
helpers_DATA = README.md

EXTRA_DIST = $(helpers_DATA)

install-data-local:
$(MKDIR_P) $(DESTDIR)$(datadir)/bash-completion/$(subdir)

uninstall-local:
-rmdir $(DESTDIR)$(datadir)/bash-completion/$(subdir)
17 changes: 17 additions & 0 deletions helpers/README.md
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting similar changes here as in completions/README.md above.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Third-party helpers directory - bash-completion

This directory `helpers` is the place to put **third-party helper scripts**
that are used by third-party completion files in the `completions` directory,
written for [bash-completion](https://github.com/scop/bash-completion).

> [!NOTE]
>
> The core `bash-completion` framework (<= 2.17) has provided also *helper
> scripts included in the bash-completion framework itself* in this directory,
> but we separated those files into `helpers-core`. However, external
> completion provider should continue to install their helper scripts in
> `helpers`. The new directory `helpers-core` is an internal directory
> intended to be used by the core `bash-completion`.

The helper script may be referenced by a completion script in `completions`
with `${BASH_COMPLETION[0]%/*}/../helpers/<helper>`.