pkgxdev / pkgx

run anything
https://pkgx.sh
Apache License 2.0
8.95k stars 1.36k forks source link

`pkgx list-installed` #985

Open felipecrs opened 6 months ago

felipecrs commented 6 months ago

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

However, my dotfiles:

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
dosubot[bot] commented 6 months ago

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 commented 6 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 3 weeks ago

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 commented 2 weeks ago

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.