AutoYADM commit: 2025-03-13 16:00:06
This commit is contained in:
parent
ce3f0e9c5d
commit
436813ee12
3 changed files with 55 additions and 1 deletions
46
.config/helix/scripts/get_git_provider_url.fish
Executable file
46
.config/helix/scripts/get_git_provider_url.fish
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env fish
|
||||
|
||||
function get_git_provider_url --argument filename line_number
|
||||
# Check if inside a git repository
|
||||
if not git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||
echo "Error: Not inside a git repository."
|
||||
return 1
|
||||
end
|
||||
|
||||
# Get the remote URL
|
||||
set remote_url (git config --get remote.origin.url)
|
||||
if test -z "$remote_url"
|
||||
echo "Error: No remote origin found."
|
||||
return 1
|
||||
end
|
||||
|
||||
# Determine the provider (GitHub, GitLab, etc.)
|
||||
if string match -q '*github.com*' $remote_url
|
||||
set provider github
|
||||
else if string match -q '*gitlab.com*' $remote_url
|
||||
set provider gitlab
|
||||
else
|
||||
echo "Error: Unsupported git provider."
|
||||
return 1
|
||||
end
|
||||
|
||||
# Extract the repo path and branch
|
||||
set repo_path (echo $remote_url | perl -nE 'say $2 if /\.com(:|\/)(.*)\.git/')
|
||||
set branch (git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
# Generate the URL based on the provider
|
||||
switch $provider
|
||||
case github
|
||||
echo "https://github.com/$repo_path/blob/$branch/$filename#L$line_number"
|
||||
case gitlab
|
||||
echo "https://gitlab.com/$repo_path/-/blob/$branch/$filename#L$line_number"
|
||||
end
|
||||
end
|
||||
|
||||
# Ensure correct number of arguments
|
||||
if [ (count $argv) -ne 2 ]
|
||||
echo "Usage: script.fish <filename> <line_number>"
|
||||
return 1
|
||||
end
|
||||
|
||||
get_git_provider_url $argv[1] $argv[2]
|
Loading…
Add table
Add a link
Reference in a new issue