Adds the ability to index folder and re-populate the db

Misc:
The arguments are now sorted alphabetically in the main funciton

close #4
master
Jonathan Hodgson 4 years ago
parent 5863d5a58f
commit d70f5398a3
  1. 2
      inc/file-management
  2. 5
      inc/init
  3. 34
      kb

@ -44,8 +44,6 @@ updateFileChange(){
[ ! -e "$filename" ] && die "No such file $1" [ ! -e "$filename" ] && die "No such file $1"
title="$(getYamlTitle "$filename")" title="$(getYamlTitle "$filename")"
newFilename="$(escapeFilename "$title.md")" newFilename="$(escapeFilename "$title.md")"
echo "Filename: '$filename'
new filename: '$newFilename'"
if [ "$filename" = "$newFilename" ]; then if [ "$filename" = "$newFilename" ]; then
# The title hasn't changed # The title hasn't changed
# check if the file is in the DB # check if the file is in the DB

@ -20,6 +20,10 @@ initKnowledgeBase(){
git -C "$dataDir" add .gitignore > "$output" git -C "$dataDir" add .gitignore > "$output"
git -C "$dataDir" commit -m "Knowledge base initialised" > output git -C "$dataDir" commit -m "Knowledge base initialised" > output
fi fi
initDB
}
initDB(){
vecho "Creating Database" vecho "Creating Database"
echo 'CREATE TABLE items echo 'CREATE TABLE items
(id integer primary key, filename text, title text, type text); (id integer primary key, filename text, title text, type text);
@ -30,4 +34,3 @@ initKnowledgeBase(){
sqlite3 "${sqliteFile}" sqlite3 "${sqliteFile}"
necho -e "${GREEN}Initialised Knowledge base${NC}" necho -e "${GREEN}Initialised Knowledge base${NC}"
} }

34
kb

@ -243,6 +243,21 @@ listEntries(){
sqlite3 --column $header "${sqliteFile}" sqlite3 --column $header "${sqliteFile}"
} }
indexFolder(){
vecho "indexFolder $*"
local olddogit="$dogit"
dogit=0
initDB
find "$dataDir" -name "*.md" | while read file; do
file="${file##*/}"
updateFileChange "$file"
done
dogit="$olddogit"
}
mainScript() { mainScript() {
############## Begin Script Here ################### ############## Begin Script Here ###################
#################################################### ####################################################
@ -255,18 +270,20 @@ mainScript() {
fi fi
fi fi
case "${args[0]}" in case "${args[0]}" in
init) initKnowledgeBase; safeExit ;; deepsearch) deepSearch "${args[@]:1}"; safeExit ;;
makedb) makedb; safeExit ;; del|delete) deleteFile "${args[@]:1}"; safeExit ;;
new) newFile "${args[@]:1}"; safeExit ;;
edit) editFile "${args[@]:1}"; safeExit ;; edit) editFile "${args[@]:1}"; safeExit ;;
fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;;
git) externalgit "${args[@]:1}"; safeExit ;;
index) indexFolder "${args[@]:1}"; safeExit ;;
init) initKnowledgeBase; safeExit ;;
list) listEntries "${args[@]:1}"; safeExit ;; list) listEntries "${args[@]:1}"; safeExit ;;
list-tags) listTags "${args[@]:1}"; safeExit ;; list-tags) listTags "${args[@]:1}"; safeExit ;;
view) viewFile "${args[@]:1}"; safeExit ;; makedb) makedb; safeExit ;;
fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;; new) newFile "${args[@]:1}"; safeExit ;;
update) updateFileChange "${args[@]:1}"; safeExit ;; update) updateFileChange "${args[@]:1}"; safeExit ;;
deepsearch) deepSearch "${args[@]:1}"; safeExit ;; view) viewFile "${args[@]:1}"; safeExit ;;
del|delete) deleteFile "${args[@]:1}"; safeExit ;;
git) externalgit "${args[@]:1}"; safeExit ;;
*) usage >&2; safeExit ;; *) usage >&2; safeExit ;;
esac esac
@ -315,6 +332,7 @@ usage() {
edit or view edit or view
git [options] Run arbitary git commands on the kb repository git [options] Run arbitary git commands on the kb repository
del [title] Delete a file del [title] Delete a file
index Indexes the folder (usful after a clone etc)
" "
} }

Loading…
Cancel
Save