2022-09-13 23:08:00 -07:00

35 lines
728 B
Bash

#!/usr/bin/env bash
# Utility functions and helpers for searching
DEFAULT_FD_OPTS=(--hidden --print0 --type f --type l --threads $(nproc))
# Locate options
declare -a LOCATE_OPTS
# Platform-specific options
# macOS doesn't support GNU-style long options
if [[ "$OSTYPE" == "linux-gnu" ]]; then
LOCATE_OPTS=(--all --ignore-case --null)
elif [[ "$OSTYPE" == "darwin"* ]]; then
LOCATE_OPTS=(-0 -i)
fi
# Parameters:
# $1: directory
# $2-n: extra arguments
find_files() {
local directory="$1"
shift
fd "${DEFAULT_FD_OPTS[@]}" "$@" -- . "$directory"
}
# Parameters:
# $1: pattern
# $2-n: extra arguments
locate_files() {
local pattern="$1"
shift
locate "${LOCATE_OPTS[@]}" "$@" -- . "$pattern"
}