bedrocklinux / bedrocklinux-userland

This tracks development for the things such as scripts and (defaults for) config files for Bedrock Linux
https://bedrocklinux.org
GNU General Public License v2.0
602 stars 65 forks source link

Minor feature: Add -a/--all option to `brl which` to list all strata that provide a given binary #212

Open cptpcrd opened 3 years ago

cptpcrd commented 3 years ago

Rationale

Sometimes, when on a Bedrock system, I find myself wondering "which strata do I have X installed in?" What I'd like is a combination of the functionality of brl which -b (which prints the stratum that provides a given binary) and which -a (with GNU coreutils, this prints all the locations in which the given program can be found). I could probably implement this with a quick one-liner using strat -r and which, but to me this feels like a missing feature.

In a nutshell, here's what I'm aiming for:

$ brl which -a xbps-install
void
void-musl

This PR adds a -a/--all option to brl which which does this.

Notes

  1. This is mostly a proof-of-concept. I'm not sure if it will work in all scenarios, and I'm happy to completely rewrite it if necessary to fix bugs or make it follow better practice. I'm not in any rush to get this merged; this is just something I'd kind of like to see eventually that I think other people would find useful too.
  2. There's an argument to be made that this should also work like which_file if any of the arguments contain a /. I can implement that too.
  3. The interface might need changes; right now if multiple arguments are passed it's unclear which strata names correspond to which arguments.
paradigm commented 3 years ago

A number of people have shown interest in something like this over the years (e.g. https://gist.github.com/NICHOLAS85/a01d5f64744e4924ec0a5d5fd112cbc1). I've been hesitant in the past, but at some point I should probably just accept the demand for this outweighs the associated complexity.

In the past, another option I've considered as an alternative to this would be a new brl subcommand which runs the provided arguments for all strata. You could then do something like

$ # list all strata that provide `ls`
$ brl all command -v ls
$ # read all /etc/os-release files
$ brl all cat /etc/os-release

However, in practice, I expect the vast majority of use cases to be equivalent to brl which -a, and in that case, it'd make more sense to group the functionality with brl which.

So I guess we'll go with brl which -a. Given this, some changes I'd like to see from your proof of concept before upstreaming something like this:

cptpcrd commented 3 years ago

@paradigm I've pushed changes that should address most of your concerns, though I have a few of my own. I'll leave comments at relevant points.