-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(clap-complete/unstable-dynamic): add '~' to HOME dir completion support #5998
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -274,7 +274,19 @@ impl ValueCompleter for PathCompleter { | |
current_dir_actual = std::env::current_dir().ok(); | ||
current_dir_actual.as_deref() | ||
}); | ||
let mut candidates = complete_path(current, current_dir, filter); | ||
|
||
let Some(current) = current.to_str() else { | ||
return vec![]; | ||
}; | ||
Comment on lines
+278
to
+280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't be doing this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I should have used |
||
|
||
#[cfg(unix)] | ||
if current.starts_with("~") { | ||
Comment on lines
+282
to
+283
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is marked as unix-only but the dep is always added However, should we support this on Windows? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this feature should be supported on Windows, as it does not seem to be used on Windows.
Comment on lines
+282
to
+283
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, there are other variants of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about what they are, can you explain? |
||
if let Some(home) = home_dir() { | ||
current.replace_range(..1, &home.to_string_lossy()); | ||
} | ||
} | ||
|
||
let mut candidates = complete_path(¤t, current_dir, filter); | ||
if self.stdio && current.is_empty() { | ||
candidates.push(CompletionCandidate::new("-").help(Some("stdio".into()))); | ||
} | ||
|
@@ -283,7 +295,7 @@ impl ValueCompleter for PathCompleter { | |
} | ||
|
||
pub(crate) fn complete_path( | ||
value_os: &OsStr, | ||
value_os: &str, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we changing this to be more restrictive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There doesn't seem to be a way for me to get let mut new_current = OsString::new();
new_current.write_str(¤t).ok();
let mut candidates = complete_path(&new_current, current_dir, filter); |
||
current_dir: Option<&std::path::Path>, | ||
is_wanted: &dyn Fn(&std::path::Path) -> bool, | ||
) -> Vec<CompletionCandidate> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With
std::env::home_dir
being undeprecated, we should be using this through a polyfll. I'll need to go create one before this can move forward.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if it wasn't for that, I'd be hesitant to add this out of question of whether the extra dep is worth it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we could copy that function from std? https://github.com/rust-lang/rust/blob/2682b88c526d493edeb2d3f2df358f44db69b73f/library/std/src/sys/unix/os.rs#L595