Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 3 additions & 15 deletions crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
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<ConfigCliActivation> 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 {
Expand Down
3 changes: 1 addition & 2 deletions docs/reference/cli/pixi/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ pixi run [OPTIONS] [TASK]...
: Max concurrent network requests, default is `50`
- <a id="arg---force-activate" href="#arg---force-activate">`--force-activate`</a>
: Do not use the environment activation cache. (default: true except in experimental mode)
- <a id="arg---no-completion" href="#arg---no-completion">`--no-completion <NO_COMPLETION>`</a>
- <a id="arg---no-completions" href="#arg---no-completions">`--no-completions`</a>
: Do not source the autocompletion scripts from the environment
<br>**options**: `true`, `false`

## Update Options
- <a id="arg---no-install" href="#arg---no-install">`--no-install`</a>
Expand Down
3 changes: 1 addition & 2 deletions docs/reference/cli/pixi/shell-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ pixi shell-hook [OPTIONS]
: Max concurrent network requests, default is `50`
- <a id="arg---force-activate" href="#arg---force-activate">`--force-activate`</a>
: Do not use the environment activation cache. (default: true except in experimental mode)
- <a id="arg---no-completion" href="#arg---no-completion">`--no-completion <NO_COMPLETION>`</a>
- <a id="arg---no-completions" href="#arg---no-completions">`--no-completions`</a>
: Do not source the autocompletion scripts from the environment
<br>**options**: `true`, `false`
- <a id="arg---change-ps1" href="#arg---change-ps1">`--change-ps1 <CHANGE_PS1>`</a>
: Do not change the PS1 variable when starting a prompt
<br>**options**: `true`, `false`
Expand Down
3 changes: 1 addition & 2 deletions docs/reference/cli/pixi/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ pixi shell [OPTIONS]
<br>**options**: `true`, `false`
- <a id="arg---force-activate" href="#arg---force-activate">`--force-activate`</a>
: Do not use the environment activation cache. (default: true except in experimental mode)
- <a id="arg---no-completion" href="#arg---no-completion">`--no-completion <NO_COMPLETION>`</a>
- <a id="arg---no-completions" href="#arg---no-completions">`--no-completions`</a>
: Do not source the autocompletion scripts from the environment
<br>**options**: `true`, `false`

## Update Options
- <a id="arg---no-install" href="#arg---no-install">`--no-install`</a>
Expand Down
6 changes: 3 additions & 3 deletions src/cli/shell_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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}
Binary file not shown.
19 changes: 9 additions & 10 deletions tests/data/channels/recipes/completions_channel_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ package:
build:
number: 1
script:
# ZSH completions
- mkdir -p $PREFIX/share/zsh/site-functions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure mkdir -p works on Windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is, if one wants to update our test channels on windows, they will have to run it with bash

- 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
Expand Down
5 changes: 5 additions & 0 deletions tests/integration_python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
5 changes: 0 additions & 5 deletions tests/integration_python/pixi_global/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
39 changes: 39 additions & 0 deletions tests/integration_python/test_shell.py
Original file line number Diff line number Diff line change
@@ -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",
)