diff options
| author | Jared Irwin <Link1J@users.noreply.github.com> | 2020-11-02 20:25:43 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-02 17:25:43 -0800 |
| commit | 5407dcdb009309b993b19ee99ad98b6ead37d5ac (patch) | |
| tree | 8b44704abb9bf260782f5d9997ed44c6c7dada9e /toolsrc | |
| parent | 13f582d864fb2601cf199f0742709f2f9a80aa51 (diff) | |
| download | vcpkg-5407dcdb009309b993b19ee99ad98b6ead37d5ac.tar.gz vcpkg-5407dcdb009309b993b19ee99ad98b6ead37d5ac.zip | |
[vcpkg] Add tab completion for Fish (#14206)
Diffstat (limited to 'toolsrc')
| -rw-r--r-- | toolsrc/src/vcpkg/commands.integrate.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/toolsrc/src/vcpkg/commands.integrate.cpp b/toolsrc/src/vcpkg/commands.integrate.cpp index 3a682b4c9..ce1522255 100644 --- a/toolsrc/src/vcpkg/commands.integrate.cpp +++ b/toolsrc/src/vcpkg/commands.integrate.cpp @@ -477,6 +477,34 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console fs.write_contents(bashrc_path, Strings::join("\n", bashrc_content) + '\n', VCPKG_LINE_INFO); Checks::exit_success(VCPKG_LINE_INFO); } + + static void integrate_fish(const VcpkgPaths& paths) + { + fs::path fish_completions_path; + const auto config_path = System::get_environment_variable("XDG_CONFIG_HOME"); + if (config_path.has_value()) + { + fish_completions_path = fs::path{config_path.value_or_exit(VCPKG_LINE_INFO)}; + } + else + { + const auto home_path = System::get_environment_variable("HOME").value_or_exit(VCPKG_LINE_INFO); + fish_completions_path = fs::path{home_path} / ".config"; + } + fish_completions_path = fish_completions_path / "fish" / "completions" / "vcpkg.fish"; + + if (fs::stdfs::exists(fish_completions_path)) + { + System::printf("vcpkg fish completion is already added at %s.\n", fs::u8string(fish_completions_path)); + Checks::exit_success(VCPKG_LINE_INFO); + } + + const fs::path completion_script_path = paths.scripts / "vcpkg_completion.fish"; + + System::printf("Adding vcpkg completion entry at %s.\n", fs::u8string(fish_completions_path)); + fs::stdfs::create_symlink(completion_script_path, fish_completions_path); + Checks::exit_success(VCPKG_LINE_INFO); + } #endif void append_helpstring(HelpTableFormatter& table) @@ -491,6 +519,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console table.format("vcpkg integrate install", "Make installed packages available user-wide"); table.format("vcpkg integrate remove", "Remove user-wide integration"); table.format("vcpkg integrate bash", "Enable bash tab-completion"); + table.format("vcpkg integrate fish", "Enable fish tab-completion"); #endif // ^^^ !defined(_WIN32) } @@ -508,6 +537,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console static const std::string PROJECT = "project"; static const std::string POWERSHELL = "powershell"; static const std::string BASH = "bash"; + static const std::string FISH = "x-fish"; } 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 #if defined(_WIN32) Subcommand::PROJECT, Subcommand::POWERSHELL, #else - Subcommand::BASH, + Subcommand::BASH, Subcommand::FISH, #endif }; } @@ -557,6 +587,10 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console { return integrate_bash(paths); } + if (args.command_arguments[0] == Subcommand::FISH) + { + return integrate_fish(paths); + } #endif Checks::exit_with_message(VCPKG_LINE_INFO, "Unknown parameter %s for integrate", args.command_arguments[0]); |
