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

Export-PoshTheme disregards the -FilePath parameter #748

Closed
2 tasks done
skycommand opened this issue May 27, 2021 · 13 comments
Closed
2 tasks done

Export-PoshTheme disregards the -FilePath parameter #748

skycommand opened this issue May 27, 2021 · 13 comments

Comments

@skycommand
Copy link

Prerequisites

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

Description

The Export-PoshTheme seems to have trouble understanding the relative path in the -FilePath parameter. Instead of resolving the relative path according to the current folder, it resolves the path according to the desktop!

Environment

  • Oh my Posh version: 3.157.3
  • Theme: I tried Powerline, Paradox and Slimfat, but the problem is theme-independent
  • Operating System: Windows 10 v21H1 x64
  • Shell: Windows Shell version 10.0.19043.1023
  • Terminal: PowerShell 7.1

Steps to Reproduce

  1. Launch PowerShell 7.1 via pwsh.exe -noprofile
  2. Issue the following commands, one by one:
Set-Location 'D:\Projects\AdminScripts\' #or another directory of your choosing
Import-Module -Name 'oh-my-posh' -MinimumVersion 3.0
Set-PoshPrompt Slim
Export-PoshTheme -FilePath '.\slim.json' -Format json

Expected behavior: slim.json must appear in D:\Projects\AdminScripts

Actual behavior: slim.json appears in ~ or (in one occasion) ~\Desktop (Use a utility like Everything to locate it in real-time)

@lnu
Copy link
Contributor

lnu commented May 27, 2021

If you don't set the FilePath, the text is copied to the clipboard.
From what I see, the FilePath works well with a fully qualified path but it has an issue with relative paths.

@JanDeDobbeleer
Copy link
Owner

@lnu this is going to be a fix like mapping HOME

@lnu
Copy link
Contributor

lnu commented May 27, 2021

I did this:

else {
    $FilePath = "$(pwd)\$FilePath"
}

after the

 if ($FilePath.StartsWith('~')) {
     $FilePath = $FilePath.Replace('~', $HOME)
}

Final code:

    if ($FilePath -ne "") {
        if ($FilePath.StartsWith('~')) {
            $FilePath = $FilePath.Replace('~', $HOME)
        }
        else {
            $FilePath = "$(pwd)\$FilePath"
        }
        [IO.File]::WriteAllLines($FilePath, $configString)
    }
    else {
        Set-Clipboard $configString
        Write-Output "Theme copied to clipboard"
    }

It seems ok

@JanDeDobbeleer
Copy link
Owner

@lnu won't that fail when you add a full path?

@lnu
Copy link
Contributor

lnu commented May 27, 2021

Yep, we should add a check to see if the path is full with ‘IsPathRooted’(for example). Or use GetFullPath. I don’t remember if it will resolve ~.

@JanDeDobbeleer
Copy link
Owner

@lnu I guess we can consider this closed now, right?

@lnu
Copy link
Contributor

lnu commented May 28, 2021

For me yes, can you validate @skycommand ?

@skycommand
Copy link
Author

skycommand commented May 29, 2021

@lnu and @JanDeDobbeleer
Since you said that the problem has been fixed, I took the pain of testing it on both my machine and a clean virtual machine. In both tests, I installed Oh-my-posh fresh from the Internet. In both cases, version 3.158.4 got installed.

I am afraid I can say with certainty that the bug persists. On my virtual machine, Export-PoshTheme attempted to write the file into my Windows folder!

Actual machine's screenshot:
Actual machine

Virtual machine's screenshot:
Virtual machine

@JanDeDobbeleer
Copy link
Owner

@skycommand "you took the pain"? Really? That's how we're addressing people who took up the task the same day waiting on your feedback to see if it was also resolved on your end?

I'll check later today, in the meanwhile, work on your attitude and gratitude.

@skycommand
Copy link
Author

@JanDeDobbeleer It's an expression. "Took the pain" means "carried out a certain task". No actual pain is involved. Sorry, that's how English works.

@lnu
Copy link
Contributor

lnu commented May 29, 2021

Yes, There is a bug for powershell core reported about this(I found it on macos this morning). The fix is to pass $pwd as second parameter to GetFullPath.
PowerShell/PowerShell#10278

@skycommand
Copy link
Author

Oh, yeah. PowerShell's run space cannot alter the PowerShell host process's current directory. There is a reason for that: In run space, the current directory is a PSDrive not an actual file system volume. Consider this:

Set-Location HKLM:\Software
$PWD.ProviderPath

These paths are not even on the file system.

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 Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants