lackadaisical/what

32 lines
647 B
Bash
Executable file

#!/bin/sh
# 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
pwd=/
all_bins=$(cd / && echo $PATH | sed 's/[:]/ /g' | xargs ls -A | grep -v ":" | sort | uniq)
output=$(printf '%s\n' "-n" $all_bins | grep -i "$1")
echo "$output"