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
This commit is contained in:
parent
caab854c09
commit
f8d04a304a
2 changed files with 46 additions and 19 deletions
|
@ -109,3 +109,14 @@ deleteFile(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewFile(){
|
||||||
|
cd "$dataDir" || return
|
||||||
|
|
||||||
|
local id="$1"
|
||||||
|
local filename
|
||||||
|
|
||||||
|
filename="$(findFile "$id")"
|
||||||
|
|
||||||
|
bat --color=always --style=full "$filename"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
54
kb
54
kb
|
@ -18,6 +18,7 @@
|
||||||
RED='\033[1;31m'
|
RED='\033[1;31m'
|
||||||
GREEN='\033[1;32m'
|
GREEN='\033[1;32m'
|
||||||
YELLOW='\033[1;33m'
|
YELLOW='\033[1;33m'
|
||||||
|
WHITE='\033[1;37m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
# Provide a variable with the location of this script.
|
# Provide a variable with the location of this script.
|
||||||
|
@ -239,16 +240,42 @@ listEntries(){
|
||||||
fuzzySelect(){
|
fuzzySelect(){
|
||||||
cd "$dataDir" || return
|
cd "$dataDir" || return
|
||||||
local id
|
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 -f fzfPreview
|
||||||
export dataDir
|
export dataDir
|
||||||
id="$(listEntries | fzf --header-lines=2 --delimiter=" +" --with-nth=3,5 \
|
output="$(listEntries |
|
||||||
--preview='bash -c "fzfPreview {}"' | awk '{print $1}')"
|
fzf --header="$header" --header-lines=2 --print-query \
|
||||||
if [ -n "$id" ]; then
|
--delimiter=" +" --with-nth=3,5 \
|
||||||
case "$1" in
|
--expect="ctrl-n,ctrl-o,ctrl-e,ctrl-d" \
|
||||||
edit) editFile "$id"; safeExit ;;
|
--preview='bash -c "fzfPreview {}"')"
|
||||||
view) viewFile "$id"; safeExit ;;
|
|
||||||
esac
|
query="$(echo "$output" | sed -n '1p')"
|
||||||
fi
|
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
|
||||||
|
;;
|
||||||
|
*) die "unknown operation '$operation'" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fzfPreview(){
|
fzfPreview(){
|
||||||
|
@ -271,17 +298,6 @@ fzfPreview(){
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
viewFile(){
|
|
||||||
cd "$dataDir" || return
|
|
||||||
|
|
||||||
local id="$1"
|
|
||||||
local filename
|
|
||||||
|
|
||||||
filename="$(findFile "$id")"
|
|
||||||
|
|
||||||
bat --color=always --style=full "$filename"
|
|
||||||
}
|
|
||||||
|
|
||||||
doDeepSearch(){
|
doDeepSearch(){
|
||||||
cd "$dataDir" || return
|
cd "$dataDir" || return
|
||||||
local query="$1"
|
local query="$1"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue