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
18
kb
18
kb
|
@ -171,8 +171,11 @@ findFile(){
|
|||
vecho "findFile $*"
|
||||
cd "$dataDir" || return
|
||||
local filename
|
||||
local options
|
||||
local count
|
||||
|
||||
if [ "$#" -eq 1 ] && isInt "$1"; then
|
||||
# if it's an integer, try to find an entry with that id
|
||||
filename="$(echo "SELECT filename
|
||||
FROM items WHERE id = '$(safeSQL "$1")'" |
|
||||
sqlite3 "${sqliteFile}")"
|
||||
|
@ -190,8 +193,21 @@ findFile(){
|
|||
echo "$filename.md"
|
||||
exit 0
|
||||
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'"
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue