improved user friendlyness
This commit is contained in:
parent
494a786395
commit
a51a766581
29
README.md
29
README.md
@ -3,10 +3,39 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### 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 ###
|
### Dependencies ###
|
||||||
+ GNU coreutils
|
+ GNU coreutils
|
||||||
+ fzf
|
+ 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 ###
|
### Instalation ###
|
||||||
1. Run `make install` (to compile the last word finder C program and move it into your $PATH)
|
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
|
2. Source `fzfind.rc` from your `.bashrc` or copy its contents directly into it
|
||||||
|
30
fzfind.rc
30
fzfind.rc
@ -4,22 +4,27 @@
|
|||||||
# Description: fzf based file fuzzy finder for Bash
|
# Description: fzf based file fuzzy finder for Bash
|
||||||
# Author: Anon
|
# Author: Anon
|
||||||
# Date: 2024
|
# Date: 2024
|
||||||
# Version: 1.0
|
# Version: 1.1
|
||||||
# Source:
|
# Source:
|
||||||
# mirror 1: http://bis64wqhh3louusbd45iyj76kmn4rzw5ysawyan5bkxwyzihj67c5lid.onion/anon/fzfind
|
# mirror 1: http://bis64wqhh3louusbd45iyj76kmn4rzw5ysawyan5bkxwyzihj67c5lid.onion/anon/fzfind
|
||||||
# mirror 2: https://github.com/agvxov/fzfind
|
# mirror 2: https://github.com/agvxov/fzfind
|
||||||
|
|
||||||
|
|
||||||
[ -z "$CTRLFMETHOD" ] && CTRLFMETHOD="find"
|
[ -z "$FZFINDMETHOD" ] && FZFINDMETHOD="find"
|
||||||
#CTRLCACHE="/home/anon/Desktop/"
|
|
||||||
|
if [ -z "$FZFINDDOBIND" ] || $FZFINDDOBIND; then
|
||||||
|
bind -x '"\C-f": fzfind'
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
function echo_readline_line(){
|
function echo_readline_line(){
|
||||||
|
# Remove non-printable character sequence markers
|
||||||
PS1_CLEANED="${PS1//\\\[/}"
|
PS1_CLEANED="${PS1//\\\[/}"
|
||||||
PS1_CLEANED="${PS1_CLEANED//\\\]/}"
|
PS1_CLEANED="${PS1_CLEANED//\\\]/}"
|
||||||
|
# Insert position marker; Eval PS1
|
||||||
eval "env echo -e \"${PS1_CLEANED}${1:0:${2}}\033[45m \033[0m${1:${2}}\""
|
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
|
# Show command and substitution position
|
||||||
echo_readline_line "${READLINE_LINE}" "${READLINE_POINT}"
|
echo_readline_line "${READLINE_LINE}" "${READLINE_POINT}"
|
||||||
# Get narrowing substring
|
# Get narrowing substring
|
||||||
@ -27,22 +32,19 @@ function ctrl_f(){
|
|||||||
if [ "${READLINE_LINE:$(expr $READLINE_POINT - 1):1}" != " " ]; then
|
if [ "${READLINE_LINE:$(expr $READLINE_POINT - 1):1}" != " " ]; then
|
||||||
OPX=$(lastWord "${READLINE_LINE:0:${READLINE_POINT}}")
|
OPX=$(lastWord "${READLINE_LINE:0:${READLINE_POINT}}")
|
||||||
fi
|
fi
|
||||||
#echo "'$PX'"
|
if [ $FZFINDMETHOD == "find" ]; then
|
||||||
if [ $CTRLFMETHOD == "find" ]; then
|
|
||||||
PX="$OPX"
|
PX="$OPX"
|
||||||
STR=$(eval find ./"$PX/" 2> /dev/null | fzf --multi=1)
|
STR=$(find ./"$PX/" 2> /dev/null | fzf --multi=1)
|
||||||
elif [ $CTRLFMETHOD == "locate" ]; then
|
elif [ $FZFINDMETHOD == "locate" ]; then
|
||||||
PX="$(realpath $PWD/$OPX)"
|
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
|
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
|
fi
|
||||||
# Remove ${PX}
|
# Remove narrowing substring from result to prevent duplication
|
||||||
STR="${STR/${PX}/}"
|
STR="${STR/${PX}/}"
|
||||||
# Write $READLINE_LINE
|
# Write $READLINE_LINE
|
||||||
[ -z "$STR" ] && return
|
[ -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_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
|
READLINE_POINT=$(expr ${READLINE_POINT} + ${#OPX} + ${#STR} + 2) # +2 for the '"'s
|
||||||
}
|
}
|
||||||
|
|
||||||
bind -x '"\C-f": ctrl_f'
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user