question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ZSH completion breaks path completion

See original GitHub issue

https://github.com/dotnet/cli/blob/7af1d28dd72fb933966e6201414dc8df6753fcd3/scripts/register-completions.zsh#L10

If I’m not missing something, this indeed helps to autocomplete commands for dotnet, but equally it will break normal path completion.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
JohnnyWombwellcommented, Jul 30, 2021

Happy to help 😃

This is probably overkill but the ‘tabbing options over file path’ thing was irritating me so this improves the experience imo:

_dotnet_zsh_complete()
{
  local completions=("$(dotnet complete "$words")")
  local completions_array=( "${(ps:\n:)completions}" )
  local narg pref
  read -nc narg
  read -Ac pref

  # To mimic the convention of 'tabbing' empty space
  # preferring file completions over command options (see ls etc),
  # this will ignore completions if the cursor is in empty space
  # and *all* completions are options (i.e. there are no command
  # completions).
  # Due to the empty result, the shell should then fallback to
  # file completions.
  if [[ ! "${pref[narg]}" = *[^[:space:]]* ]]; then
    local all_completions_are_options=true
    for completion in "${completions_array[@]}"
    do
      if [[ ${completion:0:1} != "-" ]] then
        all_completions_are_options=false
        break
      fi
    done
    if [[ "$all_completions_are_options" = true ]] then
      reply=()
      return
    fi
  fi

  reply=( $completions_array )
}
1reaction
JohnnyWombwellcommented, Jul 30, 2021

You can tell zsh to fallback to file path completion (when dotnet complete returns no suggestions) by changing

compctl -K _dotnet_zsh_complete dotnet

to

compctl -K _dotnet_zsh_complete + -f dotnet

This gets auto completion working pretty close to how you’d expect. There is a slight niggle in that when tabbing after entering a command where you’d often enter a path, e.g. dotnet add reference, showing options takes precedent over the path. It’s easily worked around by entering the first char of the path (or ./ say).

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent zsh path completion magic until I press TAB?
Zsh doesn't start doing any kind of completion magic until you press Tab in a “normal” configuration. It can be done but it...
Read more >
Zsh tab-completion not working
Hello, after switching from Bash to Zsh on macOS Catalina, Tab completion stopped working for me. Apparently it is working in directories where ......
Read more >
zsh completion for all executables in path - linux
I have written a script which itself takes as an argument any arbitrary executable in my $PATH. Is there a way to create...
Read more >
A Guide to the Zsh Completion with Examples
How work the Zsh completion system and how to configure it according to your needs, without any framework or bloated library.
Read more >
Absolutely bizarre tab completion glitch : r/zsh
It's a tab completion issue specifically around underscores, and the fix is simply to add the following to .zshrc:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found