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

pkgx list-installed #985

Open
felipecrs opened this issue Mar 9, 2024 · 7 comments
Open

pkgx list-installed #985

felipecrs opened this issue Mar 9, 2024 · 7 comments

Comments

@felipecrs
Copy link
Contributor

I'm aiming to fully replace Homebrew with pkgx in my dotfiles.

However, my dotfiles:

  • Automatically installs missing tools
  • Automatically uninstalls some tools I no longer want

And in order to perform that with pkgx, I need to fetch a list of pkgs already installed. Something like:

$ pkgx list-installed
openjdk.org@11
nodejs.org
yarnpkg.com

# a tool I want to have installed
$ if ! pkgx list-installed | grep -w openjdk.org@11; then pkgx install openjdk.org@11; fi

# a tool I do not want to have
$ if pkgx list-installed | grep -w asciinema.org; then pkgx uninstall asciinema.org; fi
Copy link

dosubot bot commented Mar 9, 2024

It's great to see that you're aiming to fully replace Homebrew with pkgx in your dotfiles! Your plan to automatically install missing tools and uninstall unwanted ones with pkgx sounds like a solid approach. If you're able to implement the functionality to fetch a list of installed packages and create a script like the one you've outlined, it would be a valuable contribution to the pkgx community. Keep up the good work, and feel free to create a pull request if you'd like to share your solution with the community!

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@jhheider
Copy link
Contributor

That seems like something that could (and probably should) easily be added to https://github.com/pkgxdev/mash. In its simplest form, it's really something like grep -l pkgx ~/.local/bin/*.

@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 27, 2024

I ended up with:

$ grep -rIhoP 'exec pkgx \+\K[^ ]+' "${HOME}/.local/bin" | sort -u
bun.sh
crates.io/bat
crates.io/hyperfine
deno.land
github.com/hadolint/hadolint
github.com/helmfile/helmfile
jfrog.com/jfrog-cli
nodejs.org
opendev.org/git-review
rust-lang.org/cargo
werf.io

Or the uncompressed variant:

grep --recursive --binary-files=without-match --no-filename --only-matching --perl-regexp 'exec pkgx \+\K[^ ]+' "${HOME}/.local/bin" | sort --unique

@felipecrs
Copy link
Contributor Author

felipecrs commented Apr 27, 2024

Here's an one-liner to uninstall all existing pkgx installed apps:

$ grep -rIhoP 'exec pkgx \+\K[^ ]+' "${HOME}/.local/bin" | sort -u | xargs -r pkgx uninstall
uninstalled: deno.land
uninstalled: maven.apache.org
uninstalled: openjdk.org

@felipecrs
Copy link
Contributor Author

And just in case others may find it useful, I built logic in my dotfiles to automate management of pkgx installed stuff:

  1. Check if a pkgx package is installed or not (here)

  2. Refresh/recreate/update all stubs (here)

  3. Updating packages for installed stubs without installing them in case they have not been executed yet (here)

@mxcl
Copy link
Member

mxcl commented Sep 6, 2024

Yeah we're leaning towards mash scripts for now here. I think for pkgx v2 the install command will become its own package built on pkgx tech, as we intend for dev.

@iyefrat
Copy link

iyefrat commented Sep 14, 2024

I think that having something like this (also as a mash script) would be a significant usability improvement. There is already https://github.com/pkgxdev/mash/blob/main/scripts/pantry-inventory.ts, a few more similar scripts that are documented on the website would make the project much easier to use as a brew replacement.

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

No branches or pull requests

4 participants