-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbinfind.bash
More file actions
executable file
·44 lines (33 loc) · 841 Bytes
/
binfind.bash
File metadata and controls
executable file
·44 lines (33 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# ----------------------------------------------------------
# binfind
#
# Finds files in $PATH through keywords.
#
# Usage: binfind[.bash] keyword [keyword2 ...]
#
# Author: konsolebox
# Copyright Free / Public Domain
# May 14, 2021
# ----------------------------------------------------------
[ -n "${BASH_VERSION}" ] || {
echo "This script requires Bash."
exit 1
}
set -f || exit 1
function main {
if [[ $# -eq 0 || $1 == -h || $1 == --help ]]; then
echo "Usage: $0 keyword [keyword2 ...]"
return 1
fi
local args paths IFS=: i=0 __
args=(); paths=()
for __; do
args=("${args[@]}" -iname "*$__*")
done
for __ in ${PATH}; do
[[ -n $__ && ":${paths[*]}:" != *":$__:"* ]] && paths[i++]=$__
done
[[ ${#paths[@]} -gt 0 ]] && find "${paths[@]}" -maxdepth 1 -xtype f "${args[@]}" 2>/dev/null
}
main "$@"