Adds key combinations for fuzzy search

Currently:
* ctrl-n - new file from query
* ctrl-o - view file
* ctrl-e - edit file
* ctrl-d - delete file

close #11
master
Jonathan Hodgson 4 years ago
parent caab854c09
commit f8d04a304a
  1. 11
      inc/file-management
  2. 46
      kb

@ -109,3 +109,14 @@ deleteFile(){
fi
}
viewFile(){
cd "$dataDir" || return
local id="$1"
local filename
filename="$(findFile "$id")"
bat --color=always --style=full "$filename"
}

46
kb

@ -18,6 +18,7 @@
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
WHITE='\033[1;37m'
NC='\033[0m'
# Provide a variable with the location of this script.
@ -239,16 +240,42 @@ listEntries(){
fuzzySelect(){
cd "$dataDir" || return
local id
local query
local operation
local output
local header="$(echo -e "Type to filter
${YELLOW}ctrl+n $WHITE create new
${YELLOW}ctrl+v $WHITE view selected
${YELLOW}ctrl+e $WHITE edit selected
${YELLOW}ctrl+d $WHITE delete selected
")"
export -f fzfPreview
export dataDir
id="$(listEntries | fzf --header-lines=2 --delimiter=" +" --with-nth=3,5 \
--preview='bash -c "fzfPreview {}"' | awk '{print $1}')"
if [ -n "$id" ]; then
output="$(listEntries |
fzf --header="$header" --header-lines=2 --print-query \
--delimiter=" +" --with-nth=3,5 \
--expect="ctrl-n,ctrl-o,ctrl-e,ctrl-d" \
--preview='bash -c "fzfPreview {}"')"
query="$(echo "$output" | sed -n '1p')"
operation="$(echo "$output" | sed -n '2p')"
id="$(echo "$output" | sed -n '3p' | cut -d' ' -f1)"
case "$operation" in
'ctrl-n') newFile "$query" ;;
'ctrl-o') viewFile "$id" ;;
'ctrl-e') editFile "$id" ;;
'ctrl-d') deleteFile "$id" ;;
'')
case "$1" in
edit) editFile "$id"; safeExit ;;
view) viewFile "$id"; safeExit ;;
esac
fi
;;
*) die "unknown operation '$operation'" ;;
esac
}
fzfPreview(){
@ -271,17 +298,6 @@ fzfPreview(){
fi
}
viewFile(){
cd "$dataDir" || return
local id="$1"
local filename
filename="$(findFile "$id")"
bat --color=always --style=full "$filename"
}
doDeepSearch(){
cd "$dataDir" || return
local query="$1"

Loading…
Cancel
Save