Remove dependency on search.sh library file
This commit is contained in:
		@@ -4,13 +4,6 @@
 | 
				
			|||||||
set -e
 | 
					set -e
 | 
				
			||||||
trap 'exit 1' SIGINT
 | 
					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
 | 
					VERSION=2.0.0
 | 
				
			||||||
DEFAULT_TEMPLATE_DIR="$HOME/Templates"
 | 
					DEFAULT_TEMPLATE_DIR="$HOME/Templates"
 | 
				
			||||||
@@ -101,7 +94,7 @@ if ! [[ -d "$DIR" ]]; then
 | 
				
			|||||||
	exit 2
 | 
						exit 2
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
files="$(find_files "$DIR")"
 | 
					files="$("${fd_opts[@]}" "$DIR")"
 | 
				
			||||||
selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
 | 
					selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Check if target exists
 | 
					# Check if target exists
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								bin/fedit
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								bin/fedit
									
									
									
									
									
								
							@@ -4,18 +4,12 @@
 | 
				
			|||||||
set -e
 | 
					set -e
 | 
				
			||||||
trap 'exit 1' SIGINT
 | 
					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
 | 
					VERSION=2.0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BOOT_DIR='/boot'
 | 
					BOOT_DIR='/boot'
 | 
				
			||||||
ETC_DIR='/etc'
 | 
					ETC_DIR='/etc'
 | 
				
			||||||
 | 
					fd_opts=(--hidden --type file --type symlink --threads "$(nproc)")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Helper functions
 | 
					# Helper functions
 | 
				
			||||||
function help() {
 | 
					function help() {
 | 
				
			||||||
@@ -75,12 +69,12 @@ while true; do
 | 
				
			|||||||
		continue
 | 
							continue
 | 
				
			||||||
		;;
 | 
							;;
 | 
				
			||||||
	'-i' | '--no-ignore-vcs')
 | 
						'-i' | '--no-ignore-vcs')
 | 
				
			||||||
		NO_IGNORE_VCS=1
 | 
					        fd_opts+=(--no-ignore-vcs)
 | 
				
			||||||
		shift
 | 
							shift
 | 
				
			||||||
		continue
 | 
							continue
 | 
				
			||||||
		;;
 | 
							;;
 | 
				
			||||||
	'-I' | '--no-ignore')
 | 
						'-I' | '--no-ignore')
 | 
				
			||||||
		NO_IGNORE=1
 | 
					        fd_opts+=(--no-ignore)
 | 
				
			||||||
		shift
 | 
							shift
 | 
				
			||||||
		continue
 | 
							continue
 | 
				
			||||||
		;;
 | 
							;;
 | 
				
			||||||
@@ -114,16 +108,7 @@ elif [[ -z $DIR ]]; then
 | 
				
			|||||||
	DIR='.'
 | 
						DIR='.'
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Handle extra options
 | 
					files="$(find_files $DIR "${fd_opts[@]}")"
 | 
				
			||||||
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[@]}")"
 | 
					 | 
				
			||||||
selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
 | 
					selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ -w "${selected_file}" ]]; then
 | 
					if [[ -w "${selected_file}" ]]; then
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										19
									
								
								bin/quickdel
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								bin/quickdel
									
									
									
									
									
								
							@@ -4,14 +4,7 @@
 | 
				
			|||||||
set -e
 | 
					set -e
 | 
				
			||||||
trap 'exit 1' SIGINT
 | 
					trap 'exit 1' SIGINT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# ========== Source library ==========
 | 
					# Constants
 | 
				
			||||||
LIBDIR="/usr/share/file-scripts/"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for f in "$LIBDIR"/*.sh; do
 | 
					 | 
				
			||||||
    source "${f}"
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# ========== Constants ==========
 | 
					 | 
				
			||||||
VERSION='2.0.0'
 | 
					VERSION='2.0.0'
 | 
				
			||||||
RED=$'\e[1;31m'
 | 
					RED=$'\e[1;31m'
 | 
				
			||||||
GREEN=$'\e[1;32m'
 | 
					GREEN=$'\e[1;32m'
 | 
				
			||||||
@@ -112,7 +105,7 @@ while true; do
 | 
				
			|||||||
                    exit 1
 | 
					                    exit 1
 | 
				
			||||||
                    ;;
 | 
					                    ;;
 | 
				
			||||||
            esac
 | 
					            esac
 | 
				
			||||||
            extra_fd_opts+=('--extension' "$EXT")
 | 
					            fd_opts+=('--extension' "$EXT")
 | 
				
			||||||
            shift 2
 | 
					            shift 2
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
@@ -126,7 +119,7 @@ while true; do
 | 
				
			|||||||
                    exit 1
 | 
					                    exit 1
 | 
				
			||||||
                    ;;
 | 
					                    ;;
 | 
				
			||||||
            esac
 | 
					            esac
 | 
				
			||||||
            extra_fd_opts+=('--extension' "$EXT")
 | 
					            fd_opts+=('--extension' "$EXT")
 | 
				
			||||||
            shift
 | 
					            shift
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
@@ -141,12 +134,12 @@ while true; do
 | 
				
			|||||||
            continue
 | 
					            continue
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        '-i' | '--no-ignore-vcs')
 | 
					        '-i' | '--no-ignore-vcs')
 | 
				
			||||||
            extra_fd_opts+=('--no-ignore-vcs')
 | 
					            fd_opts+=('--no-ignore-vcs')
 | 
				
			||||||
            shift
 | 
					            shift
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        '-I' | '--no-ignore')
 | 
					        '-I' | '--no-ignore')
 | 
				
			||||||
            extra_fd_opts+=('--no-ignore')
 | 
					            fd_opts+=('--no-ignore')
 | 
				
			||||||
            shift
 | 
					            shift
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
@@ -181,7 +174,7 @@ fi
 | 
				
			|||||||
declare -a files pattern_results
 | 
					declare -a files pattern_results
 | 
				
			||||||
 | 
					
 | 
				
			||||||
for pattern in "$@"; do
 | 
					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[@]}")
 | 
					    files+=("${pattern_results[@]}")
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user