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

sort output from pixi global list #1394

Closed
dhirschfeld opened this issue May 15, 2024 · 2 comments · Fixed by #1458
Closed

sort output from pixi global list #1394

dhirschfeld opened this issue May 15, 2024 · 2 comments · Fixed by #1458
Labels
✨ enhancement Feature request

Comments

@dhirschfeld
Copy link
Contributor

Problem description

The output of pixi global list is unsorted making it more difficult to find the package you're interested in.

e.g.

❯ pixi global list
Global install location: ~/.pixi
├── ghostscript 10.03.0
|   └─ exec: pdf2dsc, ps2pdf14, lprsetup, gsdj, dvipdf, eps2eps, ps2epsi, ps2pdf13, gslj, gs, gsdj500, pfbtopfa, printafm, ps2ascii, gsnd, pf2afm, ps2pdf12, pdf2ps, ps2pdfwr, ps2ps2, unix-lpr, gsbj, pphs, ps2pdf, gslp, ps2ps
├── starship 1.18.2
|   └─ exec: starship
├── ripgrep 14.1.0
|   └─ exec: rg
├── skopeo 1.15.0
|   └─ exec: skopeo
├── fd-find 10.1.0
|   └─ exec: fd
├── uv 0.1.42
|   └─ exec: uv
├── kubernetes-helm 3.14.4
|   └─ exec: helm
├── awscli 2.15.47
|   └─ exec: aws_completer, aws.cmd, aws_zsh_completer, aws, aws_bash_completer
├── gh 2.49.1
|   └─ exec: gh
├── toolong 1.5.0
|   └─ exec: tl
├── eza 0.18.15
|   └─ exec: eza
├── go 1.22.3
|   └─ exec: go, gofmt
├── databricks-cli 0.219.0
|   └─ exec: databricks
├── kubernetes-client 1.30.0
|   └─ exec: kubectl, kubectl-convert
├── pgcli 4.0.1
|   └─ exec: pgcli
├── micromamba 1.5.8
|   └─ exec: micromamba
├── git-delta 0.17.0
|   └─ exec: delta
└── bat 0.24.0
    └─ exec: bat
@dhirschfeld dhirschfeld added the ✨ enhancement Feature request label May 15, 2024
@dhirschfeld
Copy link
Contributor Author

This looks to be the offending function:

pixi/src/cli/global/list.rs

Lines 136 to 158 in fad669b

/// List all globally installed packages
///
/// # Returns
///
/// A list of all globally installed packages represented as [`PackageName`]s
pub(super) async fn list_global_packages() -> miette::Result<Vec<PackageName>> {
let mut packages = vec![];
let bin_env_dir =
bin_env_dir().ok_or(miette::miette!("Could not determine global envs directory"))?;
let Ok(mut dir_contents) = tokio::fs::read_dir(bin_env_dir).await else {
return Ok(vec![]);
};
while let Some(entry) = dir_contents.next_entry().await.into_diagnostic()? {
if entry.file_type().await.into_diagnostic()?.is_dir() {
if let Ok(name) = PackageName::from_str(entry.file_name().to_string_lossy().as_ref()) {
packages.push(name);
}
}
}
Ok(packages)
}

@dhirschfeld
Copy link
Contributor Author

I've never written any Rust code, but ChatGPT suggests the below may work?

diff --git a/src/cli/global/list.rs b/src/cli/global/list.rs
index f690552..a2e294e 100644
--- a/src/cli/global/list.rs
+++ b/src/cli/global/list.rs
@@ -154,5 +154,6 @@ pub(super) async fn list_global_packages() -> miette::Result<Vec<PackageName>> {
         }
     }
 
+    packages.sort();
     Ok(packages)
 }

...I guess, assuming PackageNames are sortable 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement Feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant