Remove dependency on search.sh library file

This commit is contained in:
Eric Torres 2022-10-01 12:54:50 -07:00
parent d598319760
commit 43445e4a73
4 changed files with 11 additions and 87 deletions

View File

@ -4,13 +4,6 @@
set -e
trap 'exit 1' SIGINT
# Source library
LIBDIR="/usr/share/file-scripts/"
for f in "$LIBDIR"/*.sh; do
source "${f}"
done
# Constants
VERSION=2.0.0
DEFAULT_TEMPLATE_DIR="$HOME/Templates"
@ -101,7 +94,7 @@ if ! [[ -d "$DIR" ]]; then
exit 2
fi
files="$(find_files "$DIR")"
files="$("${fd_opts[@]}" "$DIR")"
selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
# Check if target exists

View File

@ -4,18 +4,12 @@
set -e
trap 'exit 1' SIGINT
# Source library
LIBDIR="/usr/share/file-scripts/"
for f in "$LIBDIR"/*.sh; do
source "${f}"
done
# Constants
VERSION=2.0.0
BOOT_DIR='/boot'
ETC_DIR='/etc'
fd_opts=(--hidden --type file --type symlink --threads "$(nproc)")
# Helper functions
function help() {
@ -75,12 +69,12 @@ while true; do
continue
;;
'-i' | '--no-ignore-vcs')
NO_IGNORE_VCS=1
fd_opts+=(--no-ignore-vcs)
shift
continue
;;
'-I' | '--no-ignore')
NO_IGNORE=1
fd_opts+=(--no-ignore)
shift
continue
;;
@ -114,16 +108,7 @@ elif [[ -z $DIR ]]; then
DIR='.'
fi
# Handle extra options
declare -a extra_opts
if [[ -n $NO_IGNORE ]]; then
extra_opts+=('--no-ignore')
elif [[ -n $NO_IGNORE_VCS ]]; then
extra_opts+=('--no-ignore-vcs')
fi
files="$(find_files $DIR "${extra_opts[@]}")"
files="$(find_files $DIR "${fd_opts[@]}")"
selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
if [[ -w "${selected_file}" ]]; then

View File

@ -4,14 +4,7 @@
set -e
trap 'exit 1' SIGINT
# ========== Source library ==========
LIBDIR="/usr/share/file-scripts/"
for f in "$LIBDIR"/*.sh; do
source "${f}"
done
# ========== Constants ==========
# Constants
VERSION='2.0.0'
RED=$'\e[1;31m'
GREEN=$'\e[1;32m'
@ -112,7 +105,7 @@ while true; do
exit 1
;;
esac
extra_fd_opts+=('--extension' "$EXT")
fd_opts+=('--extension' "$EXT")
shift 2
continue
;;
@ -126,7 +119,7 @@ while true; do
exit 1
;;
esac
extra_fd_opts+=('--extension' "$EXT")
fd_opts+=('--extension' "$EXT")
shift
continue
;;
@ -141,12 +134,12 @@ while true; do
continue
;;
'-i' | '--no-ignore-vcs')
extra_fd_opts+=('--no-ignore-vcs')
fd_opts+=('--no-ignore-vcs')
shift
continue
;;
'-I' | '--no-ignore')
extra_fd_opts+=('--no-ignore')
fd_opts+=('--no-ignore')
shift
continue
;;
@ -181,7 +174,7 @@ fi
declare -a files pattern_results
for pattern in "$@"; do
readarray -d $'\n' -t pattern_results <<< "$(fd "${DEFAULT_FD_OPTS[@]}" "${extra_fd_opts[@]}" "${typeopts[@]}" "$pattern")"
readarray -d $'\n' -t pattern_results <<< "$(fd "${fd_opts[@]}" "${typeopts[@]}" "$pattern")"
files+=("${pattern_results[@]}")
done

View File

@ -1,47 +0,0 @@
# Utility functions and helpers for searching
DEFAULT_FD_OPTS=('--hidden' '--type' 'symlink' '--threads' "$(nproc)")
# Search and return a string with filenames delimited by \n
# Parameters:
# $1: directory
# $2-n: extra arguments
find_files() {
if [[ -d "$1" ]]; then
local directory="$1"
shift
fd "${DEFAULT_FD_OPTS[@]}" --type f "$@" -- . "$directory"
else
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" "$@"
fi
}