Skip to content

Add pattern matching for add command - #675

Closed
tagniam wants to merge 4 commits into
cmus:masterfrom
tagniam:add-glob-matching
Closed

tagniam wants to merge 4 commits into
cmus:masterfrom
tagniam:add-glob-matching

Conversation

@tagniam

@tagniam tagniam commented Apr 18, 2017 •

Copy link
Copy Markdown
Contributor

Resolves #659 with glob patterns. Some examples:

  • :add ~/Music/*.mp3
  • :add ~/Music/*/*.flac
  • :add ~/Music/*[Rr]adiohead*
  • :add ~/Music/?.wav

Calling :add on a file that contains glob metacharacters []?* in its filename must now be escaped:

  • :add ~/Music/[2004] Sung Tongs → :add ~/Music/\[2004\] Sung Tongs

Tab completion for :add has been modified to escape tab-expanded filenames.

tagniam added 4 commits April 18, 2017 16:41
All glob metacharacters "[]*?" in a filename must now be escaped when
using add.
The TABEXP_GLOB flag is used to limit glob tab completion to the add
command only.
@mahkoh

mahkoh commented Apr 22, 2017

Copy link
Copy Markdown
Member

I'll have to think about this a bit more.

@mahkoh

mahkoh commented Apr 23, 2017

Copy link
Copy Markdown
Member

Implementation aside, I think there are several issues here:

  1. If you add a path with globs, you get no feedback if the glob does not match any files. This is better:
~$ ls *.aou
zsh: no matches found: *.aou
  1. Expansion of the glob blocks the UI thread. This is a big no-no if the glob matches many files.

  2. You have to remember to escape certain characters when using add but not when using other commands that use paths. This is too irregular. Globbing should work for all such commands with reasonable semantics. There also needs to be a way to disable globbing ad-hoc the way shells do it with quotation marks. This also needs to work with tab expansion.

Therefore I'll close this PR for now.

@mahkoh mahkoh closed this Apr 23, 2017
@tagniam

tagniam commented Apr 25, 2017

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @mahkoh. I'll address your points:

  1. Straightforward fix: return FILE_TYPE_INVALID when glob() doesn't return 0.
  2. If you mean the fact that glob() is MT-unsafe, isn't this unavoidable? Correct me if I'm wrong, but even tab expansion calls readdir() which blocks the UI thread in a directory with many files.
  3. Good point. I agree, the way cmus handles paths in command mode should be modified to mimic how the shell handles paths for consistency's sake.

I'll take another shot at this when I have the time.

@mahkoh

mahkoh commented Apr 25, 2017

Copy link
Copy Markdown
Member

Straightforward fix: return FILE_TYPE_INVALID when glob() doesn't return 0.

glob should not be called in the UI thread.

If you mean the fact that glob() is MT-unsafe

No.

Correct me if I'm wrong, but even tab expansion calls readdir() which blocks the UI thread in a directory with many files.

That is so but a completely different issue. When the user requests a tab expansion there is no choice but to wait for the data and the user gets immediate feedback. There is no reason for add to block the UI thread.

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 this pull request may close these issues.

2 participants