Adds the ability to select a file by any substring of filename or title
Close #18
This commit is contained in:
parent
a504c212ef
commit
9a269628c4
1 changed files with 18 additions and 2 deletions
20
kb
20
kb
|
@ -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
|
||||||
die "No such file or ID '$filename'"
|
# If we get here, try to find it in the db
|
||||||
exit 1
|
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'"
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue