2022-09-28 21:26:39 -07:00
|
|
|
# Utility functions and helpers for searching
|
2022-09-30 23:50:14 -07:00
|
|
|
DEFAULT_FD_OPTS=('--hidden' '--type' 'symlink' '--threads' "$(nproc)")
|
2022-09-28 21:26:39 -07:00
|
|
|
|
|
|
|
# Search and return a string with filenames delimited by \n
|
|
|
|
# Parameters:
|
|
|
|
# $1: directory
|
|
|
|
# $2-n: extra arguments
|
|
|
|
find_files() {
|
2022-09-30 21:36:24 -07:00
|
|
|
if [[ -d "$1" ]]; then
|
|
|
|
local directory="$1"
|
|
|
|
shift
|
2022-09-30 23:50:14 -07:00
|
|
|
fd "${DEFAULT_FD_OPTS[@]}" --type f "$@" -- . "$directory"
|
2022-09-30 21:36:24 -07:00
|
|
|
else
|
2022-09-30 23:50:14 -07:00
|
|
|
fd "${DEFAULT_FD_OPTS[@]}" --type f "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Search and return a string with filenames delimited by \n
|
|
|
|
# Parameters:
|
|
|
|
# $1: directory
|
|
|
|
# $2-n: extra arguments
|
|
|
|
find_directories() {
|
|
|
|
if [[ -d "$1" ]]; then
|
|
|
|
local directory="$1"
|
|
|
|
shift
|
|
|
|
fd "${DEFAULT_FD_OPTS[@]}" --type d "$@" -- . "$directory"
|
|
|
|
else
|
|
|
|
fd "${DEFAULT_FD_OPTS[@]}" --type d "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Search all files and directories, determine what type of files to search
|
|
|
|
# Parameters:
|
|
|
|
# $1: filetype (specific to fd's --type flag)
|
|
|
|
# $2: directory
|
|
|
|
# $3-n: extra arguments
|
|
|
|
find_specific() {
|
|
|
|
local type_opt="$1"
|
|
|
|
shift
|
|
|
|
if [[ -d "$1" ]]; then
|
|
|
|
local directory="$1"
|
|
|
|
shift
|
|
|
|
fd "${DEFAULT_FD_OPTS[@]}" --type "$type_opt" "$@" -- . "$directory"
|
|
|
|
else
|
|
|
|
fd "${DEFAULT_FD_OPTS[@]}" --type "$type_opt" "$@"
|
2022-09-30 21:36:24 -07:00
|
|
|
fi
|
2022-09-28 21:26:39 -07:00
|
|
|
}
|