Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add completion for pixi run --environment for nushell #1636

Merged
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
17 changes: 8 additions & 9 deletions src/cli/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,17 @@ $2::task"#;
fn replace_nushell_completion(script: &str) -> Cow<str> {
// Adds tab completion to the pixi run command.
// NOTE THIS IS FORMATTED BY HAND
let pattern = r#"
export extern "pixi run" \[
...task: string"#;
let pattern = r#"(#.*\n export extern "pixi run".*\n.*...task: string)([^\]]*--environment\(-e\): string)"#;
let replacement = r#"
def "nu-complete pixi run" [] {
let result = (^pixi task list --machine-readable | complete)
if $$result.exit_code == 0 {
$$result.stderr | split row " "
}
^pixi info --json | from json | get environments_info | get tasks | flatten | uniq
}

export extern "pixi run" [
...task: string@"nu-complete pixi run""#;
def "nu-complete pixi run environment" [] {
^pixi info --json | from json | get environments_info | get name
}

${1}@"nu-complete pixi run"${2}@"nu-complete pixi run environment""#;

let re = Regex::new(pattern).unwrap();
re.replace(script, replacement)
Expand Down Expand Up @@ -244,6 +242,7 @@ _arguments "${_arguments_options[@]}" \
pub fn test_nushell_completion() {
// NOTE THIS IS FORMATTED BY HAND!
let script = r#"
# Runs task in project
export extern "pixi run" [
...task: string # The pixi task or a task shell command you want to run in the project's environment, which can be an executable in the environment's PATH
--manifest-path: string # The path to 'pixi.toml' or 'pyproject.toml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
source: src/cli/completion.rs
expression: result
---

def "nu-complete pixi run" [] {
let result = (^pixi task list --machine-readable | complete)
if $result.exit_code == 0 {
$result.stderr | split row " "
}
^pixi info --json | from json | get environments_info | get tasks | flatten | uniq
}

def "nu-complete pixi run environment" [] {
^pixi info --json | from json | get environments_info | get name
}

# Runs task in project
export extern "pixi run" [
...task: string@"nu-complete pixi run" # The pixi task or a task shell command you want to run in the project's environment, which can be an executable in the environment's PATH
--manifest-path: string # The path to 'pixi.toml' or 'pyproject.toml'
--frozen # Install the environment as defined in the lockfile, doesn't update lockfile if it isn't up-to-date with the manifest file
--locked # Check if lockfile is up-to-date before installing the environment, aborts when lockfile isn't up-to-date with the manifest file
--environment(-e): string # The environment to run the task in
--environment(-e): string@"nu-complete pixi run environment" # The environment to run the task in
baszalmstra marked this conversation as resolved.
Show resolved Hide resolved
--tls-no-verify # Do not verify the TLS certificate of the server
--auth-file: string # Path to the file containing the authentication token
--pypi-keyring-provider: string@"nu-complete pixi run pypi_keyring_provider" # Specifies if we want to use uv keyring provider
Expand Down
Loading