Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell passes trimmed command to bash completion. #27

Closed
archilkarchava opened this issue May 9, 2020 · 7 comments
Closed

PowerShell passes trimmed command to bash completion. #27

archilkarchava opened this issue May 9, 2020 · 7 comments

Comments

@archilkarchava
Copy link

Describe the bug
PowerShell passes down command to be completed with trimmed spaces and some completions don't work because of that.

To Reproduce
Steps to reproduce the behavior:

  1. Run pwsh
  2. Enter imported command with some additional arguments and space at the end and press tab
code --disable-extension <tab>
--disable-extension   --disable-extensions
  1. PowerShell outputs completions as if there is no space at the end of the command. The number of spaces at the end doesn't matter, it just passes down trimmed command to bash.

Expected behavior
PowerShell outputting completions for command that has spaces at the end.

code --disable-extension <tab>
adamsome.vscode-theme-gruvbox-minor       ms-azuretools.vscode-docker
akamud.vscode-theme-onedark               ms-dotnettools.csharp
apollographql.vscode-apollo               ms-edgedevtools.vscode-edge-devtools

Desktop (please complete the following information):

  • Windows 2004 (OS Build (19041.208)
  • Ubuntu 20.04 on Windows 10 x86_64 on 4.19.84-microsoft-standard
  • GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)

Additional context
The solution I found that works is to pad the $COMP_LINE until your cursor position $cursorPosition.
So instead of this:

$COMP_LINE = "`"$commandAst`""

do this:

$compLine = "$commandAst".PadRight($cursorPosition)
$COMP_LINE = "`"$compLine`""
@mikebattista
Copy link
Owner

I am trying this with ssh and it seems to work as you'd expect, regardless of how many spaces are appended to the line.

ssh <TAB> returns hosts
ssh -o <TAB> returns options

Do you see the same broken behavior with ssh?

@archilkarchava
Copy link
Author

@mikebattista ssh is working fine. The problem apparently appears when there is more than one option like in the example above --disable-extension and --disable-extensions. I have imported completions from fish shell into bash, so I'm not sure if I can find example among standard bash completions, but the problem definitely exists. You can create custom script and do COMPREPLY=( $(echo ${COMP_LINE}) ) inside completion script and go back to pwsh, it will output command without spaces at the end.

@mikebattista
Copy link
Owner

Can you clarify what "importing completions from fish shell into bash" means? What steps did you take there?

@archilkarchava
Copy link
Author

archilkarchava commented May 10, 2020

@mikebattista I have a script that looks into paths with fish completions and outputs a bash completion for each.
Example of generated completion:

function _code_bash_complete()
{
  local word=${COMP_WORDS[COMP_CWORD]}
  local completions
  if [[ ${COMP_LINE} = 'code' ]]; then
    completions=""
  else
    completions="$(fish -c "complete -C '${COMP_LINE}' | cut -f1 -d\\t" 2> /dev/null)"
  fi
  if [ $? -ne 0 ]; then
    completions=""
  fi
  if [[ ${completions} =~ '~' ]]; then
    completions="$(echo ${completions} | sed 's@~@\\~@g')"
    word="$(echo ${word} | sed 's@~@\\~@g')"
  fi
 COMPREPLY=( $(compgen -W "$completions" -- "$word") )
};
complete -F _code_bash_complete code

But i really don't think the problem is specific to this implementation.

@mikebattista
Copy link
Owner

@archilkarchava I do see PowerShell truncating the $commandAst as you pointed out. I implemented your proposed fix.

Could you confirm the latest changes in master address your scenario?

@archilkarchava
Copy link
Author

@mikebattista yes, it works now!

@mikebattista
Copy link
Owner

Awesome. I just published 0.2.4 with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants