Open dotsdl opened 5 years ago
+1
Really this part of accepting only one file is not at all intuitive since the accepted type of the BASH_COMPLETIONS variable is a list or a tuple, something like the code below would only use the first file:
from pathlib import Path
$BASH_COMPLETIONS = [
path.as_posix()
for path in Path('/usr/share/bash-completion/completions').glob('*')
]
Maybe it's the behavior of the _get_bash_completions_source() function that handles the $BASH_COMPLETIONS variable with the following condition:
# paths is $BASH_COMPLETIONS
for path in map(pathlib.Path, paths):
if path.is_file():
return f'source "{path.as_posix()}"'
I would like to know if there is any other way to put multiple files or put a directory to complete.
To whom it may concern, this implementation worked for me:
hi @taconi ! Thank you for the example! Do you know that you can make your xontrib for this using xontrib-template in 10 minutes? Wrap your code into the xontrib and share with xonsh users. Follow the xontrib promo guide. The example of the list of xontribs is xontrib Github topic.
Hi, @anki-code ! Thanks for the suggestion, I didn't know about this possibility, I'm new to the xonsh world. I created the xontrib bash-completions-dirs, in pypi there is an explanation of how to install and how to use.
Maybe this issue can be closed with this.
@taconi it's awesome! Many thanks! Please add your xontrib to awesome-xontribs!
@taconi it's awesome! Many thanks! Please add your xontrib to awesome-xontribs!
PR was created.
Thanks @taconi!
I'm new to the xonsh world.
It will be cool to start here - https://github.com/anki-code/xonsh-cheatsheet/blob/main/README.md
Thanks @taconi! I've been trying to get xonsh completions working with macports bash and had no luck until using this xontrib!
One additional constraint I found with macports is to set BASH_COMPLETION_USER_DIR
to include BASH_COMPLETION_COMPAT_DIR
, and to put all completions in that directory - perhaps this is specific to macports but I suspect this may be needed for homebrew as well.
Macports installs its bash_completion script at /opt/local/share/bash-completion/bash_completion
.
This script contains:
compat_dir=${BASH_COMPLETION_COMPAT_DIR:-/opt/local/etc/bash_completion.d}
Completions in xonsh work if I either
/opt/local/etc/bash_completion.d/
and add/link completions files to it, or BASH_COMPLETION_COMPAT_DIR
in .bashrc
to point my current bash completions scripts dir. In either case, the directory with completions files must be set in .bashrc to BASH_COMPLETION_COMPAT_DIR
and must also be included in xonsh $BASH_COMPLETIONS_DIRS
I also adhere to the script naming convention you mention on pypi
The completions file name must be the same as the command to be used in autocomplete
So with the following configs, completions are working in both bash and xonsh using xcontrib bash_completions_dirs
and macports-installed bash:
~/.bashrc
...
export BASH_COMPLETION_COMPAT_DIR=/Users/yolabingo/.bash_completions
source /opt/local/share/bash-completion/bash_completion
source /Users/yolabingo/.bash_completions/git
source /Users/yolabingo/.bash_completions/kubectl
source /Users/yolabingo/.bash_completions/poetry
source /Users/yolabingo/.bash_completions/docker
...
~/.xonshrc
...
# macports' bash_completion file:
$BASH_COMPLETIONS = ['/opt/local/share/bash-completion/bash_completion']
$BASH_COMPLETIONS_DIRS = ['/Users/yolabingo/.bash_completions']
xontrib load bash_completions_dirs ...
Reference #648
It is not clear what the limitations are for defining
bash_completion
s. In particular the$BASH_COMPLETION_USER_DIR
environment variable does not appear to be documented yet. Also,bash
has idiosyncratic behavior in that it only allows a single directory for defining these completions.For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 comment