Skip to content

Commit

Permalink
Add -a/--all option to brl which
Browse files Browse the repository at this point in the history
Prints the list of strata in which the given binary can be found.
  • Loading branch information
cptpcrd authored Nov 13, 2020
1 parent 5c63fdf commit 60821a2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/slash-bedrock/libexec/brl-which
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Options:
${color_sub}<none> ${color_norm}guess type from identifier
${color_cmd}-c${color_norm}, ${color_cmd}--current ${color_norm}which ${color_term}stratum${color_norm} provides current process
${color_cmd}-b${color_norm}, ${color_cmd}--bin ${color_norm}which ${color_term}stratum${color_norm} provides a given binary in \$PATH
${color_cmd}-a${color_norm}, ${color_cmd}--all ${color_norm}which ${color_term}strata${color_norm} provide a given binary in \$PATH
${color_cmd}-f${color_norm}, ${color_cmd}--file ${color_norm}which ${color_term}stratum${color_norm} provides a given file path
${color_cmd}-p${color_norm}, ${color_cmd}--pid ${color_norm}which ${color_term}stratum${color_norm} provides a given process ID
${color_cmd}-x${color_norm}, ${color_cmd}--xwindow ${color_norm}which ${color_term}stratum${color_norm} provides a given X11 window (requires xprop)
Expand Down Expand Up @@ -67,6 +68,32 @@ which_bin() {
done
}

which_bin_all() (
IFS=':'
while [ -n "${1:-}" ]; do
for strat_dir in /bedrock/strata/*; do
if [ ! -d "${strat_dir}" ] || [ -h "${strat_dir}" ]; then
continue
fi

for dir in ${PATH}; do
case "${dir}" in
''|'.'|/bedrock/*)
continue
;;
esac

if [ -e "${strat_dir}/${dir}/${1}" ]; then
which_file "${strat_dir}/${dir}/${1}"
break
fi
done
done

shift
done
)

which_file() {
while [ -n "${1:-}" ]; do
if ! [ -e "${1}" ]; then
Expand Down Expand Up @@ -146,6 +173,10 @@ case "${1:-}" in
shift
which_bin "${@}"
;;
"-a" | "--all")
shift
which_bin_all "${@}"
;;
"-f" | "--file")
shift
which_file "${@}"
Expand Down

0 comments on commit 60821a2

Please sign in to comment.