#!/usr/bin/env bash
# Where is the binary?
# Usage: what [<keyword>]
# Returns:
#   With no parameters, all visible binaries in PATH.
#   With parameter, all binaries that match the pattern
#   given. Accepts default grep patterns, case insensitive
#
# Examples:
# $ what zs.*
#  pzstd
#  zsh
#  zstd
#
# $ what ftp
#  ftppass
#  sftp
#  vsftpd
#
# $ what ftp | xargs which
#  /usr/bin/ftppass
#  /usr/bin/sftp
#  /usr/sbin/vsftpd
#

LD_INTERNAL=1
. $(dirname $(realpath $0))/daisy.source

all_bins=$(compgen -c | sort -u)

if [[ -n "$1" ]]; then
  echo "$all_bins" | grep -i "$1"
else
  echo "$all_bins"
fi
