Skip to content

Commit

Permalink
new post: bash dotglob
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagowfx committed Dec 9, 2024
1 parent a023a29 commit 8da4901
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions content/posts/2024-12-09-bash-glob-hidden-files-recursively.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "bash: glob hidden files recursively"
date: 2024-12-09T17:53:14-03:00
tags:
- dev
- devops
---

Assume you make a huge change to your git repository, that spawns several file
formats – cpp, java, javascript, python, etc.

In the end you want to revert the javascript changes, for the sake of splitting
your commit into self-contained chunks[^1].

I like the following approach[^2]:

```shell
% git checkout -- **/*.js
```

**Caveat**: It does not include hidden files, or files in hidden directories.
Unless...you set the `dotglob` option:

```shell
% shopt -s dotglob
```

Note that `shopt` works in `bash`, alas not in `zsh`.


[^1]: https://sscce.org/
[^2]: In theory, this is a pre-requisite: `shopt -s globstar`. In practice, it
should be the default behavior.

<!--more-->

0 comments on commit 8da4901

Please sign in to comment.