Open omajid opened 7 years ago
cc @wli3
I'm guessing that we should just set DOTNET_SKIP_FIRST_TIME_EXPERIENCE
in the local function that we register with complete?
Does dotnet complete
send telemetry events? My impression was that we have show the users the first-run message if it does.
That's a good point, @omajid. We could set DOTNET_CLI_TELEMETRY_OPTOUT
as well?
Sure. Any other switches we should enable?
Also, I don't know why I am not seeing the first run message on complete. Can anyone else confirm/reproduce? FWIW, I copied the completion file to /usr/share/bash-completion/comlletions/dotnet
and rely on bash automatically picking up and using the completions.
@omajid Is complete working for you when the first run message has not yet been displayed for that CLI installation?
@jonsequitur I am using rm -rf ~/.dotnet/ ~/.nuget/ ~/.local/share/NuGet
to simulate "fresh install on a fresh machine". Is there something else I should do to simulate such an environment?
That's good enough for preview2. For preview3, delete the sentinel file under dotnet/SDK/NUGetFallbackFolder, where dotnet is where you install the SDK.
I am confused here. Is the problem here that auto-complete is sending telemetry or that a command that was constructed with dotnet complete, when invoked, does not show the telemetry message?
If the first run experience has not yet been triggered, then dotnet complete
will trigger it (last I checked). If you run dotnet complete
directly you can see the first run text followed by the completion results. But if you triggered tab completion, so that the shell completion script is the caller into dotnet complete
, then what I've observed is that the shell doesn't know how to parse the result containing the first run output, and you won't see the custom completion results. You may see it fall back to file system completion or see blank output. I think this varies by shell.
I know this is old, but I've come up with a solution that solves all use cases with just one little downside.
As you said, there's the option of calling the dotnet complete
command with DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
, but that has the downside of not showing the telemetry message but collecting completion data. It also didn't have an effect when $HOME/.dotnet
is empty.
The next thing was to set DOTNET_CLI_TELEMETRY_OPTOUT=1
to avoid capturing telemetry data from completion commands, which I can see setting for all completion triggers without a way to unset it might not be a good idea.
So we could set it for as long as the first time experience message hasn't been shown, but I can't figure out a way to do it programatically.
So the option I've come up with is to parse the dotnet complete
message and separate the first time experience message from the completion entries using sed
, though it has the downside of relying on the separator line never changing (86-hyphens line). The code could use a lower magic number, the only requirement is that the last separator line has more hyphens than the rest of the separators. The code also uses two sed
calls but these are relatively inexpensive.
Here's the solution in zsh, but it can be easily ported to bash:
_dotnet() {
local dotnet_msg="$(dotnet complete "$words")"
local separator=$(printf '-%.0s' {1..86})
# Print the message until completion entries begin, where an 86-character
# hyphen separator is printed.
if [[ "$dotnet_msg" = *$separator* ]]; then
sed "/$separator/q" <<< "$dotnet_msg"
fi
# Afterwards offer the completion entries, which come after the separator.
local completions=("$(sed -e "1,/$separator/d" <<< "$dotnet_msg")")
if [[ -n "$completions" ]]; then
compadd -- "${(@f)completions}"
fi
}
compdef _dotnet dotnet
Steps to reproduce
Using bash, load the shell completions and then try and use the before invoking a
dotnet
command explicitly.Notice that I didn't get a welcome message. If I run the exact same command without using the completion, I do see the telemetry message:
Environment data
This is a custom build of the CLI.
dotnet --info
output: