diff --git a/crates/pixi_config/src/lib.rs b/crates/pixi_config/src/lib.rs index 6421d4f106..dad239489d 100644 --- a/crates/pixi_config/src/lib.rs +++ b/crates/pixi_config/src/lib.rs @@ -210,32 +210,20 @@ pub struct ConfigCliActivation { /// Do not source the autocompletion scripts from the environment. #[arg(long, help_heading = consts::CLAP_CONFIG_OPTIONS)] - no_completion: Option, + no_completions: bool, } impl ConfigCliActivation { pub fn merge_config(self, config: Config) -> Config { let mut config = config; config.shell.force_activate = Some(self.force_activate); - if let Some(no_completion) = self.no_completion { - config.shell.source_completion_scripts = Some(!no_completion); + if self.no_completions { + config.shell.source_completion_scripts = Some(false); } config } } -impl From for Config { - fn from(cli: ConfigCliActivation) -> Self { - Self { - shell: ShellConfig { - force_activate: Some(cli.force_activate), - source_completion_scripts: None, - change_ps1: None, - }, - ..Default::default() - } - } -} #[derive(Clone, Default, Debug, Deserialize, Serialize, PartialEq, Eq)] #[serde(deny_unknown_fields, rename_all = "kebab-case")] pub struct RepodataChannelConfig { diff --git a/docs/reference/cli/pixi/run.md b/docs/reference/cli/pixi/run.md index 0585a982ea..bfa4e2cf27 100644 --- a/docs/reference/cli/pixi/run.md +++ b/docs/reference/cli/pixi/run.md @@ -30,9 +30,8 @@ pixi run [OPTIONS] [TASK]... : Max concurrent network requests, default is `50` - `--force-activate` : Do not use the environment activation cache. (default: true except in experimental mode) -- `--no-completion ` +- `--no-completions` : Do not source the autocompletion scripts from the environment -
**options**: `true`, `false` ## Update Options - `--no-install` diff --git a/docs/reference/cli/pixi/shell-hook.md b/docs/reference/cli/pixi/shell-hook.md index a290caadb5..8cd9ff0d35 100644 --- a/docs/reference/cli/pixi/shell-hook.md +++ b/docs/reference/cli/pixi/shell-hook.md @@ -29,9 +29,8 @@ pixi shell-hook [OPTIONS] : Max concurrent network requests, default is `50` - `--force-activate` : Do not use the environment activation cache. (default: true except in experimental mode) -- `--no-completion ` +- `--no-completions` : Do not source the autocompletion scripts from the environment -
**options**: `true`, `false` - `--change-ps1 ` : Do not change the PS1 variable when starting a prompt
**options**: `true`, `false` diff --git a/docs/reference/cli/pixi/shell.md b/docs/reference/cli/pixi/shell.md index baf02682cb..d4618cde3c 100644 --- a/docs/reference/cli/pixi/shell.md +++ b/docs/reference/cli/pixi/shell.md @@ -28,9 +28,8 @@ pixi shell [OPTIONS]
**options**: `true`, `false` - `--force-activate` : Do not use the environment activation cache. (default: true except in experimental mode) -- `--no-completion ` +- `--no-completions` : Do not source the autocompletion scripts from the environment -
**options**: `true`, `false` ## Update Options - `--no-install` diff --git a/src/cli/shell_hook.rs b/src/cli/shell_hook.rs index 4e7a7665a3..f5e5b4b916 100644 --- a/src/cli/shell_hook.rs +++ b/src/cli/shell_hook.rs @@ -145,9 +145,9 @@ async fn generate_environment_json( /// Prints the activation script to the stdout. pub async fn execute(args: Args) -> miette::Result<()> { let config = args - .prompt_config - .merge_config(args.activation_config.into()) - .merge_config(args.config.clone().into()); + .activation_config + .merge_config(args.prompt_config.merge_config(args.config.clone().into())); + let workspace = WorkspaceLocator::for_cli() .with_search_start(args.project_config.workspace_locator_start()) .locate()? diff --git a/tests/data/channels/channels/completions_channel_1/linux-64/repodata.json b/tests/data/channels/channels/completions_channel_1/linux-64/repodata.json index 0f28a0d3f3..6dc1bd2995 100644 --- a/tests/data/channels/channels/completions_channel_1/linux-64/repodata.json +++ b/tests/data/channels/channels/completions_channel_1/linux-64/repodata.json @@ -1 +1 @@ -{"info":{"subdir":"linux-64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-hb0f4dca_1.conda":{"arch":"x86_64","build":"hb0f4dca_1","build_number":1,"depends":[],"md5":"727e54da6071dc523d93875257c7a19b","name":"ripgrep-completions","platform":"linux","sha256":"f616f9caa303466530b982f7cdd3da45665ea88c4ea7e4a7ba2204dbb6f86600","size":15622,"subdir":"linux-64","timestamp":1743062819553,"version":"14.1.1"}},"repodata_version":2} +{"info":{"subdir":"linux-64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-hb0f4dca_1.conda":{"arch":"x86_64","build":"hb0f4dca_1","build_number":1,"depends":[],"md5":"72559505584a0f688dd6122bdd88d327","name":"ripgrep-completions","platform":"linux","sha256":"ffa7dbabbf7615b71e2ec147f9f2fb217c8ca3ccea1fa45980675478a2e0c806","size":15623,"subdir":"linux-64","timestamp":1744188567968,"version":"14.1.1"}},"repodata_version":2} diff --git a/tests/data/channels/channels/completions_channel_1/linux-64/ripgrep-completions-14.1.1-hb0f4dca_1.conda b/tests/data/channels/channels/completions_channel_1/linux-64/ripgrep-completions-14.1.1-hb0f4dca_1.conda index 4f25c81522..6ebef702ba 100644 Binary files a/tests/data/channels/channels/completions_channel_1/linux-64/ripgrep-completions-14.1.1-hb0f4dca_1.conda and b/tests/data/channels/channels/completions_channel_1/linux-64/ripgrep-completions-14.1.1-hb0f4dca_1.conda differ diff --git a/tests/data/channels/channels/completions_channel_1/osx-64/repodata.json b/tests/data/channels/channels/completions_channel_1/osx-64/repodata.json index 2622a3fb0e..0d57bbe97d 100644 --- a/tests/data/channels/channels/completions_channel_1/osx-64/repodata.json +++ b/tests/data/channels/channels/completions_channel_1/osx-64/repodata.json @@ -1 +1 @@ -{"info":{"subdir":"osx-64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-h0dc7051_1.conda":{"arch":"x86_64","build":"h0dc7051_1","build_number":1,"depends":[],"md5":"52f35e06ef99cc3ee9d143803a996f9b","name":"ripgrep-completions","platform":"osx","sha256":"f852e69e7620afc9a269e03bae27588ae55cc833ee8ac12d95a775f7241f9d91","size":15625,"subdir":"osx-64","timestamp":1743062821878,"version":"14.1.1"}},"repodata_version":2} +{"info":{"subdir":"osx-64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-h0dc7051_1.conda":{"arch":"x86_64","build":"h0dc7051_1","build_number":1,"depends":[],"md5":"bda9e8efd256b3f357fd88b955dbb20f","name":"ripgrep-completions","platform":"osx","sha256":"72e9c615e47567f8335903026287999f9df5b04871ff4495cf965f35c226d2cf","size":15621,"subdir":"osx-64","timestamp":1744188570379,"version":"14.1.1"}},"repodata_version":2} diff --git a/tests/data/channels/channels/completions_channel_1/osx-64/ripgrep-completions-14.1.1-h0dc7051_1.conda b/tests/data/channels/channels/completions_channel_1/osx-64/ripgrep-completions-14.1.1-h0dc7051_1.conda index 921f747508..cb9cf77a99 100644 Binary files a/tests/data/channels/channels/completions_channel_1/osx-64/ripgrep-completions-14.1.1-h0dc7051_1.conda and b/tests/data/channels/channels/completions_channel_1/osx-64/ripgrep-completions-14.1.1-h0dc7051_1.conda differ diff --git a/tests/data/channels/channels/completions_channel_1/osx-arm64/repodata.json b/tests/data/channels/channels/completions_channel_1/osx-arm64/repodata.json index 811ff51ce1..2de1f74bf6 100644 --- a/tests/data/channels/channels/completions_channel_1/osx-arm64/repodata.json +++ b/tests/data/channels/channels/completions_channel_1/osx-arm64/repodata.json @@ -1 +1 @@ -{"info":{"subdir":"osx-arm64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-h60d57d3_1.conda":{"arch":"arm64","build":"h60d57d3_1","build_number":1,"depends":[],"md5":"b2d4c4bd1fab023a8d416a826d7606d1","name":"ripgrep-completions","platform":"osx","sha256":"bdd180980f838acc631f8a48fd38e5b0f8551f23da17c94e5c9f1f449c759051","size":15622,"subdir":"osx-arm64","timestamp":1743062820714,"version":"14.1.1"}},"repodata_version":2} +{"info":{"subdir":"osx-arm64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-h60d57d3_1.conda":{"arch":"arm64","build":"h60d57d3_1","build_number":1,"depends":[],"md5":"9079637a8c549adca1beed602c28d10b","name":"ripgrep-completions","platform":"osx","sha256":"093382f59a1ac846c8acc76f6b5f43e2d9faa09c05cda5345ab4873e5485dc7a","size":15625,"subdir":"osx-arm64","timestamp":1744188569180,"version":"14.1.1"}},"repodata_version":2} diff --git a/tests/data/channels/channels/completions_channel_1/osx-arm64/ripgrep-completions-14.1.1-h60d57d3_1.conda b/tests/data/channels/channels/completions_channel_1/osx-arm64/ripgrep-completions-14.1.1-h60d57d3_1.conda index b6783dd317..d54b254ae4 100644 Binary files a/tests/data/channels/channels/completions_channel_1/osx-arm64/ripgrep-completions-14.1.1-h60d57d3_1.conda and b/tests/data/channels/channels/completions_channel_1/osx-arm64/ripgrep-completions-14.1.1-h60d57d3_1.conda differ diff --git a/tests/data/channels/channels/completions_channel_1/win-64/repodata.json b/tests/data/channels/channels/completions_channel_1/win-64/repodata.json index e8b9dcf5e2..c78e6588cb 100644 --- a/tests/data/channels/channels/completions_channel_1/win-64/repodata.json +++ b/tests/data/channels/channels/completions_channel_1/win-64/repodata.json @@ -1 +1 @@ -{"info":{"subdir":"win-64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-h9490d1a_1.conda":{"arch":"x86_64","build":"h9490d1a_1","build_number":1,"depends":[],"md5":"62ce56a7e286f1bea4f0405127ffc5c5","name":"ripgrep-completions","platform":"win","sha256":"5c3f8db20e43333a0f7e89dc20bb072a950603df97c427c3f48a3677028c165d","size":1225,"subdir":"win-64","timestamp":1743062818391,"version":"14.1.1"}},"repodata_version":2} +{"info":{"subdir":"win-64"},"packages":{},"packages.conda":{"ripgrep-completions-14.1.1-h9490d1a_1.conda":{"arch":"x86_64","build":"h9490d1a_1","build_number":1,"depends":[],"md5":"f5ccc0304d1e824da91512a1e7309c84","name":"ripgrep-completions","platform":"win","sha256":"47627d939ead14e4bdc60152b99511584fd4601b4b51ecb8f5bf0b2bb7b044e5","size":15626,"subdir":"win-64","timestamp":1744188558502,"version":"14.1.1"}},"repodata_version":2} diff --git a/tests/data/channels/channels/completions_channel_1/win-64/ripgrep-completions-14.1.1-h9490d1a_1.conda b/tests/data/channels/channels/completions_channel_1/win-64/ripgrep-completions-14.1.1-h9490d1a_1.conda index bbb2fff5ce..a3aedcbf71 100644 Binary files a/tests/data/channels/channels/completions_channel_1/win-64/ripgrep-completions-14.1.1-h9490d1a_1.conda and b/tests/data/channels/channels/completions_channel_1/win-64/ripgrep-completions-14.1.1-h9490d1a_1.conda differ diff --git a/tests/data/channels/recipes/completions_channel_1.yaml b/tests/data/channels/recipes/completions_channel_1.yaml index 737b69eee9..10b138fded 100644 --- a/tests/data/channels/recipes/completions_channel_1.yaml +++ b/tests/data/channels/recipes/completions_channel_1.yaml @@ -8,18 +8,17 @@ package: build: number: 1 script: + # ZSH completions + - mkdir -p $PREFIX/share/zsh/site-functions + - rg --generate complete-zsh > $PREFIX/share/zsh/site-functions/_rg + # Bash completions + - mkdir -p $PREFIX/share/bash-completion/completions + - rg --generate complete-bash > $PREFIX/share/bash-completion/completions/rg + # Fish completions + - mkdir -p $PREFIX/share/fish/vendor_completions.d + - rg --generate complete-fish > $PREFIX/share/fish/vendor_completions.d/rg.fish - if: unix then: - # ZSH completions - - mkdir -p $PREFIX/share/zsh/site-functions - - rg --generate complete-zsh > $PREFIX/share/zsh/site-functions/_rg - # Bash completions - - mkdir -p $PREFIX/share/bash-completion/completions - - rg --generate complete-bash > $PREFIX/share/bash-completion/completions/rg - # Fish completions - - mkdir -p $PREFIX/share/fish/vendor_completions.d - - rg --generate complete-fish > $PREFIX/share/fish/vendor_completions.d/rg.fish - # Create a dummy rg executable - mkdir -p $PREFIX/bin - echo "echo rg on unix" > $PREFIX/bin/rg diff --git a/tests/integration_python/conftest.py b/tests/integration_python/conftest.py index 6c2cb0d76b..c3aa36fc2f 100644 --- a/tests/integration_python/conftest.py +++ b/tests/integration_python/conftest.py @@ -120,5 +120,10 @@ def deno_channel(channels: Path) -> str: return channels.joinpath("deno_channel").as_uri() +@pytest.fixture +def completions_channel_1(channels: Path) -> str: + return channels.joinpath("completions_channel_1").as_uri() + + def doc_pixi_workspaces() -> Path: return Path(__file__).parents[2].joinpath("docs", "source_files", "pixi_workspaces") diff --git a/tests/integration_python/pixi_global/conftest.py b/tests/integration_python/pixi_global/conftest.py index 1c25b2c7ee..ababd4aef6 100644 --- a/tests/integration_python/pixi_global/conftest.py +++ b/tests/integration_python/pixi_global/conftest.py @@ -10,8 +10,3 @@ def trampoline_channel(channels: Path) -> str: @pytest.fixture def trampoline_path_channel(channels: Path) -> str: return channels.joinpath("trampoline_path_channel").as_uri() - - -@pytest.fixture -def completions_channel_1(channels: Path) -> str: - return channels.joinpath("completions_channel_1").as_uri() diff --git a/tests/integration_python/test_shell.py b/tests/integration_python/test_shell.py new file mode 100644 index 0000000000..9adff0c6d1 --- /dev/null +++ b/tests/integration_python/test_shell.py @@ -0,0 +1,39 @@ +from pathlib import Path + +from .common import ExitCode, verify_cli_command + + +def test_shell_hook_completions( + pixi: Path, tmp_pixi_workspace: Path, completions_channel_1: str +) -> None: + # Create a new workspace + verify_cli_command( + [pixi, "init", "--channel", completions_channel_1, tmp_pixi_workspace], ExitCode.SUCCESS + ) + + verify_cli_command( + [pixi, "add", "--manifest-path", tmp_pixi_workspace, "ripgrep-completions"], + ExitCode.SUCCESS, + ) + + # Completions are sourced by default + verify_cli_command( + [pixi, "shell-hook", "--manifest-path", tmp_pixi_workspace, "--shell", "bash"], + ExitCode.SUCCESS, + stdout_contains="bash-completion", + ) + + # Opt-out of sourcing completions + verify_cli_command( + [ + pixi, + "shell-hook", + "--manifest-path", + tmp_pixi_workspace, + "--shell", + "bash", + "--no-completions", + ], + ExitCode.SUCCESS, + stdout_excludes="bash-completion", + )