|
|
|
@ -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 |
|
|
|
|
case "$1" in |
|
|
|
|
edit) editFile "$id"; safeExit ;; |
|
|
|
|
view) viewFile "$id"; safeExit ;; |
|
|
|
|
esac |
|
|
|
|
fi |
|
|
|
|
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 |
|
|
|
|
;; |
|
|
|
|
*) 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" |
|
|
|
|