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