GitHub Link Generator (ghlink
) is a command-line tool that generates GitHub links for files in your Git repository. It supports both relative and absolute paths, and can generate links to specific lines or line ranges.
You can install the GitHub Link Generator using pip:
pip install git+https://github.com/albertoperdomo2/ghlink.git
You can quickly set up ghlink
with the new init
command:
# Basic setup
ghlink init
# Setup with your GitHub token
ghlink init --token YOUR_GITHUB_TOKEN
ghlink
works best with a GitHub personal access token for API authentication. This helps avoid rate limiting issues. You can provide your token in several ways:
-
During initialization:
ghlink init --token YOUR_GITHUB_TOKEN
-
As an environment variable:
export GITHUB_TOKEN=your_github_token_here
-
In the configuration file (
~/.config/ghlink/config
):[github] token = your_github_token_here default_remote = origin open_browser = false
After installation, you can use the ghlink
command as follows:
-
Generate a link to a file:
ghlink path/to/your/file.py
-
Generate a link to a specific line in a file:
ghlink path/to/your/file.py -l 42
-
Generate a link to a range of lines in a file:
ghlink path/to/your/file.py -l 42,50
Create permanent links using commit SHA instead of branch name:
ghlink path/to/your/file.py -p
Specify which Git remote to use (useful for forks):
ghlink path/to/your/file.py -r upstream
Open links directly in your browser:
ghlink path/to/your/file.py -o
ghlink
first checks if the specified file exists in your local repository.- It verifies that the file is pushed to the remote GitHub repository.
- For line-specific links, it validates that the specified lines exist in the file.
- It handles both HTTPS and SSH GitHub URLs to work with any repository setup.
- When in detached HEAD state, it automatically uses the current commit SHA.
- If the file exists and is pushed, it generates the appropriate GitHub link and copies it to your clipboard.
- Based on your configuration, it can automatically open the link in your browser.
For more detailed usage instructions, please see the usage guide.
This project is licensed under the MIT License - see the LICENSE file for details.