@ -178,15 +178,26 @@ findFile(){
fi
fi
}
}
fileInDB(){
local ids
ids="$(echo "SELECT id FROM items WHERE filename = '$(safeSQL "$1")'" |
sqlite3 "${sqliteFile}")"
[ -n "$ids" ] && return 0
return 1
}
externalgit(){
externalgit(){
cd "$dataDir" || return
cd "$dataDir" || return
git "$@"
git "$@"
}
}
# This function will add and commit a file after it has been edited
# This function will add and commit a file after it has been edited
# If 2 arguments are given, it assumes a rename has taken place.
# The first should be the old file (like mv)
gitChange(){
gitChange(){
cd "$dataDir" || return
cd "$dataDir" || return
local filename="$1"
local filename="$1"
local newFilename="$2"
if [ "$dogit" -gt 0 ]; then
if [ "$dogit" -gt 0 ]; then
if [ -f "$filename" ]; then
if [ -f "$filename" ]; then
if ! git diff --exit-code "$filename" > /dev/null 2>&1; then
if ! git diff --exit-code "$filename" > /dev/null 2>&1; then
@ -198,6 +209,16 @@ gitChange(){
git add "$filename"
git add "$filename"
git commit -m "KB auto-commit: New: $filename"
git commit -m "KB auto-commit: New: $filename"
fi
fi
else
# If the file name doesn't exist, we have probably moved it
if [ -n "$newFilename" ] && [ -f "$newFilename" ]; then
git add "$filename" "$newFilename"
git commit -m "KB auto-commit: move: $filename -> $newFilename"
else
# if we get here, the file has been deleted
git add "$filename"
git commit -m "KB auto-commit: delete: $filename"
fi
fi
fi
fi
fi
}
}
@ -293,7 +314,7 @@ mainScript() {
if [ "${args[0]}" != "init" ]; then
if [ "${args[0]}" != "init" ]; then
cd "$dataDir" || return
cd "$dataDir" || return
# Check to see if datadir is a git repo
# Check to see if datadir is a git repo
if git rev-parse 2> /dev/null; then
if ! git rev-parse 2> /dev/null; then
# If not, ensure we don't run git commands
# If not, ensure we don't run git commands
dogit=0
dogit=0
fi
fi
@ -307,6 +328,7 @@ mainScript() {
list-tags) listTags "${args[@]:1}"; safeExit ;;
list-tags) listTags "${args[@]:1}"; safeExit ;;
view) viewFile "${args[@]:1}"; safeExit ;;
view) viewFile "${args[@]:1}"; safeExit ;;
fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;;
fuzzy) fuzzySelect "${args[@]:1}"; safeExit ;;
update) updateFileChange "${args[@]:1}"; safeExit ;;
deepsearch) deepSearch "${args[@]:1}"; safeExit ;;
deepsearch) deepSearch "${args[@]:1}"; safeExit ;;
del|delete) deleteFile "${args[@]:1}"; safeExit ;;
del|delete) deleteFile "${args[@]:1}"; safeExit ;;
git) externalgit "${args[@]:1}"; safeExit ;;
git) externalgit "${args[@]:1}"; safeExit ;;
@ -348,6 +370,8 @@ usage() {
--noheader Don't include the header
--noheader Don't include the header
list-tags Lists tags with the number of times its used
list-tags Lists tags with the number of times its used
--noheader Don't include the header
--noheader Don't include the header
update <file> [<file>] Updates the database and git repo of a changed file
If 2 files are given, it assumes a move
view View a file
view View a file
fuzzy [command] Fuzzy select a file
fuzzy [command] Fuzzy select a file
command is what to do with the selected file
command is what to do with the selected file