pkgx icon indicating copy to clipboard operation
pkgx copied to clipboard

`pkgx list-installed`

Open felipecrs opened this issue 1 year ago • 7 comments

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

felipecrs avatar Mar 09 '24 21:03 felipecrs

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.

dosubot[bot] avatar Mar 09 '24 21:03 dosubot[bot]

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/*.

jhheider avatar Mar 10 '24 07:03 jhheider

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 avatar Apr 27 '24 16:04 felipecrs

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 avatar Apr 27 '24 16:04 felipecrs

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)

felipecrs avatar Apr 27 '24 21:04 felipecrs

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.

mxcl avatar Sep 06 '24 15:09 mxcl