From 482ef42403248a492af35ff905a5674160ca8ab9 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Tue, 13 Sep 2022 23:08:00 -0700 Subject: [PATCH] Add bash rewrites of fzf and search modules --- misc/fzf | 8 ++++++++ misc/search | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 misc/fzf create mode 100644 misc/search diff --git a/misc/fzf b/misc/fzf new file mode 100644 index 0000000..d2359fb --- /dev/null +++ b/misc/fzf @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +## FZF helpers + +FZF_OPTS=(--read0 --select-1 --exit-0 --print0) + +run_fzf() { + fzf "${FZF_OPTS[@]}" -- "$@" +} diff --git a/misc/search b/misc/search new file mode 100644 index 0000000..3a1d56b --- /dev/null +++ b/misc/search @@ -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" +}