diff --git a/misc/fzf b/misc/fzf deleted file mode 100644 index d2359fb..0000000 --- a/misc/fzf +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -## FZF helpers - -FZF_OPTS=(--read0 --select-1 --exit-0 --print0) - -run_fzf() { - fzf "${FZF_OPTS[@]}" -- "$@" -} diff --git a/misc/fzf.sh b/misc/fzf.sh new file mode 100644 index 0000000..e7df94e --- /dev/null +++ b/misc/fzf.sh @@ -0,0 +1,7 @@ +## FZF helpers + +FZF_OPTS=('--select-1' '--exit-0') + +run_fzf() { + fzf "${FZF_OPTS[@]}" -- <<< "$@" || return 2 +} diff --git a/misc/search b/misc/search deleted file mode 100644 index 3a1d56b..0000000 --- a/misc/search +++ /dev/null @@ -1,34 +0,0 @@ -#!/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" -} diff --git a/misc/search.sh b/misc/search.sh new file mode 100644 index 0000000..330516a --- /dev/null +++ b/misc/search.sh @@ -0,0 +1,15 @@ +# Utility functions and helpers for searching +DEFAULT_FD_OPTS=('--hidden' '--type' 'f' '--type' 'l' '--threads' "$(nproc)") + +# Parameters: +# $1: directory +# $2-n: extra arguments +find_files() { + if [[ -d "$1" ]]; then + local directory="$1" + shift + fd "${DEFAULT_FD_OPTS[@]}" "$@" -- . "$directory" + else + fd "${DEFAULT_FD_OPTS[@]}" "$@" + fi +}