Comments (12)
I'm not sure I understand what you mean, could you elaborate with some specific examples? If you mean e.g. that hitting TAB after e.g. ccache
should not offer read
among possible "wrapped" commands to further complete, then I must say that first, while on first thought it seems to make sense, I'm not 100% certain that a case where that would be useful doesn't exist. And second, I don't know how to sanely filter out builtins from list of commands to complete. (Nor am I at all sure what you mean by "filtering out -b
".)
from bash-completion.
Your interpretation is correct; I mean that for example typing ccache rea
and pressing TAB gives me ccache read
, though there is no binary that can be wrapped like that.
The completion files that currently use _command_offset
are all ones that wrap commands like this, so I think the onus is on finding an example where completing built-ins like this is useful, rather than finding one where it isn't! (If it were found to be useful in some cases, an option could be added to include built-ins).
My assumption (which perhaps is mistaken) is that the builtins were included in the list of commands to complete by passing the -b
option to compgen
, so if _command_offset
were to filter out this option, then it would not complete built-ins. _command_offset
already fiddles with the options, so this (it seemed to me) should not be hard to achieve.
The motivation for this was the following exchange:
brummer10/nosuspend@e5eb83d#commitcomment-19712085
where someone decided to write a bash completion without using _command_offset
because of this bug. That seemed to me unfortunate.
from bash-completion.
I don't see where _command_offset
would be currently passing -b
to compgen
.
from bash-completion.
It gets the current options from complete -p
, stores them in cspec
, and later passes them on. It already treats -F
specially.
from bash-completion.
Sure, but are there any commands that actually have -b
in their completion options so that complete -p
on them would end up returning it? ccache
or sudo
don't, haven't checked others.
$ complete -p ccache
complete -F _ccache ccache
$ complete -p sudo
complete -F _sudo sudo
from bash-completion.
OK, so why is it completing built-ins then? Is this just the default, as when starting with an empty line?
from bash-completion.
The code branch where -F
is examined is already completing on the secondary command, too late to do anything there. The secondary command names to offer as completions are retrieved in an earlier code branch, using compgen -d -c
. And I think -c
just includes all commands, including builtins, without any further options we could use to tell it to omit builtins.
from bash-completion.
The method used by the code I link to is:
executables=$({ compgen -c; compgen -abkA function; } | sort | uniq -u)
i.e. it finds all the commands which are not executables, and then only takes the executables, which appear only once in the list (i.e. they are not builtins, functions etc.).
from bash-completion.
@scop, you've replied to my two bug reports, but you've not responded further to my updated PR#86. I wondered whether this was an oversight? Feel free to delete this comment once you've read it!
from bash-completion.
@brummer10 comments:
A much faster version to create a list of (only) the available executables will be
executables=$(echo -n "$PATH" | xargs -d: -I{} -r -- find -L {} -maxdepth 1 -mindepth 1 -type f -executable -printf '%P\n' 2>/dev/null | sort -u)
He quotes timings at the above-linked bug report.
from bash-completion.
No oversights, I'm just very very low on time to spend on bash-completion these days.
Just a first impression on the latter implementation of grabbing the executables; it uses several arguments to find
which aren't portable (at least -maxdepth
, -mindepth
, -executable
, -printf
don't exist in POSIX find
), and I'm not sure we want to depend on xargs
in the first place, or if its usage here is portable. Search for POSIX in CONTRIBUTING.md for more info.
from bash-completion.
No worries, I just wondered because you'd replied to my issues, but not to the PR.
Since the faster version is non-portable, I refer you to the previous, portable version.
from bash-completion.
Related Issues (20)
- Hard to find where to report bugs HOT 2
- Latest CHANGELOG.md starts at `## 2.11...` and earlier HOT 2
- Redirection moved to the front wrongly affects completions HOT 2
- Gentoo update to 2.14 fails due to QA notice HOT 3
- tar file completion not working as expected under various option combinations HOT 2
- Enable .java Filename Completion for java Command HOT 2
- GCC tests fail on non-x86 platforms HOT 1
- CDPATH autocomplete is not working HOT 5
- 000_bash_completion_compat.bash sourced last in some locales HOT 1
- bash: _comp_initialize: command not found HOT 2
- [Regression] make autocompletion skips install HOT 3
- Native bash-completion 2 loader using complete -D HOT 5
- Completing a relative path with a space and softlinks inside, turns it absolute (which breaks creating relative softlinks) HOT 1
- Completions for 'alternatives' command are broken HOT 1
- xspec is ignored when Bash option `force_fignore` is unset HOT 5
- [2.14.0] rsync path completion fails if a folder name have a space
- Completions are not loaded in Linux+Homebrew HOT 2
- Feature request: generalized implementation of `_comp_command_offset` HOT 12
- File ~/.bash_completion no longer working after update to 2.14. HOT 2
- Hi, i need help regarding bash-completion. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bash-completion.