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

Support smart case #209

Open
ptzz opened this issue Aug 15, 2017 · 8 comments · May be fixed by #221
Open

Support smart case #209

ptzz opened this issue Aug 15, 2017 · 8 comments · May be fixed by #221

Comments

@ptzz
Copy link

ptzz commented Aug 15, 2017

Hi,

Would it be good idea to support "smart case"? I.e. do case insensitive matching if the query is all lowercase, and do the current case sensitive matching only if the query contains upper-case? This is similar to what e.g. vim and fzf does by default.

It could be enabled with e.g. _Z_SMART_CASE if there are people who don't like it.

I'll submit a PR if this sounds acceptable.

@rupa
Copy link
Owner

rupa commented Aug 15, 2017

current behaviour is to attempt case sensitive match, if not found, we try case insensitive.

i have considered the approach of case-sensitive-if-there's-an-upper-case-letter. I think the code would be cleaner. haven't done it cause current behaviour seems to work pretty well ...

@ptzz
Copy link
Author

ptzz commented Aug 15, 2017

I have the habit of rarely having upper case in queries. Tend to also not remember case of directories. This throws me in the wrong directory from time to time.

I also have a local script where I pipe the output of z -l to fzf which presents an interactive selector if the top matches have similar score. For this use case I want case insensitive matches included.

For the normal usage of z (jump straight to best match) I agree smart case might be more arguable..

@ericbn
Copy link
Contributor

ericbn commented Nov 8, 2017

I also first though smart-case would make the user experience better. But:

Consider these directories with their respective "frecencies":

3          /tmp/foo/bar
5          /tmp/foo/Bar
8          /tmp/Bar
13         /tmp/bar
21         /tmp

This would be the result of different queries with the two approaches:

query smart-case prefer case sensitive
tm /tmp /tmp
Tm (nothing) /tmp
ba /tmp/bar /tmp/bar
Ba /tmp/Bar /tmp/Bar
fo ba /tmp/foo/Bar /tmp/foo/bar
fo Ba /tmp/foo/Bar /tmp/foo/Bar

In the case of two directories with names with just different cases, the smart-case matching would "hide" the all-lowercase one if it has a lower raking than a mixed-case sibling.

@ptzz
Copy link
Author

ptzz commented Nov 8, 2017

Agree for the normal use case. I was mainly looking for a way to get case insensitive matches included in the output of z -l (list all matches with scores). That would be quite useful in combination with fzf.

@ericbn
Copy link
Contributor

ericbn commented Nov 8, 2017

Maybe z could give users the option to use either case sensitive, insensitive, or smart-case matching, having one of these as default.

@rupa, thoughts?

@ghost
Copy link

ghost commented Nov 8, 2017

This is such a good idea

@ghost
Copy link

ghost commented Nov 8, 2017

@ericbn I think it's rare to have two directories of same name but different case as siblings. Just provide a switch to force case-sensitivity, I'm certain that smart case matching would be the best default.

ericbn added a commit to ericbn/z that referenced this issue Nov 10, 2017
and add parameters to force case insensitive (`-i`) or case sensitive
(`-s`) matching.

There are minor changes from smart-case to the original "prefer case
sensitive" implementation.

Considering these directories with their respective 'frecencies':

     3          /tmp/foo/bar
     5          /tmp/foo/Baz
     8          /tmp/Baz
     13         /tmp/bar
     21         /tmp

These would be the results of different queries with the two approaches,
considering a filesystem that allows directories with same names and
different cases:

| query | smart-case   | prefer case sensitive |
|-------|--------------|-----------------------|
| tm    | /tmp         | /tmp                  |
| Tm    | (nothing)    | /tmp                  |
| ba    | /tmp/bar     | /tmp/bar              |
| Ba    | /tmp/Baz     | /tmp/Baz              |
| fo ba | /tmp/foo/Baz | /tmp/foo/bar          |
| fo Ba | /tmp/foo/Baz | /tmp/foo/Baz          |

Fixes rupa#209
@ericbn ericbn linked a pull request Nov 10, 2017 that will close this issue
@ericbn
Copy link
Contributor

ericbn commented Nov 10, 2017

Created PR #221 changing the default matching strategy to smart case, and adding two new parameters to force case insensitive (-i) or case sensitive (-s) matching. Solution is just 1 LOC bigger than the original implementation. Also updated the man page and the README.

ericbn added a commit to ericbn/z that referenced this issue Nov 10, 2017
and add parameters to force case insensitive (`-i`) or case sensitive
(`-s`) matching.

Also rename `t` variable in main awk script to `now`, as used in the
`--add` awk script, use constant regular expression instead of string,
and add double quotes to shell script variables.

There are minor changes from smart-case to the original "prefer case
sensitive" implementation.

Considering these directories with their respective 'frecencies':

     3          /tmp/foo/bar
     5          /tmp/foo/Baz
     8          /tmp/Baz
     13         /tmp/bar
     21         /tmp

These would be the results of different queries with the two approaches,
considering a filesystem that allows directories with same names and
different cases:

| query | smart-case   | prefer case sensitive |
|-------|--------------|-----------------------|
| tm    | /tmp         | /tmp                  |
| Tm    | (nothing)    | /tmp                  |
| ba    | /tmp/bar     | /tmp/bar              |
| Ba    | /tmp/Baz     | /tmp/Baz              |
| fo ba | /tmp/foo/Baz | /tmp/foo/bar          |
| fo Ba | /tmp/foo/Baz | /tmp/foo/Baz          |

Fixes rupa#209
ericbn added a commit to ericbn/z that referenced this issue Nov 20, 2017
and add parameters to force case insensitive (`-i`) or case sensitive
(`-s`) matching.

Also rename `t` variable in main awk script to `now`, as used in the
`--add` awk script, use constant regular expression instead of string,
and add double quotes to shell script variables.

There are minor changes from smart-case to the original "prefer case
sensitive" implementation.

Considering these directories with their respective 'frecencies':

     3          /tmp/foo/bar
     5          /tmp/foo/Baz
     8          /tmp/Baz
     13         /tmp/bar
     21         /tmp

These would be the results of different queries with the two approaches,
considering a filesystem that allows directories with same names and
different cases:

| query | smart-case   | prefer case sensitive |
|-------|--------------|-----------------------|
| tm    | /tmp         | /tmp                  |
| Tm    | (nothing)    | /tmp                  |
| ba    | /tmp/bar     | /tmp/bar              |
| Ba    | /tmp/Baz     | /tmp/Baz              |
| fo ba | /tmp/foo/Baz | /tmp/foo/bar          |
| fo Ba | /tmp/foo/Baz | /tmp/foo/Baz          |

Fixes rupa#209
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

Successfully merging a pull request may close this issue.

3 participants