chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.62k stars 143 forks source link

rl.expandtilde() did not expand to %USERPROFILE% #479

Closed cardin closed 1 year ago

cardin commented 1 year ago

I was trying to use the tilde_autoexpand.lua script, and I realised it was expanding my tilde to my J: drive.

Any idea why that would be the case?

System:

chrisant996 commented 1 year ago

What does running set home report?

Tilde expansion first looks up %HOME%. If that's not set, it looks up %HOMEDRIVE% and %HOMEPATH%. If those aren't set, it looks up%USERPROFILE%`. If that's not set, it does nothing.

So, probably %HOME% or %HOMEDRIVE% refer to j:.

cardin commented 1 year ago

Ah, I've discovered the problem. While %HOME% is unset, but indeed %HOMEDRIVE% was set to j: by the sys admin.

While I could not overwrite SYS ENV %HOMEDRIVE% at a USER ENV level, your explanation of how expandtilde() resolves, gave me the idea to set %HOME% instead. So now the expandtilde() works as expected.

Thank you for the quick resolution!

chrisant996 commented 1 year ago

Martin originally made Clink v0.4.9 synthesize %HOME% from %HOMEDRIVE%%HOMEPATH% if both are set, in commit 8643c264ecbad6ad43de4e6d5de7aa2590545296 in December 2015.

Your sys admin had also set %HOMEPATH%, right? Clink shouldn't use HOMEDRIVE unless both HOMEDRIVE and HOMEPATH are set. If both are set, then they're supposed to supersede USERPROFILE, for specifying where the user's personal files are located. This is the (Windows) way. 🤷‍♂️

https://stackoverflow.com/questions/606483/what-is-the-meaning-of-these-windows-environment-variables-homedrive-homepath

cardin commented 1 year ago

Yes you're right, my sysadmin had set %HOMEPATH% = \

Your sys admin had also set %HOMEPATH%, right? Clink shouldn't use HOMEDRIVE unless both HOMEDRIVE and HOMEPATH are set. If both are set, then they're supposed to supersede USERPROFILE, for specifying where the user's personal files are located. This is the (Windows) way. 🤷‍♂️

What a weird Windows quirk... haha