{"id":19732985,"url":"https://github.com/corrupt952/closest","last_synced_at":"2026-03-07T02:34:50.193Z","repository":{"id":70311884,"uuid":"578010343","full_name":"corrupt952/closest","owner":"corrupt952","description":"The command that searches the current directory or parent directories for a specific file and returns the closest path","archived":false,"fork":false,"pushed_at":"2026-03-05T09:12:11.000Z","size":2211,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-05T13:43:32.286Z","etag":null,"topics":["command-line"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/corrupt952.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-14T03:19:53.000Z","updated_at":"2026-03-02T12:48:23.000Z","dependencies_parsed_at":"2023-12-26T01:28:32.598Z","dependency_job_id":"39e5583e-e270-4d7c-8da5-47f10f02bdd3","html_url":"https://github.com/corrupt952/closest","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/corrupt952/closest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrupt952%2Fclosest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrupt952%2Fclosest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrupt952%2Fclosest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrupt952%2Fclosest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/corrupt952","download_url":"https://codeload.github.com/corrupt952/closest/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corrupt952%2Fclosest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30206078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"online","status_checked_at":"2026-03-07T02:00:06.765Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line"],"created_at":"2024-11-12T00:28:44.051Z","updated_at":"2026-03-07T02:34:50.162Z","avatar_url":"https://github.com/corrupt952.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# closest\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/corrupt952/closest)](https://goreportcard.com/report/github.com/corrupt952/closest)\n[![Test](https://github.com/corrupt952/closest/actions/workflows/test.yml/badge.svg)](https://github.com/corrupt952/closest/actions/workflows/test.yml)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nA lightweight command-line tool that searches the current directory or parent directories for specific files and returns the closest path.\n\n## Why closest?\n\nMany tools only look for configuration files in the current directory or in the home directory, but not in parent directories. This makes it difficult to use these tools in monorepos or nested project structures.\n\n`closest` solves this problem by finding the nearest matching file in the directory hierarchy, making it easy to:\n\n- Use tools with configuration files in parent directories\n- Find configuration files in monorepo structures\n- Locate files without knowing their exact location\n- Troubleshoot configuration inheritance\n\n## Installation\n\n### Download binary\n\nDownload the latest binary from [GitHub Releases](https://github.com/corrupt952/closest/releases).\n\n```sh\n# Example for Linux (amd64)\ncurl -L https://github.com/corrupt952/closest/releases/latest/download/closest_linux_amd64.tar.gz | tar xz\nsudo mv closest /usr/local/bin/\n```\n\n### Install via aqua\n\nIf you use [aqua](https://github.com/aquaproj/aqua), you can install `closest` with:\n\n```sh\naqua g -i corrupt952/closest\n```\n\n### Build from source\n\n```sh\ngit clone https://github.com/corrupt952/closest.git\ncd closest\ngo build\n```\n\n## Usage\n\n```sh\nUsage: closest [options] [pattern]\nOptions:\n  -a    Search all files[default: false]\n  -r    Use regex pattern for matching[default: false]\n  -v    Show version\n```\n\n### Exit Codes\n\nThe tool uses the following exit codes:\n\n- `0`: Success - Files were found and output\n- `1`: Error - An error occurred (file not found, invalid regex, permission denied, etc.)\n\n### Basic Usage\n\nFind the closest file matching a specific name:\n\n```sh\nclosest .tflint.hcl\n# Output: /path/to/closest/.tflint.hcl\n```\n\nFind all matching files from current directory to root:\n\n```sh\nclosest -a .envrc\n# Output: \n# /current/path/.envrc\n# /current/.envrc\n# /home/user/.envrc\n```\n\nFind files using regex patterns:\n\n```sh\nclosest -r \".*\\.ya?ml$\"\n# Output: /path/to/closest/config.yaml\n```\n\n## Examples\n\n### Example 1: Using with tflint\n\n`tflint` only references `.tflint.hcl` in the current or home directory. With `closest`, you can use project-specific settings from parent directories in a monorepo.\n\nDirectory structure:\n```\n/\n└── home\n    └── app\n        └── terraform\n            ├── .tflint.hcl\n            └── example-service\n                ├── production\n                └── staging # \u003c- current directory\n```\n\nRun tflint with the closest configuration:\n\n```sh\ntflint --config $(closest .tflint.hcl)\n```\n\n### Example 2: Troubleshooting direnv configuration\n\nWhen using `direnv`, you might want to find all `.envrc` files that affect the current directory. The `-a` option helps with troubleshooting by showing all relevant files.\n\nDirectory structure:\n```\n/\n└── home\n    └── app\n        ├── .envrc\n        └── terraform\n            ├── .envrc\n            └── example-service\n                ├── .envrc\n                ├── production  # \u003c- current directory\n                |   └── .envrc\n                └── staging\n```\n\nFind all `.envrc` files from current directory to root:\n\n```sh\nclosest -a .envrc\n```\n\nOutput:\n```sh\n/home/app/terraform/example-service/production/.envrc\n/home/app/terraform/example-service/.envrc\n/home/app/terraform/.envrc\n/home/app/.envrc\n```\n\n\u003e **Note:** Command options must come before the filename. For example, `closest .envrc -a` doesn't work.\n\n## Error Handling\n\n`closest` provides clear error messages for common issues:\n\n- **File not found**: When no matching files are found in the directory hierarchy\n  ```\n  Error: file not found: config.json\n  ```\n\n- **Invalid regex pattern**: When the provided regex pattern is invalid\n  ```\n  Error: invalid regex pattern: error parsing regexp: missing closing ]: `[abc`\n  ```\n\n- **Permission denied**: When the tool cannot access a directory due to permission issues\n  ```\n  Error: failed to read directory /path/to/restricted: permission denied\n  ```\n\n- **Missing pattern argument**: When no search pattern is provided\n  ```\n  Error: error parsing flags: missing pattern argument\n  ```\n\n### Example 3: Finding configuration files with regex\n\nSometimes you need to find configuration files that might have different extensions. The `-r` option enables regex pattern matching for flexible searches.\n\nFind the closest YAML configuration file:\n\n```sh\nclosest -r \".*\\.ya?ml$\"\n```\n\nFind all YAML files in the directory hierarchy:\n\n```sh\nclosest -a -r \".*\\.ya?ml$\"\n```\n\nOutput:\n```sh\n/home/app/terraform/example-service/production/config.yaml\n/home/app/terraform/example-service/terraform.yaml\n/home/app/terraform/main.yml\n/home/app/config.yml\n```\n\n## Troubleshooting\n\n### Common Issues\n\n1. **No files found**\n   - Check if the file exists in any parent directory\n   - Verify the spelling and case of the filename (filesystems may be case-sensitive)\n   - If using regex, ensure the pattern is correct\n\n2. **Permission errors**\n   - Ensure you have read permissions for all directories in the path\n   - Try running with elevated privileges if necessary\n\n3. **Regex not matching**\n   - Test your regex pattern with a regex testing tool\n   - Remember to escape special characters\n   - For complex patterns, start simple and build up\n\n### Debugging Tips\n\n- Use the `-a` flag to see all matching files, which can help identify if files exist but aren't where expected\n- For regex issues, try simplifying your pattern first, then make it more specific\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\nFor detailed information about the development setup, workflow, and release process, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorrupt952%2Fclosest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorrupt952%2Fclosest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorrupt952%2Fclosest/lists"}