Skip to main content

GitHub Code Search CLI with file downloading capability.

Project description

GitHub Code Search CLI (ghcs)

ghcs is a command-line interface (CLI) tool for searching code on GitHub and downloading matched files. It allows you to search for code snippets, filter by language, user, repository, and path, and optionally download the matched files. This is effective utility specially when developers are on CLI non ui environment (i.e. on remote desktop).

Features

  • Search GitHub code with various filters (query, user, repository, language, path and so on).
  • Download matched files directly from GitHub.
  • Extract specific code sections from downloaded files and refine using AI (Gemini model)
  • Easy to use CLI interface.

Installation

To install ghcs, simply use direct pip:

pip install ghcs

or for most updated, directly from Github, using

pip install git+https://github.com/hissain/ghcs.git

Usage

To use the ghcs CLI, you need a GitHub Personal Access Token. You can set it via the --token argument or the GITHUB_TOKEN environment variable.

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

Extract Code with AI

To extract specific code sections from downloaded files using the Gemini AI model: Subsequent request provided by --remark will be applied by Gemini. The final code can be printed on Console or saved at location provided by --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: You need to set the GEMINI_API_KEY in your environment variables or .env file.

Arguments

Positional:

  • query: Search term as an string (required).

Optional:

  • -l, --language: Programming language filter.
  • -u, --user: Search in all repositories of a specific user.
  • -r, --repo: Search in a specific repository (e.g., username/repo).
  • -p, --path: Specify path specifier for filtering.
  • -t, --token: GitHub Personal Access Token (or set GITHUB_TOKEN environment variable).
  • -m, --max-result: Limit the search results to show or download.
  • -d, --download: Download matched files.
  • -dd, --download-dir: Download directory for downloading the matched files.
  • -v, --verbose: Verbose logging for matched files.
  • -r, --remark: Description of what should be extracted from the downloaded files.
  • -o, --output-file: Output file to save the extracted code (default: print to console).
  • -e, --extensions: Comma-separated list of file extensions to consider for extraction (e.g., .py,.js).
  • -h, --help: Show the help menu and exit.

GITHUB_TOKEN can be generated from https://github.com/settings/tokens

GEMINI_API_KEY can be obtained from Google AI Studio, https://aistudio.google.com/apikey .

Example

ghcs 'def train(' --language 'python' --user 'hissain' --path 'llama/train' --download --token YOUR_GITHUB_TOKEN --max-results 5

OR

ghcs 'def train(' -l 'python' -p 'llama/train' -d -m 10
ghcs "def train()" --path llm --max-results 3 --download

With AI-powered code extraction:

ghcs "def train LoRA" --path llm --download --remark "extract only the forward pass function" --output-file forward_pass.py --max-results 5

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Md. Sazzad Hissain Khan

Feel free to modify the content 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

ghcs-1.0.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ghcs-1.0.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file ghcs-1.0.0.tar.gz.

File metadata

  • Download URL: ghcs-1.0.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for ghcs-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8b91c0806dcb3a56d7b711653040a90284ec40fd30df7b651707c9be2a38653c
MD5 681b4134bbadde5980f123e172c523c2
BLAKE2b-256 7c53ee717317c3ea9b43ddf89aa8b81d9bb829aeb2e28ab58d4fb420ce1fe04e

See more details on using hashes here.

File details

Details for the file ghcs-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ghcs-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for ghcs-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a229dbb89a3163c8b874cb52f161c163f75d13b9a78667330bbec62d023f042
MD5 bdf7d06b1397a7c7dcc4b7b52639d77c
BLAKE2b-256 ad05b577bb439045c0b055e75c5687b445ff0bf28910032158c41a62d2528480

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page