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

Single word is not completed #3050

Closed
1 task done
totkeks opened this issue Nov 7, 2022 · 3 comments
Closed
1 task done

Single word is not completed #3050

totkeks opened this issue Nov 7, 2022 · 3 comments
Assignees
Labels
🐛 bug Something isn't working

Comments

@totkeks
Copy link

totkeks commented Nov 7, 2022

Code of Conduct

  • I agree to follow this project's Code of Conduct

What happened?

When I use the Powershell completion, then it fails to complete, when I want to complete the first word, e.g. con<tab> or com<tab> - should result in config or completion respectively. Instead neither happens.

I also found the issue in the completion code while writing this issue:

$Values = $Out | ForEach-Object {
		#Split the output in name and description
		$Name, $Description = $_.Split("`t", 2)
		__oh-my-posh_debug "Name: $Name Description: $Description"

		# Look for the longest completion so that we can format things nicely
		if ($Longest -lt $Name.Length) {
			$Longest = $Name.Length
		}

		# Set the description to a one space string if there is none set.
		# This is needed because the CompletionResult does not accept an empty string as argument
		if (-Not $Description) {
			$Description = " "
		}
		@{Name = "$Name"; Description = "$Description" }
	}

When there is only one completion result, which is oddly the case for oh-my-posh __complete con but not for oh-my-posh __complete config ex, then the above code makes $Values a hashtable and not an array, which results in a hidden error down the line, because a hashtable has no Length property.

if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
		__oh-my-posh_debug "ShellCompDirectiveNoFileComp is called";

		if ($Values.Length -eq 0) {
			# Just print an empty string here so the
			# shell does not start to complete paths.
			# We cannot use CompletionResult here because
			# it does not accept an empty string as argument.
			""
			return
		}
	}

My simple workaround has been forcing $Values to become an array by doing this [Array]$Values in the first code fragment.

Theme

Not relevant

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Not relevant
@totkeks totkeks added the 🐛 bug Something isn't working label Nov 7, 2022
@totkeks
Copy link
Author

totkeks commented Nov 7, 2022

After a little more digging I noticed that this code is not from omp, but comes from @spf13/cobra. I will open an issue there and link this one.

@totkeks totkeks closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2022
@JanDeDobbeleer
Copy link
Owner

@totkeks yes indeed, this can be closed here as we can't do anything on our end.

Copy link

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues.
If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants