|
|
@ -171,8 +171,11 @@ findFile(){ |
|
|
|
vecho "findFile $*" |
|
|
|
vecho "findFile $*" |
|
|
|
cd "$dataDir" || return |
|
|
|
cd "$dataDir" || return |
|
|
|
local filename |
|
|
|
local filename |
|
|
|
|
|
|
|
local options |
|
|
|
|
|
|
|
local count |
|
|
|
|
|
|
|
|
|
|
|
if [ "$#" -eq 1 ] && isInt "$1"; then |
|
|
|
if [ "$#" -eq 1 ] && isInt "$1"; then |
|
|
|
|
|
|
|
# if it's an integer, try to find an entry with that id |
|
|
|
filename="$(echo "SELECT filename |
|
|
|
filename="$(echo "SELECT filename |
|
|
|
FROM items WHERE id = '$(safeSQL "$1")'" | |
|
|
|
FROM items WHERE id = '$(safeSQL "$1")'" | |
|
|
|
sqlite3 "${sqliteFile}")" |
|
|
|
sqlite3 "${sqliteFile}")" |
|
|
@ -190,8 +193,21 @@ findFile(){ |
|
|
|
echo "$filename.md" |
|
|
|
echo "$filename.md" |
|
|
|
exit 0 |
|
|
|
exit 0 |
|
|
|
else |
|
|
|
else |
|
|
|
|
|
|
|
# If we get here, try to find it in the db |
|
|
|
|
|
|
|
options="$( echo "SELECT filename from items |
|
|
|
|
|
|
|
WHERE title LIKE '%$(safeSQL $filename)%' |
|
|
|
|
|
|
|
UNION SELECT filename from items |
|
|
|
|
|
|
|
WHERE filename LIKE '%$(safeSQL $filename)%'" | |
|
|
|
|
|
|
|
sqlite3 "${sqliteFile}" )" |
|
|
|
|
|
|
|
count="$(echo "$options" | wc -l)" |
|
|
|
|
|
|
|
if [ "$count" -eq 0 ]; then |
|
|
|
die "No such file or ID '$filename'" |
|
|
|
die "No such file or ID '$filename'" |
|
|
|
exit 1 |
|
|
|
elif [ "$count" -eq 1 ]; then |
|
|
|
|
|
|
|
echo -n "$options" |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
die "Not a unique substring\n\n${NC}Could have been any of: |
|
|
|
|
|
|
|
$options" |
|
|
|
|
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
fi |
|
|
|
} |
|
|
|
} |
|
|
|