GitHub Code Search CLI with file downloading capability.
Project description
GitHub Code Search CLI (ghcs) - With Semantic Code Refinement
ghcs is a powerful command-line interface (CLI) tool for searching code on GitHub and downloading matched files. It allows you to search for code snippets using various filters such as language, user, repository, and path. Additionally, ghcs enables AI-powered code manipulation and refinement using large language models (LLMs) like Gemini. This makes it especially useful for developers working in CLI-based environments without a graphical user interface (e.g., remote servers).
Features
- Search GitHub repositories for code using advanced filters (query, user, repository, language, path, etc.).
- Download matched files directly from GitHub.
- Extract, modify, enhance, and refine code using AI-powered transformations with models like Gemini.
- User-friendly CLI interface designed for seamless integration into developer workflows.
Installation
To install ghcs, use pip:
pip install ghcs
For the latest updates, install directly from GitHub:
pip install git+https://github.com/hissain/ghcs.git
Usage
To use ghcs, you need a GitHub Personal Access Token, which can be set using the --token argument or the GITHUB_TOKEN environment variable. For AI-powered code manipulation with --remark, you must set the GEMINI_API_KEY in your environment.
Basic Search
ghcs 'search_term' --token YOUR_GITHUB_TOKEN
ghcs 'search_term' # When GITHUB_TOKEN is already set in .env
Search with Filters
ghcs 'search_term' --user 'username' --repo 'username/repo' --language 'python' --path 'llama/train' --token YOUR_GITHUB_TOKEN --max-results MAX_RESULT_COUNT
Download Matched Files
ghcs 'search_term' --download --token YOUR_GITHUB_TOKEN
AI-Powered Code Extraction & Refinement
To extract specific code sections or apply AI-driven transformations on downloaded files:
- Use
--remarkto specify semantic modifications (requires--download). - The refined code can be printed to the console or saved using
--output-file.
Example:
ghcs "LoRA def train()" --user hissain --download --remark "Extract the training function for LoRA with proper imports" --output-file extracted_code.py --verbose
Note: The
GEMINI_API_KEYmust be set in your environment variables or.envfile to enable the--remarkfeature.
CLI Arguments
Positional Arguments
- query: Search term as a string (required).
Optional Arguments
-l, --language: Filter by programming language.-u, --user: Search within all repositories of a specific user.-r, --repo: Search within a specific repository (e.g., username/repo).-p, --path: Restrict search to a specific file path.-t, --token: GitHub Personal Access Token (or setGITHUB_TOKENenvironment variable).-m, --max-result: Limit the number of search results.-d, --download: Download matched files.-dd, --download-dir: Specify the directory for downloaded files.-v, --verbose: Enable verbose logging.-r, --remark: AI instruction for refining downloaded files.-o, --output-file: Output file to save refined code (default: print to console).-e, --extensions: Specify file extensions to consider (e.g.,.py,.js).-h, --help: Show help menu and exit.
Example Commands
ghcs 'def train(' --language 'python' --user 'hissain' --path 'llama/train' --download --token YOUR_GITHUB_TOKEN --max-results 5
ghcs 'def train(' -l 'python' -p 'llama/train' -d -m 10
ghcs "def train()" --path llm --max-results 3 --download
With AI-powered refinement:
ghcs "def train LoRA" --path llm --download --remark "Extract only the forward pass function" --output-file forward_pass.py --max-results 5
API Keys
- GitHub Token: Generate a personal access token at GitHub Tokens
- Gemini API Key: Obtain from Google AI Studio
License
This project is licensed under the MIT License. See the LICENSE file for details.
Author
Md. Sazzad Hissain Khan
- Email: hissain.khan@gmail.com
- GitHub: hissain
Feel free to modify and enhance this project as needed!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ghcs-1.0.1.tar.gz.
File metadata
- Download URL: ghcs-1.0.1.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13a4256dfb84ef2a3fcf8b08b7dba7f04a265ac94caee9302d181c66ec260c0b
|
|
| MD5 |
926683d95b4d6de02c7df629a23d895a
|
|
| BLAKE2b-256 |
bc45f54bf3161dae3b60bf71ad779605accbb86b9ae1f73d42a9cfc38b5f1710
|
File details
Details for the file ghcs-1.0.1-py3-none-any.whl.
File metadata
- Download URL: ghcs-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2e6bed8232153f02f54ab0e0040409b3df18fb136eda25338d9b2751e936789
|
|
| MD5 |
f244f3363ccc61aafdd26e321872e56e
|
|
| BLAKE2b-256 |
2b69ffec1e3c224a1b7713d98188e41a17cb536ac669a45ccc434b51fda05ad0
|