diff --git a/bin/cptemplate b/bin/cptemplate index df72b3e..78d078f 100755 --- a/bin/cptemplate +++ b/bin/cptemplate @@ -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 diff --git a/bin/fedit b/bin/fedit index 2046452..9819638 100755 --- a/bin/fedit +++ b/bin/fedit @@ -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 diff --git a/bin/quickdel b/bin/quickdel index 77b3e04..7be7231 100755 --- a/bin/quickdel +++ b/bin/quickdel @@ -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 diff --git a/lib/search.sh b/lib/search.sh deleted file mode 100644 index 90a5dbd..0000000 --- a/lib/search.sh +++ /dev/null @@ -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 -}