Add bash rewrites of fzf and search modules

This commit is contained in:
Eric Torres 2022-09-13 23:08:00 -07:00
parent 84cb0a73d9
commit 482ef42403
2 changed files with 42 additions and 0 deletions

8
misc/fzf Normal file
View File

@ -0,0 +1,8 @@
#!/usr/bin/env bash
## FZF helpers
FZF_OPTS=(--read0 --select-1 --exit-0 --print0)
run_fzf() {
fzf "${FZF_OPTS[@]}" -- "$@"
}

34
misc/search Normal file
View File

@ -0,0 +1,34 @@
#!/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"
}