improved user friendlyness

This commit is contained in:
anon 2024-02-09 17:06:22 +01:00
parent 494a786395
commit a51a766581
2 changed files with 45 additions and 14 deletions

View File

@ -3,10 +3,39 @@
![](showoff.gif)
### What it does ###
fzfind will:
+ use fzf to prompt for the file desired by the user
+ show the line typed so far with the point of insertion marked
+ take the path typed so far into account
+ quote the result
+ use either `find` or `locate`, ensuring usability on slower drives
### Configuration ###
**$FZFINDMETHOD**
Specifies what utility to use for file searches.
Possible values:
+ find
+ locate
**$FZFINDDOBIND**
Bind fzfind to `ctrl+f`.
The default behaviour is to do so.
If this is not the desired,
set it to `false` in your bashrc before evaluating fzfind.
### Dependencies ###
+ GNU coreutils
+ fzf
NOTE: fzfind uses the extra-minimalistic `lastword` executable
to determine what portion of the line typed so far is a
directory prefix.
This information is for narrowing down the results
### Instalation ###
1. Run `make install` (to compile the last word finder C program and move it into your $PATH)
2. Source `fzfind.rc` from your `.bashrc` or copy its contents directly into it

View File

@ -4,22 +4,27 @@
# Description: fzf based file fuzzy finder for Bash
# Author: Anon
# Date: 2024
# Version: 1.0
# Version: 1.1
# Source:
# mirror 1: http://bis64wqhh3louusbd45iyj76kmn4rzw5ysawyan5bkxwyzihj67c5lid.onion/anon/fzfind
# mirror 2: https://github.com/agvxov/fzfind
[ -z "$CTRLFMETHOD" ] && CTRLFMETHOD="find"
#CTRLCACHE="/home/anon/Desktop/"
[ -z "$FZFINDMETHOD" ] && FZFINDMETHOD="find"
if [ -z "$FZFINDDOBIND" ] || $FZFINDDOBIND; then
bind -x '"\C-f": fzfind'
fi
function echo_readline_line(){
# Remove non-printable character sequence markers
PS1_CLEANED="${PS1//\\\[/}"
PS1_CLEANED="${PS1_CLEANED//\\\]/}"
# Insert position marker; Eval PS1
eval "env echo -e \"${PS1_CLEANED}${1:0:${2}}\033[45m \033[0m${1:${2}}\""
#env echo -e "${PS1}${1:0:${2}}\033[45m \033[0m${1:${2}}"
}
function ctrl_f(){
function fzfind(){
# Show command and substitution position
echo_readline_line "${READLINE_LINE}" "${READLINE_POINT}"
# Get narrowing substring
@ -27,22 +32,19 @@ function ctrl_f(){
if [ "${READLINE_LINE:$(expr $READLINE_POINT - 1):1}" != " " ]; then
OPX=$(lastWord "${READLINE_LINE:0:${READLINE_POINT}}")
fi
#echo "'$PX'"
if [ $CTRLFMETHOD == "find" ]; then
if [ $FZFINDMETHOD == "find" ]; then
PX="$OPX"
STR=$(eval find ./"$PX/" 2> /dev/null | fzf --multi=1)
elif [ $CTRLFMETHOD == "locate" ]; then
STR=$(find ./"$PX/" 2> /dev/null | fzf --multi=1)
elif [ $FZFINDMETHOD == "locate" ]; then
PX="$(realpath $PWD/$OPX)"
STR=$(eval locate --existing --regex $PX/'.*' 2> /dev/null | fzf --multi=1)
STR=$(locate --existing --regex $PX/'.*' 2> /dev/null | fzf --multi=1)
else
echo -e "\033[31;1mNonsensical \033[34;1m\${CTRLFMETHOD} \033[31;1mvalue.\033[0m"
echo -e "\033[31;1mNonsensical \033[34;1m\${FZFINDMETHOD} \033[31;1mvalue.\033[0m"
fi
# Remove ${PX}
# Remove narrowing substring from result to prevent duplication
STR="${STR/${PX}/}"
# Write $READLINE_LINE
[ -z "$STR" ] && return
READLINE_LINE="${READLINE_LINE:0:$(expr ${READLINE_POINT} - ${#OPX})}\"${OPX}${STR}\"${READLINE_LINE:${READLINE_POINT}}" # start_til_px + '"' + px + str '"' + rest
READLINE_POINT=$(expr ${READLINE_POINT} + ${#OPX} + ${#STR} + 2) # +2 for the '"'s
}
bind -x '"\C-f": ctrl_f'