Repository navigation
Closed as duplicate
Labels
A:file-systemRelated to commands and core nushell behavior around the file systemA:globBehavior around file-system globbing with regular commands or `glob`. See also A:quoting/expansioncategory:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedhelp wantedstatus: Extra attention is needed
Description
Describe the bug
ls | glob '<[!.]*/>[!.]*'
will recursively list files but ignore dot-files/dirs
but
▶ watch . -v --glob=<[!.]*/>[!.]* { |op, path, new_path| $"($op) ($path) ($new_path)"}
Absolute glob path: "/home/cole/code/nixcfg/<[!.]*/>[!.]*"
Now watching files at "/home/cole/code/nixcfg". Press ctrl+c to abort.
NoticeWrite("/home/cole/code/nixcfg/foo")
Write("/home/cole/code/nixcfg/foo")
Matches glob: false
Create("/home/cole/code/nixcfg/.git/index")
Matches glob: false
just results in no matches
How to reproduce
Try to use watch without triggering on .git changes.
Expected behavior
There to be some way to achieve this with the built in glob feature
Screenshots
No response
Configuration
| key | value |
| ------------------ | ----------------------------------------------- |
| version | 0.70.0 |
| branch | |
| commit_hash | |
| build_os | linux-x86_64 |
| build_target | x86_64-unknown-linux-gnu |
| rust_version | rustc 1.64.0 |
| cargo_version | cargo 1.64.0 |
| pkg_version | 0.70.0 |
| build_time | 1980-01-01 00:00:00 +00:00 |
| build_rust_channel | release |
| features | database, dataframe, default, trash, which, zip |
| installed_plugins | |
Additional context
No response
Reacted by Ramon
Metadata
Metadata
Assignees
Labels
A:file-systemRelated to commands and core nushell behavior around the file systemA:globBehavior around file-system globbing with regular commands or `glob`. See also A:quoting/expansioncategory:inconsistent-behaviorBehavior between different commands or types inconsistent/unexpectedhelp wantedstatus: Extra attention is needed
Activity
colemickens commentedon Nov 6, 2022
Oh I guess
globis its own commandrgwood commentedon Nov 6, 2022
Hmm. I wrote
watchso this is probably my fault. That’s a tricky glob pattern!I’ll take a look tomorrow.
sholderbach commentedon Nov 6, 2022
I think this points to a larger issue we have: we have our own glob implementation in
nu-globused in the filesystem commands (lsetc. and in this casewatch) and also have theglobcommand for which we import the globbing behavior from thewaxcrate.I think in the longer term we should only have one source of truth for the globbing.
colemickens commentedon Nov 6, 2022
globbing doesn't really respect the ordering the same way bash does either.
"foo/{z,y,x}" will match "foo/x" "foo/y" "foo/z"
which in my case, break things and means I have to use a different construct
fdncred commentedon Nov 6, 2022
Agreed @sholderbach. The reason I added
waxand theglobcommand for globbing was because we had to strip some functionality fromnu-globto get it to work right withls.rgwood commentedon Dec 10, 2022
So I guess the conclusion here is that
watchshould switch towaxfor globbing?fdncred commentedon Dec 10, 2022
@rgwood another option may be to allow
watchto take aninputfrom theglobcommand. e.g.Not sure if that is a better or worse design. Just throwing things out for consideration. You usually have a good feel about that stuff.
rgwood commentedon Dec 10, 2022
Hmm, that's a clever idea but I don't think it would work for
watch.glob ... | watch ...would gather a list of files and then tellwatchto watch only those files. Butwatchneeds to be able to report on files that are created afterwatchis launched.melMass commentedon Dec 10, 2022
What about making watch support multiple arguments? for instance a subcommand
watch filesrgwood commentedon Dec 10, 2022
@melMass
I think this is the same as what you can do right now with
watch . --glob=**/*.rs { |i| print $i }. Am I missing something?Is
<command that returns a list>returning a list of glob patterns? That could work but it feels a bit too complicated to me.melMass commentedon Dec 10, 2022
The idea would be that the input is
X argsplus aclosure, in the first example glob would get expanded prior which I think is how nu works, and the command in the second sample could return astringor alist<string>(of relative or absolute paths to files)So it could be also as simple as
rgwood commentedon Dec 10, 2022
^ we discussed this on Discord: https://discord.com/channels/601130461678272522/615329862395101194/1051209969439101010
I think we came to the conclusion that the current
watch <path> --glob=<glob> <closure>design is OK (butwatchshould handle more sophisticated glob patterns).instantepiphany commentedon Nov 26, 2023
I've just encountered this. I want to run
cargo run --bin serverto build a specific binary in a rust workspace whenever the files inserverorlib(local dependency) change.I want this to happen for
.rsand.tomlfiles.There is another workspace folder,
clientwhich should not be watched as it is not a dependency ofserver.So with the current glob limitations in
watch, I:.rsor.tomlshould be watched (ie with**/*.{rs,toml})serverorlibshould be watched (ie with**/{server,lib}/**)globcan via--exclude).If
watchwas updated to usewax, or ifwatchsupported multiple globs, this would be possible (viawax"alternatives" as in my examples, or by supplying multiple globs like**/server/*.rs,**/server/Cargo.toml,**/lib/*.rs,**/lib/Cargo.toml).I suppose I could do another layer of filtering inside the closure, but that feels inefficient and awkward.
fdncred commentedon Nov 26, 2023
The
globcommand also doesn't accept multiple separate globs on the command line. Although, I'd like it to. Seems like we could do it with theanyfunctionality of wax but I could never get it integrated properly. Theglobcommand does offer a completely different syntax though. It is sometimes helpful to be able to do things likeglob **/*.{rs,toml} --depth 2.instantepiphany commentedon Nov 26, 2023
Thats the alternative (
alternatives, ha) that I mentioned in my comment.If
waxwas used as the library fornu-globthen I could have usedwatch . --glob **/{server,lib}/**/*.{rs,toml} {|| cargo run --bin server}and that would have worked fine.Also unfortunate is that this glob matches 0 files, but doesn't error. I was scratching my head for quite a while before I realised that
globbehaves differently tonu-globused bywatch- my first response was to put that glob pattern intoglob <pattern>so was confused when it produced exactly the files I wanted it to 😄fdncred commentedon Nov 27, 2023
nu-globwas meant to be a more simplistic globbing crate, whereasglobusingwaxwas meant to be more "advanced". The two aren't necessarily compatible with each other.I'm not sure if anyone is against switching glob crates in the watch command. What may be better is removing the globbing from
watchand passing it in so one could doglob some_complicated_globbing | watch --param1 --param2. Then it would be composable and more nushell-y. If you wantednu-globfunctionality you could dols some_nu_glob | get name | watch --param1 --parm2.instantepiphany commentedon Dec 10, 2023
This makes sense - but for someone new to
nu, it is a fair assumption that "globbing" innuis consistent. Silently using different globbing logic will absolutely confuse users.I thought about this when I encountered the problem.
I think the trick with passing the glob paths in to
watchas piped input is that if the command thatwatchruns generates files that would and should match the filter, they won't get picked up unless the user restarts watch.Whereas if
watchis passed an argument, it can reexecute the glob after each time the requested command is invoked bywatch, and get a new, current list of paths.fdncred commentedon Dec 10, 2023
makes sense
kronberger-droid commentedon Nov 13, 2026
The difference comes from
globandwatchusing two different glob implementations.The dc-glob backend replaces both, and with
nu --experimental-options [dc-glob]watch --glob '**/*.{rs,toml}'andglobalready agree.That work is tracked in #18101, so closing this in favour of it.