oh-my-posh: Posh-Git autocomplete broken when importing oh-my-posh3 in $profile

Prerequisites

  • I have read and understand the CONTRIBUTING guide
  • I looked for duplicate issues before submitting this one

Description

With empty profile: empty-profile

With imports in profile: with-profile

posh-git’s contextual autocomplete is not working if I have these three lines in my $profile:

Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt powerlevel10k_lean

Interestingly, if I remove those and import them at the commandline in that same order, everything works just fine.

Environment

  • Oh my Posh version: 3.28.0
  • Theme: powerlevel10k_lean (also tried agnoster, same problem)
  • Operating System: Windows 10
  • Shell: Powershell 7.0.3
  • Terminal: Windows Terminal

Steps to Reproduce

  1. Add these lines to your $profile
Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt powerlevel10k_lean
  1. navigate to directory containing git repo cd C:\path\to\git\repo
  2. make a change to a file (or create a new one) to create an unstaged change scenario. for this, calling this file “dir/to/filetoadd.txt”
  3. type git add (include a space after “add”) and hit {TAB}

Expected behavior: Terminal autocompletes to: git add dir/to/filetoadd.txt

Actual behavior: Terminal autocompletes to something else, like git add .\.git\

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Ok, sorry for wasting your time. I hadn’t seen this page in the docs and as it was not mentioned in this issue I didn’t think that I had missed any steps.

After setting $env:POSH_GIT_ENABLED = $true in my $PROFILE the posh-git completion works as expected.

just to note here the problem that I was having since someone might have it as well.

to use posh-git first you need to install it with Install-Module posh-git remember to run as admin. After that’s done you can add Import-Module posh-git to the top of youre $PROFILE, it will look like this:

Import-Module posh-git

$env:POSH_GIT_ENABLED=$true
oh-my-posh init pwsh | Invoke-Expression

@MendelMonteiro what does $env:POSH_GIT_ENABLED say?

can you check the result of $env:POSH_GIT_ENABLED -eq $true -and (Get-Module -Name "posh-git") and Get-GitStatus? https://github.com/JanDeDobbeleer/oh-my-posh/blob/27d324441be2c35fc905557ece4bdfb1f516273d/src/init/omp.ps1#L48

This seems to have regressed in (at least) versions 5.12.1 and 5.16.2.