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

Use HOME environment variable, but... #13

Closed
gotoh opened this issue Jul 12, 2024 · 7 comments
Closed

Use HOME environment variable, but... #13

gotoh opened this issue Jul 12, 2024 · 7 comments

Comments

@gotoh
Copy link
Contributor

gotoh commented Jul 12, 2024

I'm using HOME environment variable to specify my home folder,
not with HOMEDRIVE HOMEPATH or USERPROFILE.
These are all different in my case.

HOME=c:\users\gotoh
HOMEDRIVE=f:
HOMEPATH=\
USERPROFILE=c:\Users\gotoh.TAIYO

So I made a patch to use HOME prior to USERPROFILE
to cd by execute 'z' with no argument

diff --git a/config/clink-zoxide.lua b/config/clink-zoxide.lua
index c90bb5a..87417cc 100644
--- a/config/clink-zoxide.lua
+++ b/config/clink-zoxide.lua
@@ -99,7 +99,8 @@ end
 -- 'z' alias
 local function __zoxide_z(keywords)
   if #keywords == 0 then
-    return __zoxide_cd(os.getenv 'USERPROFILE')
+    local home = os.getenv("HOME") or os.getenv("USERPROFILE")
+    return __zoxide_cd(home)
   elseif #keywords == 1 then
     local keyword = keywords[1]
     if keyword == '-' then

But by clink's special behaviour, os.getenv("HOME") returns:

  1. %HOME% if defined, or...
  2. %HOMEDRIVE%%HOMEPATH% if defined, or..
  3. %USERPROFILE%

see: https://github.com/chrisant996/clink/blob/ce074165461c8e491602f4980536e8abf8d333d7/clink/core/src/os.cpp#L780

What is good fix to use HOME?

@shunsambongi
Copy link
Owner

It seems like your use case is pretty unique. I don't think I want to add any specialized logic in this script to support non-standard home directory setups, but feel free to just hard-code your preferred path into the script on your machine.

@gotoh
Copy link
Contributor Author

gotoh commented Jul 14, 2024

Yes, my case is not normal.
However, if the user is using HOME for any reason, 'clink-zoxide.lua' may not work as expected
even though clink supports a "HOME" environment by implementing own get_env() behaviour.

@eggbean
Copy link

eggbean commented Jul 14, 2024

@gotoh Your user profile is at c:\Users\gotoh.TAIYO, so it must have been recreated by the OS because your old profile was corrupted or it had to be remade for some other reason, or you tried making a new profile using the same username.

So you should be using that profile only as that is your current user profile. Anything pointing to the old profile is wrong.

@gotoh
Copy link
Contributor Author

gotoh commented Jul 14, 2024

clink's function tilde-expand supports HOME, so I would appreciate it if clink-zoxide could use os.getnev("HOME").

BTW, My USERPROFILE is gotoh.TAIYO because I already had gotoh as a local account and joined domain:TAIYO with an account with the same name, so it was created separately.
And HOMEDRIVE and HOMEPATH are forced by domain's policy.
Anyway it is not a main point of this issue.

@shunsambongi
Copy link
Owner

I think I understand what you mean. Since the special behavior for HOME will fallback to USERPROFILE, I think it's fine to use HOME instead.

@gotoh if you can test and send a PR to use HOME, I would be happy to merge it.

@shunsambongi shunsambongi reopened this Jul 15, 2024
@gotoh
Copy link
Contributor Author

gotoh commented Jul 16, 2024

I've made a PR #14.

@shunsambongi
Copy link
Owner

Closed by #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants