diff options
author | Rafael Kitover <rkitover@gmail.com> | 2024-05-25 12:44:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-25 20:44:39 +0800 |
commit | fdeb01cd77404aba446c67af32134a2ff793a14b (patch) | |
tree | fc45738c89069262a59feaa068de16d02d3206a6 /src/nvim/main.c | |
parent | bdb81afab3e5c43a33267666c2689feb284f6b52 (diff) | |
download | rneovim-fdeb01cd77404aba446c67af32134a2ff793a14b.tar.gz rneovim-fdeb01cd77404aba446c67af32134a2ff793a14b.tar.bz2 rneovim-fdeb01cd77404aba446c67af32134a2ff793a14b.zip |
feat(main): expand file ~\ or ~/ prefix on Windows (#28515)
In command_line_scan() for MSWIN, expand "~\" or "~/" prefixed paths to
the USERPROFILE environment variable for the user's profile directory.
Fix #23901
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Diffstat (limited to 'src/nvim/main.c')
-rw-r--r-- | src/nvim/main.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 30b6b6e86b..17a0bbf082 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1444,6 +1444,19 @@ scripterror: ga_grow(&global_alist.al_ga, 1); char *p = xstrdup(argv[0]); + // On Windows expand "~\" or "~/" prefix in file names to profile directory. +#ifdef MSWIN + if (*p == '~' && (p[1] == '\\' || p[1] == '/')) { + char *profile_dir = vim_getenv("HOME"); + size_t size = strlen(profile_dir) + strlen(p); + char *tilde_expanded = xmalloc(size); + snprintf(tilde_expanded, size, "%s%s", profile_dir, p + 1); + xfree(p); + xfree(profile_dir); + p = tilde_expanded; + } +#endif + if (parmp->diff_mode && os_isdir(p) && GARGCOUNT > 0 && !os_isdir(alist_name(&GARGLIST[0]))) { char *r = concat_fnames(p, path_tail(alist_name(&GARGLIST[0])), true); |