Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions command-signatures/src/generators/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use warp_completion_metadata::{
GeneratorResultsCollector, Suggestion,
};

/// Shell command that reads ~/.ssh/config and all files referenced by Include directives.
/// Include paths are resolved by replacing ~ with $HOME and treating relative paths as
/// relative to ~/.ssh/. Glob patterns in Include paths are expanded by the shell.
const SSH_CONFIG_CMD: &str = "cat ~/.ssh/config $(awk 'tolower($1)==\"include\"{for(i=2;i<=NF;i++){gsub(\"~\",ENVIRON[\"HOME\"],$i);if($i!~/^\\//)$i=ENVIRON[\"HOME\"]\"/.ssh/\"$i;print $i}}' ~/.ssh/config 2>/dev/null) 2>/dev/null";

fn hosts(output: &str) -> GeneratorResults {
output
.lines()
Expand All @@ -22,11 +27,11 @@ pub fn generator() -> CommandSignatureGenerators {
CommandSignatureGenerators::new("ssh")
.add_generator(
"hosts",
Generator::script(CommandBuilder::single_command("cat ~/.ssh/config"), hosts),
Generator::script(CommandBuilder::single_command(SSH_CONFIG_CMD), hosts),
)
.add_generator(
"addresses",
Generator::script(CommandBuilder::single_command("cat ~/.ssh/config"), hosts),
Generator::script(CommandBuilder::single_command(SSH_CONFIG_CMD), hosts),
)
.add_generator(
"known_hosts",
Expand Down
Loading