mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 12:32:22 -08:00
fix(git): do not convert path when using native_fallback in WSL
This commit is contained in:
parent
d38025177d
commit
0cfe9a7423
|
@ -92,6 +92,7 @@ type scm struct {
|
||||||
rootDir string
|
rootDir string
|
||||||
realDir string // real directory (can be different from current path when in worktrees)
|
realDir string // real directory (can be different from current path when in worktrees)
|
||||||
command string
|
command string
|
||||||
|
nativeFallback bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -111,13 +112,16 @@ func (s *scm) Init(props properties.Properties, env platform.Environment) {
|
||||||
func (s *scm) truncateBranch(branch string) string {
|
func (s *scm) truncateBranch(branch string) string {
|
||||||
fullBranchPath := s.props.GetBool(FullBranchPath, true)
|
fullBranchPath := s.props.GetBool(FullBranchPath, true)
|
||||||
maxLength := s.props.GetInt(BranchMaxLength, 0)
|
maxLength := s.props.GetInt(BranchMaxLength, 0)
|
||||||
|
|
||||||
if !fullBranchPath && strings.Contains(branch, "/") {
|
if !fullBranchPath && strings.Contains(branch, "/") {
|
||||||
index := strings.LastIndex(branch, "/")
|
index := strings.LastIndex(branch, "/")
|
||||||
branch = branch[index+1:]
|
branch = branch[index+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
if maxLength == 0 || len(branch) <= maxLength {
|
if maxLength == 0 || len(branch) <= maxLength {
|
||||||
return branch
|
return branch
|
||||||
}
|
}
|
||||||
|
|
||||||
symbol := s.props.GetString(TruncateSymbol, "")
|
symbol := s.props.GetString(TruncateSymbol, "")
|
||||||
return branch[0:maxLength] + symbol
|
return branch[0:maxLength] + symbol
|
||||||
}
|
}
|
||||||
|
@ -135,9 +139,11 @@ func (s *scm) FileContents(folder, file string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scm) convertToWindowsPath(path string) string {
|
func (s *scm) convertToWindowsPath(path string) string {
|
||||||
if s.env.GOOS() == platform.WINDOWS || s.IsWslSharedPath {
|
// only convert when in Windows, or when in a WSL shared folder and not using the native fallback
|
||||||
|
if s.env.GOOS() == platform.WINDOWS || (s.IsWslSharedPath && !s.nativeFallback) {
|
||||||
return s.env.ConvertToWindowsPath(path)
|
return s.env.ConvertToWindowsPath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,6 +151,7 @@ func (s *scm) convertToLinuxPath(path string) string {
|
||||||
if !s.IsWslSharedPath {
|
if !s.IsWslSharedPath {
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.env.ConvertToLinuxPath(path)
|
return s.env.ConvertToLinuxPath(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,24 +159,30 @@ func (s *scm) hasCommand(command string) bool {
|
||||||
if len(s.command) > 0 {
|
if len(s.command) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// when in a WSL shared folder, we must use command.exe and convert paths accordingly
|
// when in a WSL shared folder, we must use command.exe and convert paths accordingly
|
||||||
// for worktrees, stashes, and path to work
|
// for worktrees, stashes, and path to work, except when native_fallback is set
|
||||||
s.IsWslSharedPath = s.env.InWSLSharedDrive()
|
s.IsWslSharedPath = s.env.InWSLSharedDrive()
|
||||||
if s.env.GOOS() == platform.WINDOWS || s.IsWslSharedPath {
|
if s.env.GOOS() == platform.WINDOWS || s.IsWslSharedPath {
|
||||||
command += ".exe"
|
command += ".exe"
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.env.HasCommand(command) {
|
if s.env.HasCommand(command) {
|
||||||
s.command = command
|
s.command = command
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
s.CommandMissing = true
|
s.CommandMissing = true
|
||||||
|
|
||||||
// only use the native fallback when set by the user
|
// only use the native fallback when set by the user
|
||||||
if s.IsWslSharedPath && s.props.GetBool(NativeFallback, false) {
|
if s.IsWslSharedPath && s.props.GetBool(NativeFallback, false) {
|
||||||
command = strings.TrimSuffix(command, ".exe")
|
command = strings.TrimSuffix(command, ".exe")
|
||||||
if s.env.HasCommand(command) {
|
if s.env.HasCommand(command) {
|
||||||
s.command = command
|
s.command = command
|
||||||
|
s.nativeFallback = true
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue