pkgxdev / pkgx

the last thing you’ll install

Home Page:https://pkgx.sh

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`pkgx list-installed`

felipecrs opened this issue · 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

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.

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

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

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

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)