ngrokgitconfig

package module
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 10 Imported by: 0

README ยถ

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

ngrok-gitconfig

Generate a gitconfig snippet that rewrites each target source domain to the active ngrok tunnel URL.


CHINESE README

ไธญๆ–‡่ฏดๆ˜Ž

Main Features

๐Ÿš€ Single-Purpose Command: Fetch active ngrok tunnel URLs and write them as a gitconfig snippet ๐Ÿ”— Plug-In Design: Output snippet plugs into ~/.gitconfig via git's [include] mechanism ๐Ÿ”„ Symlink-Based Switching: Toggle between LAN and ngrok paths via a single ln -sf ๐Ÿ” Multi-Account Support: Pick from a list of ngrok api keys via the -n index flag

Installation

go install github.com/yylego/ngrok-gitconfig/cmd/ngrok-gitconfig@latest

Usage

# Fetch active ngrok tunnels and write the snippet (default api key index 0)
ngrok-gitconfig -c ~/configs/ngrok-gitconfig.yaml -o ~/.gitconfig.gitlab.ngrok

# Pick api key index 1
ngrok-gitconfig -c ~/configs/ngrok-gitconfig.yaml -o ~/.gitconfig.gitlab.ngrok -n 1
Flags
Flag Default Note
--config / -c (required) path to YAML config
--output / -o (required) output path of the gitconfig snippet
--choose / -n 0 api key index

Configuration

YAML config โ€” ~/configs/ngrok-gitconfig.yaml
api_keys:
  - "<ngrok api key 1>" # account 1
  - "<ngrok api key 2>" # account 2 (extras OK, pick via -n flag)
targets:
  - "https://gitlab.example.com/"
  - "http://gitlab.example.com/"

targets are paired by index with the tunnel URLs returned by the ngrok API.

Wire up ~/.gitconfig with [include]

Add at the top of ~/.gitconfig:

[include]
	path = ~/.gitconfig.gitlab.active
LAN snippet โ€” ~/.gitconfig.gitlab.local

Hand-written, does not change:

[url "http://192.168.1.100:8080/"]
	insteadof = https://gitlab.example.com/
[url "http://192.168.1.100:8080/"]
	insteadof = http://gitlab.example.com/
ngrok snippet โ€” ~/.gitconfig.gitlab.ngrok

Touch the snippet file (this command overwrites it on each run):

touch ~/.gitconfig.gitlab.ngrok

Point active at one of the snippets to start (LAN here):

ln -sf ~/.gitconfig.gitlab.local ~/.gitconfig.gitlab.active

In ~/.zshrc (or ~/.bashrc):

gitlab-use-ngrok() {
    ngrok-gitconfig -c ~/configs/ngrok-gitconfig.yaml -o ~/.gitconfig.gitlab.ngrok "$@" \
        && ln -sf ~/.gitconfig.gitlab.ngrok ~/.gitconfig.gitlab.active
}
alias gitlab-use-local='ln -sf ~/.gitconfig.gitlab.local ~/.gitconfig.gitlab.active'
alias gitlab-use-which='ls -la ~/.gitconfig.gitlab.active'
Usage Examples
# In office (LAN direct)
gitlab-use-local

# Off-LAN (refresh ngrok URLs from API, switch active to ngrok)
gitlab-use-ngrok

# Same as above, pick api key index 1
gitlab-use-ngrok -n 1

# Check which path is now active
gitlab-use-which

๐Ÿ“„ License

MIT License - see LICENSE.


๐Ÿ’ฌ Contact & Feedback

Contributions are welcome! Report bugs, suggest features, and contribute code:

  • ๐Ÿ› Mistake reports? Open an issue on GitHub with reproduction steps
  • ๐Ÿ’ก Fresh ideas? Create an issue to discuss
  • ๐Ÿ“– Documentation confusing? Report it so we can improve
  • ๐Ÿš€ Need new features? Share the use cases to help us understand requirements
  • โšก Performance issue? Help us optimize through reporting slow operations
  • ๐Ÿ”ง Configuration problem? Ask questions about complex setups
  • ๐Ÿ“ข Follow project progress? Watch the repo to get new releases and features
  • ๐ŸŒŸ Success stories? Share how this package improved the workflow
  • ๐Ÿ’ฌ Feedback? We welcome suggestions and comments

๐Ÿ”ง Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


๐ŸŒŸ Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

Project Support:

  • โญ Give GitHub stars if this project helps you
  • ๐Ÿค Share with teammates and (golang) programming friends
  • ๐Ÿ“ Write tech blogs about development tools and workflows - we provide content writing support
  • ๐ŸŒŸ Join the ecosystem - committed to supporting open source and the (golang) development scene

Have Fun Coding with this package! ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰


GitHub Stars

Stargazers

Documentation ยถ

Overview ยถ

Package ngrokgitconfig renders ngrok tunnel URLs as a gitconfig snippet Plug the snippet into ~/.gitconfig via git's [include] mechanism or a symlink

ngrokgitconfig ๆŠŠ ngrok ้šง้“ URL ๆธฒๆŸ“ๆˆ gitconfig ็‰‡ๆฎต ้€š่ฟ‡ git ็š„ [include] ๆœบๅˆถ๏ผˆๆˆ–็ฌฆๅท้“พๆŽฅ๏ผ‰ๆŽฅๅ…ฅ ~/.gitconfig

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

func Generate ยถ

func Generate(ctx context.Context, cfg *Config, keyIdx int) ([]byte, error)

Generate fetches the active ngrok tunnel URLs and returns the gitconfig snippet bytes keyIdx must be in [0, len(cfg.APIKeys))

Generate ๆ‹‰ๅ–ๆดป่ทƒ ngrok ้šง้“ URL ๅนถ่ฟ”ๅ›ž gitconfig ็‰‡ๆฎตๅญ—่Š‚ keyIdx ่Œƒๅ›ด [0, len(cfg.APIKeys))

Types ยถ

type Config ยถ

type Config struct {
	APIKeys []string `yaml:"api_keys"` // ngrok api keys, one each account // ngrok api ๅฏ†้’ฅ๏ผŒๆฏ่ดฆๅทไธ€ไธช
	Targets []string `yaml:"targets"`  // source domains to rewrite, paired by index with fetched tunnel URLs // ๅพ…้‡ๅ†™็š„ๆบๅŸŸๅ๏ผŒๆŒ‰็ดขๅผ•ไธŽๆ‹‰ๆฅ็š„้šง้“ URL ไธ€ไธ€ๅฏนๅบ”
}

Config holds the YAML config that drives this command

Config ๆŒๆœ‰้ฉฑๅŠจๆœฌๅ‘ฝไปค็š„ YAML ้…็ฝฎ

func LoadConfig ยถ

func LoadConfig(path string) (*Config, error)

LoadConfig reads, parses, and validates the YAML config at the given path Errors when api_keys or targets is missing

LoadConfig ่ฏปๅ–ใ€่งฃๆžๅนถๆ ก้ชŒๆŒ‡ๅฎš่ทฏๅพ„็š„ YAML ้…็ฝฎ ็ผบ api_keys ๆˆ– targets ๆ—ถๆŠฅ้”™

Directories ยถ

Path Synopsis
cmd
ngrok-gitconfig command
Command ngrok-gitconfig writes ngrok tunnel URLs as a gitconfig snippet
Command ngrok-gitconfig writes ngrok tunnel URLs as a gitconfig snippet

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL