badmotorfinger / z

Save time typing out directory paths in PowerShell by jumping around instead.
The Unlicense
434 stars 33 forks source link

Add support for .cdHistory file being hidden #48

Closed smitranic closed 4 years ago

smitranic commented 4 years ago

Update WriteHistoryToDisk function to use Set-Content instead of Out-File since Out-File throws an access denied exception when trying to write to a hidden file.

A common practice on Windows is to make the dotfiles in the user home folder hidden, and doing that on .cdHistory currently causes an exception whenever .cdHistory is updated.

smitranic commented 4 years ago

Just to clarify, this issue manifests itself only if the user explicitly sets the 'hidden' attribute on the .cdHistory file.

badmotorfinger commented 4 years ago

Thank you for taking time to maintain this script, much appreciated.

Can you please verify if file encoding will be a problem by using Set-Content? See here https://stackoverflow.com/questions/10655788/powershell-set-content-and-out-file-what-is-the-difference

smitranic commented 4 years ago

PowerShell Core uses UTF8 by default for both Set-Content and Out-File, but you are correct, older PowerShell (v5 and earlier) don't. So I have added the -Encoding UTF8 parameter to Set-Encoding and tested it with folders with non-ANSI characters and they get saved in UTF8.

Everything seems to work fine with Unicode characters now in both PowerShell Core (pwsh.exe) and PowerShell Desktop (powershell.exe).

badmotorfinger commented 4 years ago

Thank you once again for taking the time to help me maintain this.

Will publish to the PowerShell gallery in the next few days.

badmotorfinger commented 4 years ago

Package published https://www.powershellgallery.com/packages/z/1.1.13