unison/unison-src/transcripts/globbing.md

68 lines
1.6 KiB
Markdown
Raw Normal View History

# Globbing
## Overview
This allows quickly selecting terms, types, and namespaces for any "bulk" commands.
* Currently supports up to one wildcard PER SEGMENT; Each segment can have its own wildcard if you really want and it'll still be performant. E.g. `.base.?.to?`
* Can have a prefix, suffix or infix wildcard! E.g. `to?` or `?List` or `to?With!`
* I went with `?` instead of `*` for the wildcard symbol since `?` isn't currently a valid symbol name. This may cause some confusion since it differs from bash globbing though; so if anyone has thoughts/concerns about how to better handle this I'd love to hear them.
* Commands can select which targets they want globs to expand to; e.g. `cd` should only glob for namespace, `view` should only glob to terms & types.
## Demo
2021-10-19 03:43:04 +03:00
Add some definitions which we can match over:
2021-10-19 03:52:01 +03:00
```unison:hide
2021-10-19 03:43:04 +03:00
convertToThing = 1
convertFromThing = 2
otherTerm = 3
2021-10-19 03:43:04 +03:00
-- Nested definitions
nested.toList = 4
nested.toMap = 5
othernest.toList = 6
othernest.toMap = 7
```
2021-10-19 03:43:04 +03:00
```ucm:hide
.> add
2021-10-19 03:43:04 +03:00
```
Globbing as a prefix, infix, or suffix wildcard.
```ucm
.> view convert?
.> view convert?Thing
.> view ?Thing
```
Globbing can occur in any name segment.
```ucm
.> view ?.toList
.> view nested.to?
```
You may have up to one glob per name segment.
```ucm
.> view ?.to?
```
Globbing only expands to the appropriate argument type.
E.g. `view` should not see glob expansions for namespaces.
This should expand to only the otherTerm.
2021-10-19 03:43:04 +03:00
```ucm
2021-10-19 03:43:04 +03:00
.> view other?
```
2021-10-19 03:52:01 +03:00
Globbing should work from within a namespace with both absolute and relative patterns.
```ucm
.nested> view .othernest.to?
.nested> view to?
```