Closed pjcdawkins closed 9 years ago
I've noticed the source
method in the readme doesn't work on a few machines, so it's not something you're doing. With a little bit of fiddling, it looks like in some environments (different versions of bash) using source /dev/stdin
causes the code to execute in a sub-shell. A comment on SuperUser mentions this:
Using
|
, however, is not going to work (at least not exactly), because both sides of the pipe are separate subprocesses, so sourced commands would not affect the current shell.
Using process substitution works in environments where the piping method doesn't work, however the reverse also seems to be true - this doesn't work where the piping method works (BASH 3.2 on OSX for me):
source <(platform _completion -g -p platform)
That makes sense, thanks. I wonder if I have to find a test for that, or if it would be appropriate just to run both, on any system (since neither appear to cause errors)...
HOOK=$(platform _completion -g -p platform)
echo "$HOOK" | source /dev/stdin
source <(echo "$HOOK")
FYI the above works on Fedora, OS X, and Ubuntu.
but those two commands fail on FreeBSD, which only seems to accept
eval $(platform _completion -g -p platform --shell-type=bash)
It seems bash under Git Bash on Windows 7 also only accepts eval
.
I'm going to provide users with a script for this - so I can always use eval
as above.
Thanks, @pjcdawkins. It's been useful to look into this. I've updated the readme to be clearer about how completion can be registered in different environments.
Thanks. It actually doesn't appear to be dependent on the Bash version (at least, not as reported by bash --version) - the FreeBSD I was testing does have Bash 4.x.
I'm trying to get autocompletion working, via an install script, on an Ubuntu 14.04 VirtualBox VM for our project platformsh/cli.
On this machine, this command works:
However, I'd prefer to use the following command as it would work for users across platforms / shell types, and it seems less evil. It works nicely on OS X with either bash or zsh. But on the Ubuntu VM, while it doesn't emit any errors, it doesn't enable auto-completion:
The
source /dev/stdin
bit appears to work fine:Do you know what I might be doing wrong?