From 47b8acb9994ffd5540c94a78d18757c2930aea49 Mon Sep 17 00:00:00 2001 From: Adrien DELSALLE Date: Mon, 25 Oct 2021 11:23:44 +0200 Subject: [PATCH 1/2] improve umamba bash completion use default path completion when nothing is found fixes -p or -f requiring paths options add a mock umamba activate subcommand to provide env names completion add docs --- docs/source/installation.rst | 26 ++++++++++++++++++++++++++ src/micromamba/completer.bash | 2 +- src/micromamba/completer.cpp | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 0971b7cd0b..2cf50c8a8e 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -144,3 +144,29 @@ Windows # and use micromamba directly micromamba create -f ./test/env_win.yaml -y micromamba activate yourenv + + +.. _shell_completion: + +Shell completion +================ + +For now, only ``micromamba`` provides shell completion on ``bash``. + +To activate it, it's as simple as running: + +.. code:: + + micromamba shell completion + +.. note:: + This command will not work if you're not using ``bash`` + +The completion is now available in any new shell opened or in the current shell after running ``source ~/.bashrc`` to take modifications into account. + +| Just hit ```` to get completion when typing your command. +| For example the following command will help you to pick a named environment to activate: + +.. code:: + + micromamba activate diff --git a/src/micromamba/completer.bash b/src/micromamba/completer.bash index d7eee13258..64d06fab7f 100755 --- a/src/micromamba/completer.bash +++ b/src/micromamba/completer.bash @@ -5,6 +5,6 @@ _umamba_completions() COMPREPLY=($(micromamba completer "${COMP_WORDS[@]:1}")) } -complete -F _umamba_completions micromamba +complete -o default -F _umamba_completions micromamba # <<< umamba completion <<< )MAMBARAW" diff --git a/src/micromamba/completer.cpp b/src/micromamba/completer.cpp index fe18ecf4db..dcc4b888fa 100644 --- a/src/micromamba/completer.cpp +++ b/src/micromamba/completer.cpp @@ -83,6 +83,20 @@ overwrite_callbacks(std::vector& apps, } } +void +add_activate_completion(CLI::App* app, std::vector& completer_args, bool& completed) +{ + CLI::App* activate_subcom + = app->add_subcommand("activate", "Mock activate shell function for completion"); + activate_subcom->callback([app, &completer_args, &completed]() { + if (completer_args.size() == 1) + { + completer_args = { "-n", completer_args.back() }; + complete_options(app, completer_args, completed); + } + }); +} + void get_completions(CLI::App* app, int argc, char** argv) { @@ -100,6 +114,7 @@ get_completions(CLI::App* app, int argc, char** argv) std::vector apps = { app }; overwrite_callbacks(apps, completer_args, completed); + add_activate_completion(app, completer_args, completed); argv[1] = argv[0]; try From c540e03136d528a57b18a134eeb132a29c44892b Mon Sep 17 00:00:00 2001 From: Adrien DELSALLE Date: Mon, 25 Oct 2021 14:15:49 +0200 Subject: [PATCH 2/2] improve documentation --- docs/source/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 2cf50c8a8e..82eba75c4a 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -160,7 +160,7 @@ To activate it, it's as simple as running: micromamba shell completion .. note:: - This command will not work if you're not using ``bash`` + This command will only work on ``bash`` The completion is now available in any new shell opened or in the current shell after running ``source ~/.bashrc`` to take modifications into account.