Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/corrupt952/closest
The command that searches the current directory or parent directories for a specific file and returns the closest path
https://github.com/corrupt952/closest
command-line
Last synced: about 2 months ago
JSON representation
The command that searches the current directory or parent directories for a specific file and returns the closest path
- Host: GitHub
- URL: https://github.com/corrupt952/closest
- Owner: corrupt952
- License: mit
- Created: 2022-12-14T03:19:53.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T01:16:08.000Z (2 months ago)
- Last Synced: 2024-10-30T03:53:42.331Z (2 months ago)
- Topics: command-line
- Language: Go
- Homepage:
- Size: 221 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# closest
The command that searches the current directory or parent directories for a specific file and returns the closest path.
## Install
There are two ways to install closest.
- Download the binary from GitHub Releases
- Install via [aqua](https://github.com/aquaproj/aqua)## Usage
```sh
Usage: closest [options] [pattern]
Options:
-a Search all files[default: false]
```To find a closest file the current directory, run the following:
```sh
closest .tflint.hcl
```To find all files from the current directory to root directory, run the following:
```sh
closest -a .envrc
```### Example 1: Find a .tflint.hcl file and run tflint
`tflint` only references `.tflint.hcl` in the current or home directory.
This makes it easy to read per-project settings in the repository root or in the terraform directory in monorepo.The directory structure is as follows, where `staging` is the current directory.
```
/
└── home
└── app
└── terraform
├── .tflint.hcl
└── example-service
├── production
└── staging # <- current directory
```To run `tflint` in combination with `closest`, run the following:
```sh
tflint --config $(closest .tflint.hcl)
```### Example 2: Find all .envrc files up to the root directory
Sometimes when using `direnv`, you want to find where `.envrc` is defined from the root directory to the current directory.
In that case, you can use the `-a` option to display all `.envrc` files up to the root directory, which is useful for troubleshooting.The directory structure is as follows, where `production` is the current directory.
```
/
└── home
└── app
├── .envrc
└── terraform
├── .envrc
└── example-service
├── .envrc
├── production # <- current directory
| └── .envrc
└── staging
```To find all `.envrc` from `production` to the root directory, run the following:
```sh
closest -a .envrc
```Please take care that **the filename must be prefix with `-a`**.
For example, `closest .envrc -a` doesn't work.The output:
```sh
/home/app/terraform/example-service/production/.envrc
/home/app/terraform/example-service/.envrc
/home/app/terraform/.envrc
/home/app/.envrc
```