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

feat(main): expand file ~\ or ~/ prefix on Windows #28515

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ DEFAULTS

EDITOR

• TODO
* On Windows, filename arguments on the command-line prefixed with "~\" or
"~/" are now expanded to the user's profile directory, not a relative path
to a literal "~" directory.

EVENTS

Expand Down
13 changes: 13 additions & 0 deletions src/nvim/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,19 @@ static void command_line_scan(mparm_T *parmp)
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this happen before init_homedir, or why not use os_homedir ? $HOME is not always available Windows.

Also needs test coverage.

But I'm confused about why this is needed, because #23901 (comment) indicated that powershell would provide this feature without every program needing to implement it manually.

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);
rkitover marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down