Skip to content

Commit b24593e

Browse files
authored
[vcpkg] Add tab completion for Fish (microsoft#14206)
1 parent 799c002 commit b24593e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/vcpkg/commands.integrate.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,34 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
477477
fs.write_contents(bashrc_path, Strings::join("\n", bashrc_content) + '\n', VCPKG_LINE_INFO);
478478
Checks::exit_success(VCPKG_LINE_INFO);
479479
}
480+
481+
static void integrate_fish(const VcpkgPaths& paths)
482+
{
483+
fs::path fish_completions_path;
484+
const auto config_path = System::get_environment_variable("XDG_CONFIG_HOME");
485+
if (config_path.has_value())
486+
{
487+
fish_completions_path = fs::path{config_path.value_or_exit(VCPKG_LINE_INFO)};
488+
}
489+
else
490+
{
491+
const auto home_path = System::get_environment_variable("HOME").value_or_exit(VCPKG_LINE_INFO);
492+
fish_completions_path = fs::path{home_path} / ".config";
493+
}
494+
fish_completions_path = fish_completions_path / "fish" / "completions" / "vcpkg.fish";
495+
496+
if (fs::stdfs::exists(fish_completions_path))
497+
{
498+
System::printf("vcpkg fish completion is already added at %s.\n", fs::u8string(fish_completions_path));
499+
Checks::exit_success(VCPKG_LINE_INFO);
500+
}
501+
502+
const fs::path completion_script_path = paths.scripts / "vcpkg_completion.fish";
503+
504+
System::printf("Adding vcpkg completion entry at %s.\n", fs::u8string(fish_completions_path));
505+
fs::stdfs::create_symlink(completion_script_path, fish_completions_path);
506+
Checks::exit_success(VCPKG_LINE_INFO);
507+
}
480508
#endif
481509

482510
void append_helpstring(HelpTableFormatter& table)
@@ -491,6 +519,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
491519
table.format("vcpkg integrate install", "Make installed packages available user-wide");
492520
table.format("vcpkg integrate remove", "Remove user-wide integration");
493521
table.format("vcpkg integrate bash", "Enable bash tab-completion");
522+
table.format("vcpkg integrate fish", "Enable fish tab-completion");
494523
#endif // ^^^ !defined(_WIN32)
495524
}
496525

@@ -508,6 +537,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
508537
static const std::string PROJECT = "project";
509538
static const std::string POWERSHELL = "powershell";
510539
static const std::string BASH = "bash";
540+
static const std::string FISH = "x-fish";
511541
}
512542

513543
static std::vector<std::string> valid_arguments(const VcpkgPaths&)
@@ -518,7 +548,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
518548
#if defined(_WIN32)
519549
Subcommand::PROJECT, Subcommand::POWERSHELL,
520550
#else
521-
Subcommand::BASH,
551+
Subcommand::BASH, Subcommand::FISH,
522552
#endif
523553
};
524554
}
@@ -557,6 +587,10 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
557587
{
558588
return integrate_bash(paths);
559589
}
590+
if (args.command_arguments[0] == Subcommand::FISH)
591+
{
592+
return integrate_fish(paths);
593+
}
560594
#endif
561595

562596
Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown parameter %s for integrate", args.command_arguments[0]);

0 commit comments

Comments
 (0)