mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Find All Tool Version Files Containing Postgres as a Unix TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1606 TILs and counting..._
|
||||
_1607 TILs and counting..._
|
||||
|
||||
See some of the other learning resources I work on:
|
||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||
@@ -1539,6 +1539,7 @@ If you've learned something here, support my efforts writing daily TILs by
|
||||
- [File Type Info With File](unix/file-type-info-with-file.md)
|
||||
- [Find All Files Matching A Name With fd](unix/find-all-files-matching-a-name-with-fd.md)
|
||||
- [Find All Files With A Specific Extension With fd](unix/find-all-files-with-a-specific-extension-with-fd.md)
|
||||
- [Find All Tool Version Files Containing Postgres](unix/find-all-tool-version-files-containing-postgres.md)
|
||||
- [Find Any Dotfiles That Modify Path Env Var](unix/find-any-dotfiles-that-modify-path-env-var.md)
|
||||
- [Find A File Installed By Brew](unix/find-a-file-installed-by-brew.md)
|
||||
- [Find Duplicate Lines In A File](unix/find-duplicate-lines-in-a-file.md)
|
||||
|
||||
38
unix/find-all-tool-version-files-containing-postgres.md
Normal file
38
unix/find-all-tool-version-files-containing-postgres.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Find All Tool Version Files Containing Postgres
|
||||
|
||||
I've been using [`asdf`](https://asdf-vm.com/) for many years now which means I
|
||||
have projects and directories all over my machine with `.tool-versions` files.
|
||||
Many of them specify Ruby and Node versions. Some of them also include
|
||||
PostgreSQL versions. I used to use `asdf` to manage Postgres versions, but no
|
||||
longer do that for new or active projects.
|
||||
|
||||
I want to find all the places that a `.tool-versions` file declares `postgres`
|
||||
as a tool. That way I can begin to clean up the left behind artifacts of
|
||||
asdf-managed Postgres.
|
||||
|
||||
By combining [`fd`](https://github.com/sharkdp/fd) (a better `find`) and
|
||||
[`rg`](https://github.com/BurntSushi/ripgrep) (a better `grep`), I'm able to
|
||||
quickly track down the list of places.
|
||||
|
||||
```bash
|
||||
$ fd --hidden .tool-versions ~/ | xargs rg postgres
|
||||
|
||||
/Users/jbranchaud/.local/state/nvim/undo/%Users%jbranchaud%.tool-versions: binary file matches (found "\0" byte around offset 9)
|
||||
|
||||
/Users/jbranchaud/code/fake-data/.tool-versions
|
||||
2:postgres 13.1
|
||||
|
||||
/Users/jbranchaud/code/thirty_days/thirty_days_server/.tool-versions
|
||||
1:postgres 13.1
|
||||
|
||||
/Users/jbranchaud/code/visualmode/.tool-versions
|
||||
1:postgres 11.11
|
||||
```
|
||||
|
||||
That first instance is a binary file as part of `nvim`'s undo history which I
|
||||
can ignore. The other three are good results.
|
||||
|
||||
I tell the `fd` command to not exclude hidden files as it looks for all
|
||||
occurrences of `.tool-versions` recursively from my home (`~/`) directory. I
|
||||
then pipe that list of files to `xargs` which makes those filenames arguments
|
||||
to the `rg postgres` command.
|
||||
Reference in New Issue
Block a user