Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--in option doesn't distinguish between subdir and partial path match #54

Open
henrebotha opened this issue Jun 11, 2019 · 4 comments
Open

Comments

@henrebotha
Copy link
Contributor

henrebotha commented Jun 11, 2019

If I call histdb --in while in ~/dev/vim, it yields results from ~/dev/vim as well as ~/dev/vimrc. I assume the logic that is meant to handle the "current dir or below" logic is using some kind of simple substring matching, therefore seeing ~/dev/vimrc as including the substring ~/dev/vim and returning a match.

In fact, it seems that's exactly what's happening:

dirwhere="${dirwhere}${dirwhere:+ or }places.dir like '$(sql_escape $dir)%'"

@larkery
Copy link
Owner

larkery commented Jul 26, 2019

You are quite right - I'll have a look at the pattern handling in sqlite and see whether this can be improved.

@JordanP-Dev
Copy link

I think the following will work, right? It will match the exact directory or the directory name followed by a slash, then any other characters.

diff --git a/sqlite-history.zsh b/sqlite-history.zsh
index 32c3990..87b3ff4 100644
--- a/sqlite-history.zsh
+++ b/sqlite-history.zsh
@@ -305,7 +305,7 @@ histdb () {
         local dir=""
         for dir ($indirs); do
             dir="${${${dir#--in}#=}:-$PWD}"
-            dirwhere="${dirwhere}${dirwhere:+ or }places.dir like '$(sql_escape $dir)%'"
+            dirwhere="${dirwhere}${dirwhere:+ or }places.dir = '$(sql_escape $dir)%' or places.dir like '$(sql_escape $dir/)%'"
         done
         for dir ($atdirs); do
             dir="${${${dir#--at}#=}:-$PWD}"

@larkery
Copy link
Owner

larkery commented Apr 26, 2022

This looks correct, thanks - I will apply this change.

@JordanP-Dev
Copy link

Oops, there is a mistake there. I accidentally left the percent sign on the first comparison. It should be:

diff --git a/sqlite-history.zsh b/sqlite-history.zsh
index 32c3990..87b3ff4 100644
--- a/sqlite-history.zsh
+++ b/sqlite-history.zsh
@@ -305,7 +305,7 @@ histdb () {
         local dir=""
         for dir ($indirs); do
             dir="${${${dir#--in}#=}:-$PWD}"
-            dirwhere="${dirwhere}${dirwhere:+ or }places.dir like '$(sql_escape $dir)%'"
+            dirwhere="${dirwhere}${dirwhere:+ or }places.dir = '$(sql_escape $dir)' or places.dir like '$(sql_escape $dir/)%'"
         done
         for dir ($atdirs); do
             dir="${${${dir#--at}#=}:-$PWD}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants