Open cptpcrd opened 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:
/bedrock/share/common-code
for helper functions like list_strata
rather than writing your own.$PATH
and files, since there's obvious ways to interpret it for both.-a
/--all
flag could be something that can be combine with other flags.
brl which -ab <binary>
it'll find strata that provide the given binarybrl which -af file
it'll find all strata that provide the given file path if /bedrock/strata/<stratum>
is prefixedbrl which -a <arg>
it should auto-detect binary vs file vs something it doesn't know how to all-ify and error out$PATH
yourself. Other strategies to consider:
strat "${strat}" /bedrock/libexec/busybox sh -c "command -v \"$cmd\""
strat "${strat}" /bedrock/libexec/busybox which "$cmd"
/bedrock/share/{bash,zsh,fish}
)@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.
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) andwhich -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 usingstrat -r
andwhich
, but to me this feels like a missing feature.In a nutshell, here's what I'm aiming for:
This PR adds a
-a
/--all
option tobrl which
which does this.Notes
which_file
if any of the arguments contain a/
. I can implement that too.