Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 49 additions & 35 deletions cheatsheet.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,67 @@
# Globbing cheatsheet
# Globbing Cheatsheet

WIP
> WIP

## Basic globbing
## Basic Globbing

| **Character** | **Description** |
| --- | --- |
| `*` | Matches any character zero or more times, except for `/` |
| `**` | Matches any character zero or more times, including `/` |
| `?` | Matches any character except for `/` one time |
| `[abc]` | Matches any characters inside the brackets. For example, `[abc]` would match the characters `a`, `b` or `c`, and nothing else. |
| **Character** | **Regex Equivalent** | **Description** |
| --- | --- | --- |
| `*` | `[^/]*` | Matches any character zero or more times, except for `/`. |
| `**` | `.*` | Matches any character zero or more times, including `/`. |
| `?` | `[^/]` | Matches any character except for `/` one time. |
| `[abc]` | `[abc]` | Matches any characters inside the brackets.[^1] |

[^1]: For example, [abc] would match the characters `a`, `b` or `c`, and nothing else.

Notes:

- `*` typically does not match dotfiles (file names starting with a `.`) unless explicitly enabled by the user [via options](#common-options)
- `*` typically does not match dotfiles (file names starting with a `.`),
unless explicitly enabled by the user [via options](#globbing-options)
- `?` also typically does not match the leading dot
- More than two stars in a glob path segment are typically interpreted as _a single star_ (e.g. `/***/` is the same as `/*/`)
- More than two stars in a glob path segment are typically interpreted as _a single star_
- e.g. `/***/` is the same as `/*/`

## Extended Globbing

## Extended globbing
### Brace Expansion

### brace expansion
> TODO

TODO
### `extglob`

### extglob
In addition to basic globs (`*`, `*`, `?`, `[...]`),
`extglob` adds (almost) the full expressive power of standard RegEx,
allowing the use of patterns like `foo/!(a\|b)*`

| **pattern** | **regex equivalent** | **description** |
| --- | --- | --- |
| `?(pattern-list)` | `(...|...)?` | Matches zero or one occurrence of the given patterns |
| `*(pattern-list)` | `(...|...)*` | Matches zero or more occurrences of the given patterns |
| `+(pattern-list)` | `(...|...)+` | Matches one or more occurrences of the given patterns |
| `@(pattern-list)` | `(...|...)` <sup>*</sup> | Matches one of the given patterns |
| `!(pattern-list)` | N/A | Matches anything except one of the given patterns |
| **Pattern** | **Regex Equivalent** | **Description** |
| --- | --- | --- |
| `?(pattern-list)` | `(...\|...)?` | Matches zero or one occurrence of the given patterns |
| `*(pattern-list)` | `(...\|...)*` | Matches zero or more occurrences of the given patterns |
| `+(pattern-list)` | `(...\|...)+` | Matches one or more occurrences of the given patterns |
| `@(pattern-list)` | `(...\|...)` | Matches one of the given patterns |
| `!(pattern-list)` | N/A | Matches anything except one of the given patterns |

### POSIX character classes
### POSIX Character Classes

TODO
> TODO

## Globbing options
## Globbing Options

Options that are commonly available on various globbing implementations.

| **Option name** | **Description** |
| --- | --- |
| `extglob` | Enable extended globs. In addition to the traditional globs (using wildcards: `*`, `*`, `?` and `[...]`), extended globs add (almost) the expressive power of regular expressions, allowing the use of patterns like `foo/!(a|b)*` |
| `dotglob` | Allows files beginning with `.` to be included in matches. This option is automatically enabled if the glob pattern begins with a dot. Aliases: `dot` (supported by: [minimatch][], [micromatch][]) |
| `failglob` | report an error when no matches are found |
| `globignore` allows you to specify patterns a glob should not match Aliases: `ignore` (supported by: [minimatch][], [micromatch][]) |
| `globstar` | recursively match directory paths (enabled by default in [minimatch][] and [micromatch][], but not in [bash][]) |
| `nocaseglob` | perform case-insensitive pathname expansion |
| `nocasematch` | perform case-insensitive matching. Aliases: `nocase` (supported by: [minimatch][], [micromatch][]) |
| `nullglob` | when enabled, the pattern itself will be returned when no matches are found. Aliases: `nonull` (supported by: [minimatch][], [micromatch][]) |
| **Option Name** | **Description** | **Alias** | **Supported By** |
| --- | --- | --- | --- |
| `extglob` | Enables [extended globbing](#extended-globbing). | | |
| `dotglob` | Allows files beginning with `.` to be included in matches. | `dot` | [minimatch], [micromatch]<br>(Automatically enabled if glob pattern begins with a dot) |
| `failglob` | Reports an error if no matches are found. | | |
| `globignore` | Allows you to specify patterns a glob should *not* match. | `ignore` | [minimatch], [micromatch] |
| `globstar` | Recursively matches directory paths. | | [minimatch], [micromatch]<br>(On by default in minimatch and micromatch, but not in [bash]) |
| `nocaseglob` | Performs case-insensitive pathname expansion. | | |
| `nocasematch` | Performs case-insensitive matching. | `nocase` | [minimatch], [micromatch] |
| `nullglob` | Returns the glob pattern itself if no matches are found. | `nonull` | [minimatch], [micromatch] |

[minimatch]: https://github.com/isaacs/minimatch
[micromatch]: https://github.com/micromatch/micromatch
[bash]: https://www.gnu.org/software/bash/

<!-- cSpell:ignore extglob dotglob failglob globignore nocaseglob nocasematch nullglob nocase nonull -->